Advertisement
Unofficialpage

Untitled

Apr 26th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1.  
  2.  
  3. public class MainActivity extends AppCompatActivity {
  4.  
  5. private FirebaseAuth mAuth;
  6.  
  7. EditText email, pass;
  8. private String TAG = MainActivity.class.getName();
  9. AuthCredential emailAuthProvider;
  10.  
  11. @Override
  12. protected void onCreate(Bundle savedInstanceState) {
  13. super.onCreate(savedInstanceState);
  14. setContentView(R.layout.activity_main);
  15.  
  16. mAuth = FirebaseAuth.getInstance();
  17.  
  18. email = findViewById(R.id.editText);
  19. pass = findViewById(R.id.editText2);
  20. }
  21.  
  22. public void sign(View view){
  23. String email2 = email.getText().toString();
  24. String passs = pass.getText().toString();
  25.  
  26.  
  27. mAuth.signInWithEmailAndPassword(email2, passs)
  28. .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
  29. @Override
  30. public void onComplete(@NonNull Task<AuthResult> task) {
  31. if (task.isSuccessful()) {
  32. // Sign in success, update UI with the signed-in user's information
  33. Log.d(TAG, "signInWithEmail:success");
  34. FirebaseUser user = mAuth.getCurrentUser();
  35.  
  36.  
  37.  
  38. } else {
  39. // If sign in fails, display a message to the user.
  40. Log.w(TAG, "signInWithEmail:failure", task.getException());
  41. Toast.makeText(MainActivity.this, "Authentication failed.",
  42. Toast.LENGTH_SHORT).show();
  43.  
  44. }
  45.  
  46. // ...
  47. }
  48. });
  49.  
  50. linkUserAuth(email2, passs);
  51. }
  52.  
  53.  
  54.  
  55. private void linkUserAuth(String email, String pass){
  56. AuthCredential credential = EmailAuthProvider.getCredential(email, pass);
  57. mAuth.getCurrentUser().linkWithCredential(credential).addOnCompleteListener(this, new OnCompleteListener<AuthResult>(){
  58. @Override
  59. public void onComplete(@NonNull Task<AuthResult> task) {
  60. if(task.isSuccessful()){
  61. Log.d(TAG,"linkWithCredential:success");
  62. FirebaseUser mergeAuthUser=task.getResult().getUser();
  63.  
  64. }else{
  65. Log.w(TAG,"linkWithCredential:failure",task.getException());
  66. }
  67. }
  68. });
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement