Firebase (5)
User Verification Email
==================
User က Sign Up လုပ္တဲ့အခါ တခါထဲ တန္းမလုပ္ေပးပဲ Verification email တေစာင္ ပို႔မယ္။ သူက Confirm လုပ္မွ လက္ခံမယ္ ဆိုရင္ ဒီလို ေရးရပါမယ္။
========
auth version 9.4.0 နဲ႔ အဆင္မေျပပါဘူး။ ေနာက္ဆံုး version ရေအာင္ Build.gradle မွာ ဒီလို ျပင္ေရးၿပီး download ခ်ထားပါ။
compile 'com.google.firebase:firebase-auth:+'
အရင္ဆံုး createUserWithEmailAndPassword ကို အရင္ လုပ္ပါ။
ၿပီးရင္ Verification email ကို ဒီလို ပို႔ပါ။
========
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
user.sendEmailVerification()
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(Task<Void> task) {
if (task.isSuccessful()) {
tv.setText("Verification email sent. Please check your email to confirm.");
}
}
});
========
Sign In ၀င္တဲ့အခ်ိန္မွာ ဒီလို စစ္ပါ။
========
FirebaseAuth.getInstance().signInWithEmailAndPassword(email, password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user.isEmailVerified()){
//ok, Email confirm လုပ္ၿပီးၿပီ
}else{
//Email confirm မလုပ္ရေသး
}
} else {
//Sign in failed
}
========
Email စာသားေတြ ျပင္ခ်င္ရင္ Authentication --> Templates မွာ edit ၀င္လုပ္ပါ။
:)
#firebase
Comments
Post a Comment