Search in sources :

Example 6 with FirebaseAuth

use of com.google.firebase.auth.FirebaseAuth in project Grupp by tmoronta1208.

the class LoginActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // button views
    signInButton = findViewById(R.id.google_button);
    emailLogInButton = findViewById(R.id.btn_login);
    // publicUserDatabaseReference = firebaseDatabase.getReference().child(Constants.PUBLIC_USER);
    // getUserData();
    emailLogInButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            signIn();
        }
    });
    signInButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            signIn();
        }
    });
    mAuthListner = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            if (firebaseAuth.getCurrentUser() != null) {
                CurrentUserUtility currentUserUtility = new CurrentUserUtility();
                currentUserUtility.getCurrentPublicUser(new PublicUserListener() {

                    @Override
                    public void publicUserExists(Boolean userExists) {
                        Log.w("TAG", "login user exist" + userExists);
                        if (userExists) {
                            Log.w("TAG", "login user has profile" + userExists);
                            startActivity(new Intent(LoginActivity.this, UserProfileActivity.class));
                        } else {
                            Log.w("TAG", "login user does not have profile " + userExists);
                            startActivity(new Intent(LoginActivity.this, OnBoardActivity.class));
                        }
                    }
                });
                startActivity(new Intent(LoginActivity.this, OnBoardActivity.class));
            }
        }
    };
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestIdToken(getString(R.string.default_web_client_id)).requestEmail().build();
    // Build a GoogleSignInClient with the options specified by gso.
    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}
Also used : Intent(android.content.Intent) View(android.view.View) PublicUserListener(com.example.c4q.capstone.utils.currentuser.PublicUserListener) CurrentUserUtility(com.example.c4q.capstone.utils.currentuser.CurrentUserUtility) OnBoardActivity(com.example.c4q.capstone.userinterface.user.onboarding.OnBoardActivity) GoogleSignInOptions(com.google.android.gms.auth.api.signin.GoogleSignInOptions) UserProfileActivity(com.example.c4q.capstone.userinterface.user.UserProfileActivity) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 7 with FirebaseAuth

use of com.google.firebase.auth.FirebaseAuth in project BloodHub by kazijehangir.

the class DonationsFragment method fetchData.

// Getting data from database
public ArrayList<BloodRequest> fetchData() {
    donations = new ArrayList<BloodRequest>();
    FirebaseAuth mAuth = FirebaseAuth.getInstance();
    FirebaseUser user = mAuth.getCurrentUser();
    db.orderByChild("userid").equalTo(user.getUid()).addValueEventListener(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot child : dataSnapshot.getChildren()) {
                Donation donation = child.getValue(Donation.class);
                if (donation != null) {
                    FirebaseDatabase.getInstance().getReference().child("bloodrequests").child(donation.requestid).addListenerForSingleValueEvent(new ValueEventListener() {

                        @Override
                        public void onDataChange(DataSnapshot dataSnapshot) {
                            BloodRequest request = dataSnapshot.getValue(BloodRequest.class);
                            if (request != null) {
                                donations.add(request);
                                numDonations.setText("LIVES SAVED: " + donations.size());
                                mAdapter.notifyDataSetChanged();
                            }
                        }

                        @Override
                        public void onCancelled(DatabaseError databaseError) {
                        }
                    });
                }
                FirebaseDatabase.getInstance().getReference().child("bloodrequests").child(donation.requestid).addListenerForSingleValueEvent(new ValueEventListener() {

                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        BloodRequest request = dataSnapshot.getValue(BloodRequest.class);
                        donations.add(request);
                        numDonations.setText("LIVES SAVED: " + donations.size());
                        mAdapter.notifyDataSetChanged();
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                    }
                });
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    return donations;
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) Donation(com.jexapps.bloodhub.m_Model.Donation) FirebaseUser(com.google.firebase.auth.FirebaseUser) ValueEventListener(com.google.firebase.database.ValueEventListener) BloodRequest(com.jexapps.bloodhub.m_Model.BloodRequest) DataSnapshot(com.google.firebase.database.DataSnapshot) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 8 with FirebaseAuth

use of com.google.firebase.auth.FirebaseAuth in project BloodHub by kazijehangir.

the class IndividualRegistrationActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_individual_registration);
    setTitle("Individual Registration");
    // make the actionbar show arrow to go back to login
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    mAuth = FirebaseAuth.getInstance();
    mAuthListener = new FirebaseAuth.AuthStateListener() {

        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                Toast toast = Toast.makeText(getApplicationContext(), "Sending email", Toast.LENGTH_SHORT);
                toast.show();
                sendVerificationEmail();
            } else {
                Toast toast = Toast.makeText(getApplicationContext(), "Not sending email", Toast.LENGTH_SHORT);
                toast.show();
            }
        }
    };
    username = (AutoCompleteTextView) findViewById(R.id.name);
    mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
    mPasswordView = (EditText) findViewById(R.id.password);
    // progressBar = (ProgressBar) findViewById(R.id.progressBar);
    bloodGroup = (Spinner) findViewById(R.id.spin);
    try {
        Field popup = Spinner.class.getDeclaredField("mPopup");
        popup.setAccessible(true);
        android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(bloodGroup);
        popupWindow.setHeight(500);
    } catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) {
    }
    List<String> bgroups = Arrays.asList(getResources().getStringArray(R.array.blood_groups));
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_text_view, bgroups) {

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = super.getView(position, convertView, parent);
            v.setPadding(8, 8, 8, 15);
            if (position == getCount()) {
                ((TextView) v.findViewById(R.id.text1)).setText("");
                ((TextView) v.findViewById(R.id.text1)).setHint(getItem(getCount()));
            }
            return v;
        }

        @Override
        public int getCount() {
            return super.getCount() - 1;
        }
    };
    adapter.setDropDownViewResource(R.layout.spinner_text_view);
    bloodGroup.setAdapter(adapter);
    bloodGroup.setSelection(adapter.getCount());
    // Set OnClick Listeners for buttons
    photo_btn = (ImageButton) findViewById(R.id.profile_photo);
    photo_btn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(Intent.ACTION_PICK);
            intent.setType("image/*");
            startActivityForResult(intent, GALLERY_INTENT);
        }
    });
    Button mRegisterButton = (Button) findViewById(R.id.register_individual_button);
    mRegisterButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            registerNewUser();
        }
    });
}
Also used : Field(java.lang.reflect.Field) Toast(android.widget.Toast) ImageButton(android.widget.ImageButton) Button(android.widget.Button) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ArrayAdapter(android.widget.ArrayAdapter)

Example 9 with FirebaseAuth

use of com.google.firebase.auth.FirebaseAuth in project Firebase-Helper by AtifAbbAsi19.

the class FireBaseHelper method userLogin.

// method for user login
private void userLogin(String email, String password, Context context) {
    // if the email and password are not empty
    // displaying a progress dialog
    progressDialog.setMessage("Logging in  Please Wait...");
    progressDialog.show();
    FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
    // logging in the user
    firebaseAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener((Activity) context, new OnCompleteListener<AuthResult>() {

        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            // if the task is successfull
            if (task.isSuccessful()) {
            // start the profile activity
            // Check in user Node that whether data exists or not
            // if exists then login else show Snakbar data does not exist
            // mAuthUserStr = mAuth.getCurrentUser().getUid();
            // mEmail = mAuth.getCurrentUser().getEmail();
            // AddEventFireBaseListner(mAuthUserStr, TypeSpinnerStr);
            // startActivity(new Intent(getApplicationContext(), MainHomeDashBoard.class));
            } else {
                // Snackbar snackbar = Snackbar
                // .make(coordinatorLayout, "Invalid user", Snackbar.LENGTH_LONG)
                // .setAction("HIDE", new View.OnClickListener() {
                // @Override
                // public void onClick(View view) {
                // 
                // 
                // }
                // });
                // snackbar.show();
                progressDialog.dismiss();
            }
        }
    });
}
Also used : AuthResult(com.google.firebase.auth.AuthResult) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Example 10 with FirebaseAuth

use of com.google.firebase.auth.FirebaseAuth in project Firebase-Helper by AtifAbbAsi19.

the class FireBaseHelper method registerUser.

private void registerUser(final String email, String password, Context context) {
    // if (TextUtils.isEmpty(phone_number)) {
    // Toast.makeText(this, "Please enter Number", Toast.LENGTH_LONG).show();
    // return;
    // }
    FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
    // if the email and password are not empty
    // displaying a progress dialog
    // progressDialog.setMessage("Registering Please Wait...");
    // progressDialog.show();
    // /http://stackoverflow.com/questions/40404567/how-to-send-verification-email-with-firebase
    // .addOnCompleteListener((Activity) context, new OnCompleteListener<AuthResult>() {
    // .addOnCompleteListener((Executor) this, new OnCompleteListener<AuthResult>() {
    // creating a new user
    firebaseAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener((Activity) context, new OnCompleteListener<AuthResult>() {

        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            // checking if success
            if (task.isSuccessful()) {
                // display some message here
                String userId = task.getResult().getUser().getUid();
            // Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
            // startActivity(intent);
            // https://firebase.googleblog.com/2017/02/email-verification-in-firebase-auth.html
            // startActivity(new Intent(Signup_Activity.this, MainHomeDashBoard.class));
            // Toast.makeText(getApplicationContext(), "Successfully registered", Toast.LENGTH_LONG).show();
            } else {
                if (task.getException() instanceof FirebaseAuthUserCollisionException) {
                // Toast.makeText(Signup.this, "User with this email already exist.", Toast.LENGTH_SHORT).show();
                }
            // 
            // //display some message here
            // Toast.makeText(getApplicationContext(), "Registration Error", Toast.LENGTH_LONG).show();
            }
        // progressDialog.dismiss();
        }
    });
}
Also used : AuthResult(com.google.firebase.auth.AuthResult) FirebaseAuthUserCollisionException(com.google.firebase.auth.FirebaseAuthUserCollisionException) FirebaseAuth(com.google.firebase.auth.FirebaseAuth)

Aggregations

FirebaseAuth (com.google.firebase.auth.FirebaseAuth)32 FirebaseUser (com.google.firebase.auth.FirebaseUser)20 Intent (android.content.Intent)11 DataSnapshot (com.google.firebase.database.DataSnapshot)8 DatabaseError (com.google.firebase.database.DatabaseError)8 View (android.view.View)7 ValueEventListener (com.google.firebase.database.ValueEventListener)7 AuthResult (com.google.firebase.auth.AuthResult)6 IdpResponse (com.firebase.ui.auth.IdpResponse)5 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)5 GoogleSignInOptions (com.google.android.gms.auth.api.signin.GoogleSignInOptions)4 NonNull (androidx.annotation.NonNull)3 Nullable (androidx.annotation.Nullable)3 RestrictTo (androidx.annotation.RestrictTo)3 AuthCredential (com.google.firebase.auth.AuthCredential)3 Application (android.app.Application)2 Bundle (android.os.Bundle)2 TextView (android.widget.TextView)2 FacebookException (com.facebook.FacebookException)2 LoginResult (com.facebook.login.LoginResult)2