Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ublic class Authentication extends AppCompatActivity implements View.OnClickListener {
- private FirebaseAuth mAuth;
- private FirebaseAuth.AuthStateListener mAuthStateListener;
- private EditText ETemail;
- private EditText ETpassword;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_authentication);
- mAuth = FirebaseAuth.getInstance();
- mAuthStateListener = new FirebaseAuth.AuthStateListener() {
- @Override
- public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
- FirebaseUser user = firebaseAuth.getCurrentUser();
- if (user != null) {
- //Если пользователь авторизовался
- } else {
- }
- }
- };
- ETemail = (EditText) findViewById(R.id.et_email);
- ETpassword = (EditText) findViewById(R.id.et_password);
- findViewById(R.id.btn_sign_in).setOnClickListener(this);
- findViewById(R.id.btn_registration).setOnClickListener(this);
- }
- @Override
- public void onClick(View view) {
- if(view.getId() == R.id.btn_sign_in)
- {
- signIn(ETemail.getText().toString(),ETpassword.getText().toString());
- }else if(view.getId() == R.id.btn_registration){
- createAccount(ETemail.getText().toString(),ETpassword.getText().toString());
- }
- }
- private void createAccount (String email , String password)
- {
- mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
- @Override
- public void onComplete(@NonNull Task<AuthResult> task) {
- if(task.isSuccessful()){
- Toast.makeText(Authentication.this,"Регистрация успешна",Toast.LENGTH_SHORT).show();
- }
- if(!task.isSuccessful()){
- Toast.makeText(Authentication.this,"Регистрация провалена",Toast.LENGTH_SHORT).show();
- }
- }
- });
- {
- }
- }
- private void signIn(String email,String password)
- {
- mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
- @Override
- public void onComplete(@NonNull Task<AuthResult> task) {
- if(task.isSuccessful()){
- Toast.makeText(Authentication.this,"Авторизация успешна",Toast.LENGTH_SHORT).show();
- }
- if(!task.isSuccessful()){
- Toast.makeText(Authentication.this,"Авторизация провалена",Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement