-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainActivity.java
126 lines (95 loc) · 3.91 KB
/
MainActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.example.pet1;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import java.util.regex.Pattern;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private TextView register, forgotPassword;
private EditText editTextemail, editTextpassword;
private Button signIn;
private FirebaseAuth mAuth;
private ProgressBar progressBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
register = (TextView) findViewById(R.id.register);
register.setOnClickListener(this);
signIn = (Button) findViewById(R.id.signIN);
signIn.setOnClickListener(this);
editTextemail = (EditText) findViewById(R.id.email);
editTextpassword = (EditText) findViewById(R.id.password);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
mAuth =FirebaseAuth.getInstance();
forgotPassword = (TextView) findViewById(R.id.forgotPassword);
forgotPassword.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.register:
startActivity(new Intent(this, RegisterUser.class));
break;
case R.id.signIN:
userLogin();
break;
case R.id.forgotPassword:
startActivity(new Intent(this,ForgotPassword.class));
break;
}
}
private void userLogin(){
String email = editTextemail.getText().toString().trim();
String password = editTextpassword.getText().toString().trim();
if(email.isEmpty()){
editTextemail.setError("Email gereklidir!");
editTextemail.requestFocus();
return;
}
if(!Patterns.EMAIL_ADDRESS.matcher(email).matches()){
editTextemail.setError(("Doğru bir email. giriniz!"));
editTextemail.requestFocus();
return;
}
if(password.isEmpty()){
editTextpassword.setError("Şifre alanını doldurunuz!");
editTextpassword.requestFocus();
return;
}
if(password.length() < 6 ){
editTextpassword.setError("Şifreniz en az 6 karakterden oluşmalıdır!");
editTextpassword.requestFocus();
return;
}
progressBar.setVisibility(View.VISIBLE);
mAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user.isEmailVerified()) {
startActivity(new Intent(MainActivity.this, HomePage.class));
}else {
user.sendEmailVerification();
Toast.makeText(MainActivity.this, "Hesabınızı emailinizden doğrulayınız!", Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(MainActivity.this, "Giriş yapılamamıştır! Lütfen bilgilerinizi doğru giriniz!", Toast.LENGTH_SHORT).show();
}
}
});
}
}