mirror of
https://github.com/Nezumi-2711/Foodify.git
synced 2026-09-22 20:00:50 +00:00
Check phone and email user before register
This commit is contained in:
@@ -3,6 +3,7 @@ package com.capstone.foodify.API;
|
||||
import com.capstone.foodify.Model.Category;
|
||||
import com.capstone.foodify.Model.DistrictWardResponse;
|
||||
import com.capstone.foodify.Model.Food;
|
||||
import com.capstone.foodify.Model.Response.EmailOrPhoneExist;
|
||||
import com.capstone.foodify.Model.Response.Foods;
|
||||
import com.capstone.foodify.Model.Response.Shops;
|
||||
import com.capstone.foodify.Model.Shop;
|
||||
@@ -28,7 +29,7 @@ public interface FoodApi {
|
||||
Gson gson = new GsonBuilder().setDateFormat("HH:mm:ss dd-MM-yyyy").setLenient().create();
|
||||
|
||||
FoodApi apiService = new Retrofit.Builder()
|
||||
.baseUrl("http://192.168.1.183:8080/api/").addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.baseUrl("http://192.168.1.88:8080/api/").addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.build()
|
||||
.create(FoodApi.class);
|
||||
|
||||
@@ -74,4 +75,7 @@ public interface FoodApi {
|
||||
@Headers({"accept: */*", "Content-Type: application/json"})
|
||||
@POST("auth/signup")
|
||||
Call<User> register(@Body User user);
|
||||
|
||||
@POST("auth/check")
|
||||
Call<EmailOrPhoneExist> checkEmailOrPhoneExist (@Body User user);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public interface FoodApiToken {
|
||||
|
||||
FoodApiToken apiService = new Retrofit.Builder()
|
||||
.client(client)
|
||||
.baseUrl("http://192.168.1.183:8080/api/").addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.baseUrl("http://192.168.1.88:8080/api/").addConverterFactory(GsonConverterFactory.create(gson))
|
||||
.build()
|
||||
.create(FoodApiToken.class);
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ import com.capstone.foodify.API.FoodApi;
|
||||
import com.capstone.foodify.Common;
|
||||
import com.capstone.foodify.Model.Address;
|
||||
import com.capstone.foodify.Model.DistrictWardResponse;
|
||||
import com.capstone.foodify.Model.Response.EmailOrPhoneExist;
|
||||
import com.capstone.foodify.Model.User;
|
||||
import com.capstone.foodify.R;
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
@@ -152,15 +153,53 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
signUpButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//TODO Check user have exits in database before sign up
|
||||
if(validateData()){
|
||||
loading();
|
||||
signUp();
|
||||
checkEmailOrPhoneExist();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void checkEmailOrPhoneExist(){
|
||||
//Create user object
|
||||
User user = new User();
|
||||
user.setAddress(new Address(address, ward, district));
|
||||
user.setDateOfBirth(dateOfBirth);
|
||||
user.setEmail(email);
|
||||
user.setFullName(name);
|
||||
user.setIdentifiedCode("");
|
||||
user.setImageUrl("");
|
||||
user.setLocked(false);
|
||||
user.setPhoneNumber(phone);
|
||||
user.setRoleName("ROLE_USER");
|
||||
|
||||
FoodApi.apiService.checkEmailOrPhoneExist(user).enqueue(new Callback<EmailOrPhoneExist>() {
|
||||
@Override
|
||||
public void onResponse(Call<EmailOrPhoneExist> call, Response<EmailOrPhoneExist> response) {
|
||||
EmailOrPhoneExist dataTemp = response.body();
|
||||
|
||||
boolean isExist = false;
|
||||
|
||||
if(dataTemp != null)
|
||||
isExist = dataTemp.isTrue();
|
||||
|
||||
if(!isExist){
|
||||
//If user not exist on database, the app will create account
|
||||
signUp(user);
|
||||
} else {
|
||||
loadCompleted();
|
||||
Toast.makeText(SignUpActivity.this, "Email or Phone exist!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<EmailOrPhoneExist> call, Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private boolean validateData(){
|
||||
boolean dataHasValidate = true;
|
||||
|
||||
@@ -280,7 +319,7 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void signUp(){
|
||||
private void signUp(User user){
|
||||
FirebaseAuth auth = FirebaseAuth.getInstance();
|
||||
PhoneAuthOptions options = PhoneAuthOptions.newBuilder(auth)
|
||||
.setPhoneNumber(Common.PHONE_CODE + edt_phone.getText().toString())
|
||||
@@ -292,18 +331,6 @@ public class SignUpActivity extends AppCompatActivity {
|
||||
@NonNull PhoneAuthProvider.ForceResendingToken forceResendingToken) {
|
||||
loadCompleted();
|
||||
|
||||
//Create user object
|
||||
User user = new User();
|
||||
user.setAddress(new Address(address, ward, district));
|
||||
user.setDateOfBirth(dateOfBirth);
|
||||
user.setEmail(email);
|
||||
user.setFullName(name);
|
||||
user.setIdentifiedCode("");
|
||||
user.setImageUrl("");
|
||||
user.setLocked(false);
|
||||
user.setPhoneNumber(phone);
|
||||
user.setRoleName("ROLE_USER");
|
||||
|
||||
Intent intent = new Intent(SignUpActivity.this, VerifyAccountActivity.class);
|
||||
intent.putExtra("user", user);
|
||||
intent.putExtra("phone", edt_phone.getText().toString());
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.capstone.foodify.Model.Response;
|
||||
|
||||
public class EmailOrPhoneExist {
|
||||
private String title;
|
||||
private boolean isTrue;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public boolean isTrue() {
|
||||
return isTrue;
|
||||
}
|
||||
|
||||
public void setTrue(boolean aTrue) {
|
||||
isTrue = aTrue;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user