mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 13:38:41 +00:00
Add verify email user
This commit is contained in:
@@ -6,6 +6,7 @@ import android.content.ContentResolver;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.view.View;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.Button;
|
||||
@@ -13,6 +14,7 @@ import android.widget.DatePicker;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.result.ActivityResult;
|
||||
@@ -58,9 +60,10 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
||||
|
||||
private static final String FOLDER_DIRECTORY = "UserImages/";
|
||||
TextInputLayout textInput_email, textInput_phone, textInput_fullName, textInput_birthDay;
|
||||
TextView txt_countdown, txt_resend_code, txt_verify_email;
|
||||
EditText edt_birthday, edt_email, edt_phone, edt_fullName;
|
||||
final Calendar myCalendar= Calendar.getInstance();
|
||||
LinearLayout change_password;
|
||||
LinearLayout change_password, countdown_layout;
|
||||
Button update_button, update_image_button;
|
||||
ImageView back_image;
|
||||
RoundedImageView profile_avatar;
|
||||
@@ -69,6 +72,19 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
||||
ConstraintLayout progressLayout;
|
||||
FirebaseAuth mAuth;
|
||||
FirebaseUser firebaseUser;
|
||||
CountDownTimer count = new CountDownTimer(60000, 1000) {
|
||||
@Override
|
||||
public void onTick(long millisUntilFinished) {
|
||||
txt_countdown.setText(millisUntilFinished / 1000 + " giây");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
countdown_layout.setVisibility(View.GONE);
|
||||
|
||||
txt_resend_code.setVisibility(View.VISIBLE);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -145,8 +161,21 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
//Set event resend_code button
|
||||
txt_resend_code.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
sendEmailVerification();
|
||||
|
||||
countdown_layout.setVisibility(View.VISIBLE);
|
||||
|
||||
txt_resend_code.setVisibility(View.GONE);
|
||||
|
||||
count.start();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
private void uploadToFirebase(Uri uri){
|
||||
|
||||
//Name of image user
|
||||
@@ -217,34 +246,52 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void sendEmailVerification(){
|
||||
firebaseUser.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
Toast.makeText(AccountAndProfileActivity.this, "Email đã được gửi đi, vui lòng kiểm tra hộp thư của bạn!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
private void showNotificationEmailVerify(){
|
||||
//Get firebase user from Paper
|
||||
firebaseUser = Paper.book().read("user");
|
||||
|
||||
// Check if user is signed in (non-null) and update UI accordingly.
|
||||
firebaseUser = mAuth.getCurrentUser();
|
||||
if(firebaseUser != null){
|
||||
|
||||
if(!firebaseUser.isEmailVerified()){
|
||||
showDialogCaution();
|
||||
textInput_email.setError("Nhấp vào đây để xác thực!");
|
||||
textInput_email.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//When user click on the text
|
||||
firebaseUser.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
Toast.makeText(AccountAndProfileActivity.this, "Email đã được gửi đi, vui lòng kiểm tra hộp thư của bạn!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
//Reload firebase user data
|
||||
firebaseUser.reload().addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
progressLayout.setVisibility(View.GONE);
|
||||
if(task.isSuccessful()){
|
||||
if(firebaseUser != null){
|
||||
|
||||
//If user don't verify email yet
|
||||
if(!firebaseUser.isEmailVerified()){
|
||||
showDialogCaution();
|
||||
txt_verify_email.setVisibility(View.VISIBLE);
|
||||
txt_verify_email.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//When user click on the text
|
||||
|
||||
//Count down resend code
|
||||
countdown_layout.setVisibility(View.VISIBLE);
|
||||
count.start();
|
||||
|
||||
sendEmailVerification();
|
||||
txt_verify_email.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
txt_verify_email.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
textInput_email.setErrorEnabled(false);
|
||||
} else {
|
||||
Common.showErrorServerNotification(AccountAndProfileActivity.this, "Đã có lỗi từ hệ thống! Vui lòng thử lại sau!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showDialogCaution() {
|
||||
@@ -275,7 +322,7 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<User> call, Throwable t) {
|
||||
Common.showErrorServerNotification(AccountAndProfileActivity.this);
|
||||
Common.showErrorServerNotification(AccountAndProfileActivity.this, "Không thể cập nhật thông tin, vui lòng thử lại sau!");
|
||||
progressLayout.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
@@ -301,6 +348,11 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
||||
profile_avatar = findViewById(R.id.profile_avatar);
|
||||
|
||||
progressLayout = findViewById(R.id.progress_layout);
|
||||
countdown_layout = findViewById(R.id.countdown_layout);
|
||||
|
||||
txt_countdown = findViewById(R.id.textview_countdown);
|
||||
txt_resend_code = findViewById(R.id.textview_resendCode_button);
|
||||
txt_verify_email = findViewById(R.id.textview_verify_email);
|
||||
}
|
||||
private void setFontUI() {
|
||||
textInput_email.setTypeface(Common.setFontBebas(getAssets()));
|
||||
|
||||
@@ -48,6 +48,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
// Check if user is signed in (non-null) and update UI accordingly.
|
||||
user = mAuth.getCurrentUser();
|
||||
|
||||
if(user != null && Common.CURRENT_USER == null){
|
||||
user.getIdToken(true)
|
||||
.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
|
||||
|
||||
@@ -184,7 +184,7 @@ public class SignInActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onFailure(Call<User> call, Throwable t) {
|
||||
System.out.println("ERROR: " + t);
|
||||
Common.showErrorServerNotification(SignInActivity.this);
|
||||
Common.showErrorServerNotification(SignInActivity.this, "Không thể đăng nhập tài khoản! Vui lòng thử lại sau!");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -259,12 +259,12 @@ public class VerifyAccountActivity extends AppCompatActivity {
|
||||
public void onFailure(Call<User> call, Throwable t) {
|
||||
progressLayout.setVisibility(View.GONE);
|
||||
showErrorText(t.toString());
|
||||
Common.showErrorServerNotification(VerifyAccountActivity.this);
|
||||
Common.showErrorServerNotification(VerifyAccountActivity.this, "Không thể tạo tài khoản! Vui lòng thử lại sau!");
|
||||
}
|
||||
});
|
||||
} else {
|
||||
progressLayout.setVisibility(View.GONE);
|
||||
Common.showErrorServerNotification(VerifyAccountActivity.this);
|
||||
Common.showErrorServerNotification(VerifyAccountActivity.this, "Đã có lỗi kết nối! Vui lòng thử lại sau!");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -109,17 +109,17 @@ public class Common {
|
||||
public static void showNotificationError(Context context, Activity activity) {
|
||||
if(getConnectionType(context) != 0){
|
||||
//Has internet connection
|
||||
showErrorServerNotification(activity);
|
||||
showErrorServerNotification(activity, "Đã có lỗi từ hệ thống! Xin vui lòng thử lại sau!");
|
||||
} else {
|
||||
//No internet, show notification
|
||||
showErrorInternetConnectionNotification(activity);
|
||||
}
|
||||
}
|
||||
|
||||
public static void showErrorServerNotification(Activity activity){
|
||||
public static void showErrorServerNotification(Activity activity, String message){
|
||||
new AestheticDialog.Builder(activity, DialogStyle.RAINBOW, DialogType.ERROR)
|
||||
.setTitle("LỖI!")
|
||||
.setMessage("Đã xuất hiện lỗi từ hệ thống! Vui lòng thử lại sau!")
|
||||
.setMessage(message)
|
||||
.setCancelable(false)
|
||||
.setOnClickListener(new OnDialogClickListener() {
|
||||
@Override
|
||||
|
||||
@@ -85,6 +85,68 @@
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="20dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/textInput_email"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:id="@+id/countdown_layout"
|
||||
android:visibility="gone"
|
||||
>
|
||||
<TextView
|
||||
android:id="@+id/textview_resendCode"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="15sp"
|
||||
android:text="Gửi lại sau: "
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textColor="@color/black"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textview_countdown"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:text="00:35"
|
||||
android:textColor="@color/secondary"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textview_verify_email"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="15sp"
|
||||
android:text="Xác thực"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textColor="@color/primaryColor"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textInput_email"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textview_resendCode_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="15sp"
|
||||
android:text="@string/resend_code"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:fontFamily="@font/opensans"
|
||||
android:textColor="@color/primaryColor"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textInput_email"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:visibility="gone"
|
||||
/>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/textInput_phone"
|
||||
android:layout_width="match_parent"
|
||||
@@ -227,7 +289,7 @@
|
||||
android:background="#80000000"
|
||||
android:id="@+id/progress_layout"
|
||||
android:clickable="true"
|
||||
android:visibility="gone"
|
||||
android:visibility="visible"
|
||||
>
|
||||
|
||||
<ProgressBar
|
||||
|
||||
Reference in New Issue
Block a user