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.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.CountDownTimer;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@@ -13,6 +14,7 @@ import android.widget.DatePicker;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.activity.result.ActivityResult;
|
import androidx.activity.result.ActivityResult;
|
||||||
@@ -58,9 +60,10 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private static final String FOLDER_DIRECTORY = "UserImages/";
|
private static final String FOLDER_DIRECTORY = "UserImages/";
|
||||||
TextInputLayout textInput_email, textInput_phone, textInput_fullName, textInput_birthDay;
|
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;
|
EditText edt_birthday, edt_email, edt_phone, edt_fullName;
|
||||||
final Calendar myCalendar= Calendar.getInstance();
|
final Calendar myCalendar= Calendar.getInstance();
|
||||||
LinearLayout change_password;
|
LinearLayout change_password, countdown_layout;
|
||||||
Button update_button, update_image_button;
|
Button update_button, update_image_button;
|
||||||
ImageView back_image;
|
ImageView back_image;
|
||||||
RoundedImageView profile_avatar;
|
RoundedImageView profile_avatar;
|
||||||
@@ -69,6 +72,19 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
|||||||
ConstraintLayout progressLayout;
|
ConstraintLayout progressLayout;
|
||||||
FirebaseAuth mAuth;
|
FirebaseAuth mAuth;
|
||||||
FirebaseUser firebaseUser;
|
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
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
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){
|
private void uploadToFirebase(Uri uri){
|
||||||
|
|
||||||
//Name of image user
|
//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(){
|
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.
|
// Check if user is signed in (non-null) and update UI accordingly.
|
||||||
firebaseUser = mAuth.getCurrentUser();
|
firebaseUser = mAuth.getCurrentUser();
|
||||||
if(firebaseUser != null){
|
|
||||||
|
|
||||||
if(!firebaseUser.isEmailVerified()){
|
//Reload firebase user data
|
||||||
showDialogCaution();
|
firebaseUser.reload().addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||||
textInput_email.setError("Nhấp vào đây để xác thực!");
|
@Override
|
||||||
textInput_email.setOnClickListener(new View.OnClickListener() {
|
public void onComplete(@NonNull Task<Void> task) {
|
||||||
@Override
|
progressLayout.setVisibility(View.GONE);
|
||||||
public void onClick(View view) {
|
if(task.isSuccessful()){
|
||||||
//When user click on the text
|
if(firebaseUser != null){
|
||||||
firebaseUser.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
|
|
||||||
@Override
|
//If user don't verify email yet
|
||||||
public void onComplete(@NonNull Task<Void> task) {
|
if(!firebaseUser.isEmailVerified()){
|
||||||
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();
|
showDialogCaution();
|
||||||
}
|
txt_verify_email.setVisibility(View.VISIBLE);
|
||||||
});
|
txt_verify_email.setOnClickListener(new View.OnClickListener() {
|
||||||
}
|
@Override
|
||||||
});
|
public void onClick(View view) {
|
||||||
} else {
|
//When user click on the text
|
||||||
textInput_email.setErrorEnabled(false);
|
|
||||||
|
//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 {
|
||||||
|
Common.showErrorServerNotification(AccountAndProfileActivity.this, "Đã có lỗi từ hệ thống! Vui lòng thử lại sau!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDialogCaution() {
|
private void showDialogCaution() {
|
||||||
@@ -275,7 +322,7 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<User> call, Throwable t) {
|
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);
|
progressLayout.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -301,6 +348,11 @@ public class AccountAndProfileActivity extends AppCompatActivity {
|
|||||||
profile_avatar = findViewById(R.id.profile_avatar);
|
profile_avatar = findViewById(R.id.profile_avatar);
|
||||||
|
|
||||||
progressLayout = findViewById(R.id.progress_layout);
|
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() {
|
private void setFontUI() {
|
||||||
textInput_email.setTypeface(Common.setFontBebas(getAssets()));
|
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.
|
// Check if user is signed in (non-null) and update UI accordingly.
|
||||||
user = mAuth.getCurrentUser();
|
user = mAuth.getCurrentUser();
|
||||||
|
|
||||||
if(user != null && Common.CURRENT_USER == null){
|
if(user != null && Common.CURRENT_USER == null){
|
||||||
user.getIdToken(true)
|
user.getIdToken(true)
|
||||||
.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
|
.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ public class SignInActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<User> call, Throwable t) {
|
public void onFailure(Call<User> call, Throwable t) {
|
||||||
System.out.println("ERROR: " + 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 {
|
} else {
|
||||||
|
|||||||
@@ -259,12 +259,12 @@ public class VerifyAccountActivity extends AppCompatActivity {
|
|||||||
public void onFailure(Call<User> call, Throwable t) {
|
public void onFailure(Call<User> call, Throwable t) {
|
||||||
progressLayout.setVisibility(View.GONE);
|
progressLayout.setVisibility(View.GONE);
|
||||||
showErrorText(t.toString());
|
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 {
|
} else {
|
||||||
progressLayout.setVisibility(View.GONE);
|
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) {
|
public static void showNotificationError(Context context, Activity activity) {
|
||||||
if(getConnectionType(context) != 0){
|
if(getConnectionType(context) != 0){
|
||||||
//Has internet connection
|
//Has internet connection
|
||||||
showErrorServerNotification(activity);
|
showErrorServerNotification(activity, "Đã có lỗi từ hệ thống! Xin vui lòng thử lại sau!");
|
||||||
} else {
|
} else {
|
||||||
//No internet, show notification
|
//No internet, show notification
|
||||||
showErrorInternetConnectionNotification(activity);
|
showErrorInternetConnectionNotification(activity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showErrorServerNotification(Activity activity){
|
public static void showErrorServerNotification(Activity activity, String message){
|
||||||
new AestheticDialog.Builder(activity, DialogStyle.RAINBOW, DialogType.ERROR)
|
new AestheticDialog.Builder(activity, DialogStyle.RAINBOW, DialogType.ERROR)
|
||||||
.setTitle("LỖI!")
|
.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)
|
.setCancelable(false)
|
||||||
.setOnClickListener(new OnDialogClickListener() {
|
.setOnClickListener(new OnDialogClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -85,6 +85,68 @@
|
|||||||
|
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</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
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
android:id="@+id/textInput_phone"
|
android:id="@+id/textInput_phone"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -227,7 +289,7 @@
|
|||||||
android:background="#80000000"
|
android:background="#80000000"
|
||||||
android:id="@+id/progress_layout"
|
android:id="@+id/progress_layout"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:visibility="gone"
|
android:visibility="visible"
|
||||||
>
|
>
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
|
|||||||
Reference in New Issue
Block a user