Search in sources :

Example 86 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project PhotoBlog-Android-Blog-App by akshayejh.

the class RegisterActivity method onStart.

@Override
protected void onStart() {
    super.onStart();
    FirebaseUser currentUser = mAuth.getCurrentUser();
    if (currentUser != null) {
        sendToMain();
    }
}
Also used : FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 87 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project EC2018App by Manan-YMCA.

the class FragmentFbLogin method handleFacebookAccessToken.

private void handleFacebookAccessToken(AccessToken token) {
    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    mAuth.signInWithCredential(credential).addOnCompleteListener((Activity) mContext, new OnCompleteListener<AuthResult>() {

        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
                // Sign in success, update UI with the signed-in user's information
                FirebaseUser user = mAuth.getCurrentUser();
                barLogin.setVisibility(View.GONE);
                dismiss();
            } else {
                // If sign in fails, display a message to the user.
                MDToast.makeText(mContext, "Authentication failed.", Toast.LENGTH_SHORT, MDToast.TYPE_ERROR).show();
                dismiss();
            }
        }
    });
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 88 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project EC2018App by Manan-YMCA.

the class QuestionFragment method handleFacebookAccessToken.

private void handleFacebookAccessToken(AccessToken token) {
    AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
    mAuth.signInWithCredential(credential).addOnCompleteListener((Activity) mContext, new OnCompleteListener<AuthResult>() {

        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
                // Sign in success, update UI with the signed-in user's information
                FirebaseUser user = mAuth.getCurrentUser();
            } else {
                // If sign in fails, display a message to the user.
                MDToast.makeText(mContext, "Authentication failed.", Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : AuthCredential(com.google.firebase.auth.AuthCredential) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 89 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project CSCI3130 by T-Caines.

the class LoginActivity method signIn.

public void signIn(View view) {
    String user = ((EditText) findViewById(R.id.email_sign_in)).getText().toString();
    String password = ((EditText) findViewById(R.id.password_sign_in)).getText().toString();
    dbAuth.signInWithEmailAndPassword(user, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {

        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
                // Sign in success, update UI with the signed-in user's information
                Log.d(TAG, "signInWithEmail:success");
                FirebaseUser user = dbAuth.getCurrentUser();
                if (user != null) {
                    Intent calendar = new Intent(LoginActivity.this, CourseViewer.class);
                    startActivity(calendar);
                }
            } else {
                // If sign in fails, display a message to the user.
                Log.w(TAG, "signInWithEmail:failure", task.getException());
                Toast.makeText(LoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show();
                ((TextView) findViewById(R.id.error_sign_in)).setText(" Invalid username or password ");
            }
        }
    });
}
Also used : AuthResult(com.google.firebase.auth.AuthResult) Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Example 90 with FirebaseUser

use of com.google.firebase.auth.FirebaseUser in project CSCI3130 by T-Caines.

the class SignUpActivity method onClick.

public void onClick(View view) {
    final EditText user = (EditText) findViewById(R.id.sign_up_user);
    final EditText password = (EditText) findViewById(R.id.sign_up_password);
    final EditText confirm = (EditText) findViewById(R.id.sign_up_password_confirm);
    if (!password.getText().toString().equals(confirm.getText().toString())) {
        ((TextView) findViewById(R.id.error_sign_up)).setText(" Passwords do not match ");
        return;
    }
    dbAuth.createUserWithEmailAndPassword(user.getText().toString(), password.getText().toString()).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {

        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
                FirebaseUser user = dbAuth.getCurrentUser();
                Log.d(TAG, "signUpWithEmail:success");
                finish();
            } else {
                Toast.makeText(SignUpActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show();
                ((TextView) findViewById(R.id.error_sign_up)).setText(" Username already exists ");
            }
        }
    });
}
Also used : EditText(android.widget.EditText) TextView(android.widget.TextView) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser)

Aggregations

FirebaseUser (com.google.firebase.auth.FirebaseUser)100 AuthResult (com.google.firebase.auth.AuthResult)26 Intent (android.content.Intent)22 FirebaseAuth (com.google.firebase.auth.FirebaseAuth)16 DataSnapshot (com.google.firebase.database.DataSnapshot)12 DatabaseError (com.google.firebase.database.DatabaseError)12 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)11 AuthCredential (com.google.firebase.auth.AuthCredential)11 DatabaseReference (com.google.firebase.database.DatabaseReference)11 ValueEventListener (com.google.firebase.database.ValueEventListener)11 View (android.view.View)10 Task (com.google.android.gms.tasks.Task)10 Button (android.widget.Button)9 NonNull (android.support.annotation.NonNull)8 OnCompleteListener (com.google.android.gms.tasks.OnCompleteListener)7 FirebaseAuthUserCollisionException (com.google.firebase.auth.FirebaseAuthUserCollisionException)7 TextView (android.widget.TextView)6 Test (org.junit.Test)6 Context (android.content.Context)5 SharedPreferences (android.content.SharedPreferences)5