-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmailVerification.java
More file actions
83 lines (73 loc) · 3.46 KB
/
EmailVerification.java
File metadata and controls
83 lines (73 loc) · 3.46 KB
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
package com.sxillocc.androidchat;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class EmailVerification extends AppCompatActivity implements View.OnClickListener {
FirebaseAuth firebaseAuth;
FirebaseUser currentUser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_email_verification);
firebaseAuth = FirebaseAuth.getInstance();
currentUser = firebaseAuth.getCurrentUser();
if(!currentUser.isEmailVerified()) {
currentUser.sendEmailVerification()
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Toast.makeText(EmailVerification.this, "Verification send" +
"to email:- " + currentUser.getEmail(), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(EmailVerification.this, "Failed Sending Verification"
, Toast.LENGTH_SHORT).show();
}
}
});
}
findViewById(R.id.resend).setOnClickListener(this);
findViewById(R.id.next).setOnClickListener(this);
}
@Override
public void onClick(View v) {
int id = v.getId();
if(id==R.id.resend){
//resend email verification
currentUser.sendEmailVerification()
.addOnCompleteListener(this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
Toast.makeText(EmailVerification.this,"Verification send " +
"to email:- "+ currentUser.getEmail(),Toast.LENGTH_LONG).show();
}else{
Toast.makeText(EmailVerification.this,"Failed Sending Verification"
,Toast.LENGTH_SHORT).show();
}
}
});
}
if(id==R.id.next){
//go to Main2Activity or show invalid user toast
currentUser.reload();
Toast.makeText(this,"Email Verified = " +
String.valueOf(currentUser.isEmailVerified()), Toast.LENGTH_SHORT).show();
if(currentUser.isEmailVerified()){
//Toast.makeText(this,"Email verified ",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(EmailVerification.this,Main2Activity.class);
startActivity(intent);
finish();
}else{
//Toast.makeText(this,"Email not verified ",Toast.LENGTH_SHORT).show();
}
}
}
}