mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-22 20:00:53 +00:00
Up code
This commit is contained in:
@@ -4,14 +4,20 @@ import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
import com.google.firebase.auth.PhoneAuthProvider;
|
||||
import com.google.firebase.database.DataSnapshot;
|
||||
import com.google.firebase.database.DatabaseError;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
@@ -22,7 +28,7 @@ import com.waterbase.foodify.Model.User;
|
||||
|
||||
public class SignUp extends AppCompatActivity {
|
||||
|
||||
EditText edtPhone, edtName, edtPassword;
|
||||
EditText edtPhone, edtName, edtPassword, edtEmail;
|
||||
Button btnSignUp;
|
||||
TextView txtAppName;
|
||||
|
||||
@@ -34,7 +40,7 @@ public class SignUp extends AppCompatActivity {
|
||||
edtName = (EditText) findViewById(R.id.txtFullName);
|
||||
edtPassword = (EditText) findViewById(R.id.edtPassword);
|
||||
edtPhone = (EditText) findViewById(R.id.edtPhone);
|
||||
|
||||
edtEmail = (EditText) findViewById(R.id.edtEmail);
|
||||
btnSignUp = (Button) findViewById(R.id.btnSignUp);
|
||||
|
||||
txtAppName = (TextView) findViewById(R.id.txtAppName);
|
||||
@@ -49,35 +55,54 @@ public class SignUp extends AppCompatActivity {
|
||||
btnSignUp.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (Common.isConnectedToInternet(getBaseContext())) {
|
||||
final ProgressDialog mDialog = new ProgressDialog(SignUp.this);
|
||||
mDialog.setMessage("Please waiting...");
|
||||
mDialog.show();
|
||||
if(!TextUtils.isEmpty(edtName.getText().toString()) && !TextUtils.isEmpty(edtPassword.getText().toString())
|
||||
&& !TextUtils.isEmpty(edtPhone.getText().toString()) && !TextUtils.isEmpty(edtEmail.getText().toString())) {
|
||||
if (Common.isConnectedToInternet(getBaseContext())) {
|
||||
final ProgressDialog mDialog = new ProgressDialog(SignUp.this);
|
||||
mDialog.setMessage("Vui lòng chờ...");
|
||||
mDialog.show();
|
||||
|
||||
table_user.addListenerForSingleValueEvent(new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||
//Check if already user phone
|
||||
if (dataSnapshot.child(edtPhone.getText().toString()).exists()) {
|
||||
mDialog.dismiss();
|
||||
Toast.makeText(SignUp.this, "Phone Number is already register!", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
} else {
|
||||
mDialog.dismiss();
|
||||
User user = new User(edtName.getText().toString(), edtPassword.getText().toString());
|
||||
table_user.child(edtPhone.getText().toString()).setValue(user);
|
||||
Toast.makeText(SignUp.this, "Sign up successfully!", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
table_user.addListenerForSingleValueEvent(new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||
//Check if already user phone
|
||||
if (dataSnapshot.child(edtPhone.getText().toString()).exists()) {
|
||||
mDialog.dismiss();
|
||||
Toast.makeText(SignUp.this, "Số điện thoại đã được đăng ký!", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
} else {
|
||||
//Firebase Auth
|
||||
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
|
||||
firebaseAuth.createUserWithEmailAndPassword(edtEmail.getText().toString(), edtPassword.getText().toString()).addOnCompleteListener((task) -> {
|
||||
if(task.isSuccessful()) {
|
||||
firebaseAuth.getCurrentUser().sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
if(task.isSuccessful()) {
|
||||
mDialog.dismiss();
|
||||
User user = new User(edtName.getText().toString(), edtPassword.getText().toString());
|
||||
table_user.child(edtPhone.getText().toString()).setValue(user);
|
||||
Toast.makeText(SignUp.this, "Đăng ký thành công!", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled(DatabaseError databaseError) {
|
||||
@Override
|
||||
public void onCancelled(DatabaseError databaseError) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Toast.makeText(SignUp.this, "Vui lòng kiểm tra kết nối mạng!", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(SignUp.this, "Vui lòng kiểm tra kết nối mạng!", Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(SignUp.this, "Vui lòng điền đầy đủ thông tin!", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z"/>
|
||||
</vector>
|
||||
@@ -44,11 +44,28 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/txtAppName" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/edtEmail"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:backgroundTint="#CCCCCC"
|
||||
android:drawableLeft="@drawable/ic_baseline_email_24"
|
||||
android:drawablePadding="13dp"
|
||||
android:hint="Email"
|
||||
android:inputType="textEmailAddress"
|
||||
android:textColor="@color/white"
|
||||
android:textColorHint="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/txtSignUp"
|
||||
app:layout_constraintWidth_percent=".8" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/txtFullName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:backgroundTint="#CCCCCC"
|
||||
android:drawableLeft="@drawable/ic_baseline_account_circle_24"
|
||||
android:drawablePadding="13dp"
|
||||
@@ -57,7 +74,7 @@
|
||||
android:textColorHint="@color/white"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/txtSignUp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/edtEmail"
|
||||
app:layout_constraintWidth_percent=".8" />
|
||||
|
||||
<EditText
|
||||
|
||||
Reference in New Issue
Block a user