Guest User

Untitled

a guest
Sep 28th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. private TextInputLayout mName;
  2. private TextInputLayout mEmail;
  3. private TextInputLayout mPwd;
  4. private Button mSubmit;
  5. String username, email,password;
  6. private FirebaseAuth mAuth;
  7.  
  8. @Override
  9. protected void onCreate(Bundle savedInstanceState) {
  10. super.onCreate(savedInstanceState);
  11. setContentView(R.layout.activity_reg);
  12.  
  13. mAuth = FirebaseAuth.getInstance();
  14.  
  15. mName=(TextInputLayout)findViewById(R.id.pName);
  16. mEmail=(TextInputLayout)findViewById(R.id.pEmail);
  17. mPwd=(TextInputLayout)findViewById(R.id.pPassword);
  18. mSubmit=(Button) findViewById(R.id.regStart);
  19.  
  20. mSubmit.setOnClickListener(new View.OnClickListener() {
  21. @Override
  22. public void onClick(View view) {
  23.  
  24. username= mName.getEditText().getText().toString();
  25. email= mEmail.getEditText().getText().toString();
  26. password= mPwd.getEditText().getText().toString();
  27.  
  28. Toast.makeText(getApplicationContext(), username+" "+email+" "+password,
  29. Toast.LENGTH_SHORT).show();
  30. register_user(username,email,password);
  31.  
  32. }
  33. });
  34.  
  35. }
  36.  
  37. private void register_user(String username, String email, String password)
  38. {
  39.  
  40. mAuth.createUserWithEmailAndPassword(email, password)
  41. .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
  42. @Override
  43. public void onComplete(@NonNull Task<AuthResult> task) {
  44. if (task.isSuccessful()) {
  45. // Sign in success, update UI with the signed-in user's information
  46. Log.d("yaaayy", "createUserWithEmail:success");
  47.  
  48. Intent i= new Intent(getApplicationContext(),MainActivity.class);
  49. startActivity(i);
  50. finish();
  51.  
  52. } else {
  53. // If sign in fails, display a message to the user.
  54. Log.w("oops", "createUserWithEmail:failure", task.getException());
  55. Toast.makeText(getApplicationContext(), "Authentication failed.",
  56. Toast.LENGTH_SHORT).show();
  57.  
  58. }
  59.  
  60. // ...
  61. }
  62. });
  63. } }
Add Comment
Please, Sign In to add comment