-
Notifications
You must be signed in to change notification settings - Fork 0
/
ForgotPassword.java
70 lines (58 loc) · 2.29 KB
/
ForgotPassword.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
package com.example.pet1;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
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.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
public class ForgotPassword extends AppCompatActivity {
private EditText emailEditText;
private Button resetPasswordButton;
private ProgressBar progressBar;
FirebaseAuth auth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_forgot_password);
emailEditText = (EditText) findViewById(R.id.email);
resetPasswordButton = (Button) findViewById(R.id.resetPassword);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
auth = FirebaseAuth.getInstance();
resetPasswordButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
resetPassword();
}
});
}
private void resetPassword(){
String email = emailEditText.getText().toString().trim();
if(email.isEmpty()){
emailEditText.setError("Email alanını doldurunuz!");
emailEditText.requestFocus();
return;
}
if(!Patterns.EMAIL_ADDRESS.matcher(email).matches()){
emailEditText.setError("Doğru bir email giriniz!");
emailEditText.requestFocus();
return;
}
progressBar.setVisibility(View.VISIBLE);
auth.sendPasswordResetEmail(email).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
Toast.makeText(ForgotPassword.this,"Emailinizi kontrol ediniz!",Toast.LENGTH_LONG).show();
}else{
Toast.makeText(ForgotPassword.this,"Tekrar deneyin!Bir hatayla karşılaşıldı!",Toast.LENGTH_LONG).show();
}
}
});
}
}