mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 13:38:41 +00:00
Change method sign in
This commit is contained in:
@@ -43,12 +43,12 @@ public class SignInActivity extends AppCompatActivity {
|
||||
|
||||
private FirebaseAuth mAuth;
|
||||
TextView signUp_textView, forgotPassword_textView;
|
||||
TextInputLayout textInput_phone, textInput_password;
|
||||
TextInputEditText edt_phone, edt_password;
|
||||
TextInputLayout textInput_email, textInput_password;
|
||||
TextInputEditText edt_email, edt_password;
|
||||
MaterialButton signInButton;
|
||||
ImageView back_image;
|
||||
ConstraintLayout progressLayout;
|
||||
String phone, password = null;
|
||||
String email, password = null;
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -60,6 +60,9 @@ public class SignInActivity extends AppCompatActivity {
|
||||
//Init Paper
|
||||
Paper.init(this);
|
||||
|
||||
if(Common.TOKEN != null)
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
|
||||
// Initialize Firebase Auth
|
||||
mAuth = FirebaseAuth.getInstance();
|
||||
|
||||
@@ -103,7 +106,7 @@ public class SignInActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void initData(){
|
||||
phone = edt_phone.getText().toString();
|
||||
email = edt_email.getText().toString();
|
||||
password = edt_password.getText().toString();
|
||||
}
|
||||
|
||||
@@ -111,19 +114,19 @@ public class SignInActivity extends AppCompatActivity {
|
||||
boolean dataHasValidate = true;
|
||||
|
||||
//Check phone number
|
||||
if(phone.isEmpty()){
|
||||
textInput_phone.setError("Số điện thoại không được bỏ trống!");
|
||||
if(email.isEmpty()){
|
||||
textInput_email.setError("Email không được bỏ trống!");
|
||||
dataHasValidate = false;
|
||||
} else {
|
||||
|
||||
|
||||
Pattern patternPhone = Pattern.compile(Common.PHONE_PATTERN);
|
||||
Matcher matcherPhone = patternPhone.matcher(phone);
|
||||
if(!matcherPhone.find()){
|
||||
textInput_phone.setError("Số điện thoại không đúng định dạng. Vui lòng kiểm tra lại!");
|
||||
//Check email valid
|
||||
Pattern patternEmail = Pattern.compile(Common.VALID_EMAIL_ADDRESS_REGEX, Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcherEmail = patternEmail.matcher(email);
|
||||
if(!matcherEmail.matches()){
|
||||
textInput_email.setError("Địa chỉ email không đúng định dạng. Xin vui lòng kiểm tra lại!");
|
||||
dataHasValidate = false;
|
||||
} else {
|
||||
textInput_phone.setErrorEnabled(false);
|
||||
textInput_email.setErrorEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +150,7 @@ public class SignInActivity extends AppCompatActivity {
|
||||
|
||||
mAuth.setLanguageCode("vi");
|
||||
|
||||
mAuth.signInWithEmailAndPassword(edt_phone.getText().toString(), edt_password.getText().toString())
|
||||
mAuth.signInWithEmailAndPassword(edt_email.getText().toString(), edt_password.getText().toString())
|
||||
.addOnCompleteListener(SignInActivity.this, new OnCompleteListener<AuthResult>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<AuthResult> task) {
|
||||
@@ -187,12 +190,12 @@ public class SignInActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void initComponent() {
|
||||
textInput_phone = findViewById(R.id.textInput_phone);
|
||||
textInput_email = findViewById(R.id.textInput_email);
|
||||
textInput_password = findViewById(R.id.textInput_password);
|
||||
signUp_textView = findViewById(R.id.sign_up_textView);
|
||||
forgotPassword_textView = findViewById(R.id.forgotPassword_textView);
|
||||
back_image = findViewById(R.id.back_image);
|
||||
edt_phone = findViewById(R.id.edt_email);
|
||||
edt_email = findViewById(R.id.edt_email);
|
||||
edt_password = findViewById(R.id.edt_password);
|
||||
|
||||
signInButton = findViewById(R.id.sign_in_button);
|
||||
@@ -201,7 +204,7 @@ public class SignInActivity extends AppCompatActivity {
|
||||
|
||||
}
|
||||
private void setFontUI() {
|
||||
textInput_phone.setTypeface(Common.setFontBebas(getAssets()));
|
||||
textInput_email.setTypeface(Common.setFontBebas(getAssets()));
|
||||
textInput_password.setTypeface(Common.setFontBebas(getAssets()));
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,6 @@ import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class SignUpActivity extends AppCompatActivity {
|
||||
public static final String VALID_EMAIL_ADDRESS_REGEX = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$";
|
||||
public static final String FORMAT_DATE="dd/MM/yyyy";
|
||||
TextInputLayout textInput_password, textInput_phone, textInput_email,
|
||||
textInput_address, textInput_confirmPassword, textInput_fullName, textInput_birthDay;
|
||||
@@ -169,7 +168,7 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
getDataFromForm();
|
||||
|
||||
//Check email valid
|
||||
Pattern patternEmail = Pattern.compile(VALID_EMAIL_ADDRESS_REGEX, Pattern.CASE_INSENSITIVE);
|
||||
Pattern patternEmail = Pattern.compile(Common.VALID_EMAIL_ADDRESS_REGEX, Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcherEmail = patternEmail.matcher(email);
|
||||
if(!matcherEmail.matches()){
|
||||
textInput_email.setError("Địa chỉ email không đúng định dạng. Xin vui lòng kiểm tra lại!");
|
||||
@@ -310,6 +309,7 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
intent.putExtra("phone", edt_phone.getText().toString());
|
||||
intent.putExtra("verificationId", verificationId);
|
||||
intent.putExtra("token", forceResendingToken);
|
||||
intent.putExtra("password", password);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -44,10 +44,11 @@ public class VerifyAccountActivity extends AppCompatActivity {
|
||||
private EditText inputCode1, inputCode2, inputCode3, inputCode4, inputCode5, inputCode6;
|
||||
ImageView close_image;
|
||||
MaterialButton confirm_code;
|
||||
String verificationId, phone = null;
|
||||
String verificationId, phone, password = null;
|
||||
ConstraintLayout progressLayout;
|
||||
TextView resendCodeText, resendCodeTextButton, countDown, errorText;
|
||||
User user;
|
||||
FirebaseAuth mAuth;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -61,8 +62,12 @@ public class VerifyAccountActivity extends AppCompatActivity {
|
||||
verificationId = getIntent().getStringExtra("verificationId");
|
||||
phone = getIntent().getStringExtra("phone");
|
||||
user = (User) getIntent().getSerializableExtra("user");
|
||||
password = getIntent().getStringExtra("password");
|
||||
}
|
||||
|
||||
//Init firebase auth
|
||||
mAuth = FirebaseAuth.getInstance();
|
||||
|
||||
|
||||
//Init text changedListener
|
||||
textChangedListenerEditTextOTP();
|
||||
@@ -166,7 +171,7 @@ public class VerifyAccountActivity extends AppCompatActivity {
|
||||
inputCode4.getText().toString() +
|
||||
inputCode5.getText().toString() +
|
||||
inputCode6.getText().toString();
|
||||
if(verificationId != null) {
|
||||
if(verificationId != null && user != null && password != null) {
|
||||
//Show progress bar
|
||||
progressLayout.setVisibility(View.VISIBLE);
|
||||
|
||||
@@ -174,34 +179,41 @@ public class VerifyAccountActivity extends AppCompatActivity {
|
||||
verificationId,
|
||||
code
|
||||
);
|
||||
FirebaseAuth.getInstance().signInWithCredential(phoneAuthCredential)
|
||||
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<AuthResult> task) {
|
||||
//Dismiss progress layout
|
||||
progressLayout.setVisibility(View.GONE);
|
||||
|
||||
if(task.isSuccessful()) {
|
||||
if(phoneAuthCredential.getSmsCode().equals(code)){
|
||||
//Create user account
|
||||
mAuth.createUserWithEmailAndPassword(user.getEmail(), password)
|
||||
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<AuthResult> task) {
|
||||
if(task.isSuccessful()){
|
||||
//Add information user to server
|
||||
FoodApi.apiService.register(user).enqueue(new Callback<User>() {
|
||||
@Override
|
||||
public void onResponse(Call<User> call, Response<User> response) {
|
||||
|
||||
//Add information user to server
|
||||
FoodApi.apiService.register(user).enqueue(new Callback<User>() {
|
||||
@Override
|
||||
public void onResponse(Call<User> call, Response<User> response) {
|
||||
//Create user success;
|
||||
Toast.makeText(VerifyAccountActivity.this, "Tạo tài khoản thành công!", Toast.LENGTH_SHORT).show();
|
||||
startActivity(new Intent(VerifyAccountActivity.this, SignInActivity.class));
|
||||
}
|
||||
progressLayout.setVisibility(View.GONE);
|
||||
//Create user success;
|
||||
Toast.makeText(VerifyAccountActivity.this, "Tạo tài khoản thành công!", Toast.LENGTH_SHORT).show();
|
||||
startActivity(new Intent(VerifyAccountActivity.this, SignInActivity.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<User> call, Throwable t) {
|
||||
Common.showErrorServerNotification(VerifyAccountActivity.this);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Toast.makeText(VerifyAccountActivity.this, "Mã code không đúng. Vui lòng kiểm tra lại!", Toast.LENGTH_SHORT).show();
|
||||
@Override
|
||||
public void onFailure(Call<User> call, Throwable t) {
|
||||
progressLayout.setVisibility(View.GONE);
|
||||
showErrorText(t.toString());
|
||||
Common.showErrorServerNotification(VerifyAccountActivity.this);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
progressLayout.setVisibility(View.GONE);
|
||||
Common.showErrorServerNotification(VerifyAccountActivity.this);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Common {
|
||||
public static final String VALID_EMAIL_ADDRESS_REGEX = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$";
|
||||
public static final String PHONE_CODE = "+84";
|
||||
public static final String PASSWORD_PATTERN = "^(?=.*[0-9])(?=.*[A-Z])(?=.*[@#$%^&+=!_])(?=\\S+$).{4,}$";
|
||||
public static final String PHONE_PATTERN = "^0[98753]{1}\\d{8}$";
|
||||
|
||||
@@ -40,14 +40,14 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/textInput_phone"
|
||||
android:id="@+id/textInput_email"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginRight="20dp"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:hint="@string/phone"
|
||||
android:hint="@string/email_text"
|
||||
app:boxBackgroundColor="@color/white"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/logo_image"
|
||||
@@ -58,7 +58,7 @@
|
||||
android:id="@+id/edt_email"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:inputType="phone" />
|
||||
android:inputType="textEmailAddress" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
app:boxBackgroundColor="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textInput_phone"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textInput_email"
|
||||
app:passwordToggleEnabled="true"
|
||||
app:passwordToggleTint="@color/primaryColor"
|
||||
app:startIconDrawable="@drawable/baseline_vpn_key_24"
|
||||
|
||||
Reference in New Issue
Block a user