mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-22 13:48:29 +00:00
Change Password Function
This commit is contained in:
@@ -58,6 +58,7 @@ dependencies {
|
||||
implementation 'com.stepstone.apprating:app-rating:2.0.0'
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.7.1'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.7.1'
|
||||
implementation 'com.github.d-max:spots-dialog:0.7@aar'
|
||||
|
||||
implementation 'com.squareup.picasso:picasso:2.5.2'
|
||||
implementation 'com.firebaseui:firebase-ui-database:1.2.0'
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.waterbase.foodify;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@@ -10,6 +12,7 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.view.GravityCompat;
|
||||
@@ -19,10 +22,14 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.firebase.ui.database.FirebaseRecyclerAdapter;
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.OnFailureListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.firebase.iid.FirebaseInstanceId;
|
||||
import com.rengwuxian.materialedittext.MaterialEditText;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.waterbase.foodify.Common.Common;
|
||||
import com.waterbase.foodify.Interface.ItemClickListener;
|
||||
@@ -30,6 +37,10 @@ import com.waterbase.foodify.Model.Category;
|
||||
import com.waterbase.foodify.Model.Token;
|
||||
import com.waterbase.foodify.ViewHolder.MenuViewHolder;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import dmax.dialog.SpotsDialog;
|
||||
import io.paperdb.Paper;
|
||||
|
||||
|
||||
@@ -148,7 +159,10 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
||||
} else if (id == R.id.nav_order) {
|
||||
Intent orderIntent = new Intent(Home.this, OrderStatus.class);
|
||||
startActivity(orderIntent);
|
||||
} else if (id == R.id.nav_log_out) {
|
||||
} else if (id == R.id.nav_change_pwd) {
|
||||
showChangePasswordDialog();
|
||||
}
|
||||
else if (id == R.id.nav_log_out) {
|
||||
|
||||
//Delete Remember user & password
|
||||
Paper.book().destroy();
|
||||
@@ -165,4 +179,66 @@ public class Home extends AppCompatActivity implements NavigationView.OnNavigati
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void showChangePasswordDialog() {
|
||||
AlertDialog.Builder alertDialog = new AlertDialog.Builder(Home.this);
|
||||
alertDialog.setTitle("Đổi mật khẩu");
|
||||
alertDialog.setMessage("Vui lòng điền đầy đủ thông tin");
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(this);
|
||||
View layout_pwd = inflater.inflate(R.layout.change_password_layout, null);
|
||||
|
||||
MaterialEditText edtPassword = (MaterialEditText) layout_pwd.findViewById(R.id.edtPassword);
|
||||
MaterialEditText edtNewPassword = (MaterialEditText) layout_pwd.findViewById(R.id.edtNewPassword);
|
||||
MaterialEditText edtRepeatPassword = (MaterialEditText) layout_pwd.findViewById(R.id.edtRepeatPassword);
|
||||
|
||||
alertDialog.setView(layout_pwd);
|
||||
|
||||
//Button
|
||||
alertDialog.setPositiveButton("Đổi mật khẩu", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
android.app.AlertDialog waitingDialog = new SpotsDialog(Home.this);
|
||||
waitingDialog.show();
|
||||
|
||||
//Check old password
|
||||
if(edtPassword.getText().toString().equals(Common.currentUser.getPassword())) {
|
||||
|
||||
//Check new password and repeat password
|
||||
if(edtNewPassword.getText().toString().equals(edtRepeatPassword.getText().toString())){
|
||||
Map<String, Object> passwordUpdate = new HashMap<>();
|
||||
passwordUpdate.put("password", edtNewPassword.getText().toString());
|
||||
|
||||
//Make update
|
||||
DatabaseReference user = FirebaseDatabase.getInstance().getReference("User");
|
||||
user.child(Common.currentUser.getPhone())
|
||||
.updateChildren(passwordUpdate)
|
||||
.addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
waitingDialog.dismiss();
|
||||
Toast.makeText(Home.this, "Mật khẩu đã được cập nhật!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
})
|
||||
.addOnFailureListener(new OnFailureListener() {
|
||||
@Override
|
||||
public void onFailure(@NonNull Exception e) {
|
||||
Toast.makeText(Home.this, "Đã xảy ra lỗi hệ thống: " + e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
waitingDialog.dismiss();
|
||||
Toast.makeText(Home.this, "Mật khẩu chưa khớp! Vui lòng thử lại!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
waitingDialog.dismiss();
|
||||
Toast.makeText(Home.this, "Sai mật khẩu! Vui lòng thử lại!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog dialog = alertDialog.create();
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,8 @@ public class SignIn extends AppCompatActivity {
|
||||
Common.currentUser = user;
|
||||
startActivity(homeIntent);
|
||||
finish();
|
||||
|
||||
table_user.removeEventListener(this);
|
||||
} else {
|
||||
Toast.makeText(SignIn.this, "Số điện thoại hoặc mật khẩu không đúng. Xin vui lòng thử lại!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="#000000"
|
||||
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="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12L21,5l-9,-4zM12,11.99h7c-0.53,4.12 -3.28,7.79 -7,8.94L12,12L5,12L5,6.3l7,-3.11v8.8z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.cardview.widget.CardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:cardElevation="10dp"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="20dp">
|
||||
|
||||
<com.rengwuxian.materialedittext.MaterialEditText
|
||||
android:id="@+id/edtPassword"
|
||||
android:hint="Mật khẩu"
|
||||
android:inputType="textPassword"
|
||||
android:text=""
|
||||
android:textColor="@color/colorPrimary"
|
||||
android:textColorHint="@color/colorPrimary"
|
||||
android:textSize="24sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:met_baseColor="@color/colorPrimary"
|
||||
app:met_floatingLabel="highlight"
|
||||
app:met_primaryColor="@color/colorPrimary"
|
||||
app:met_singleLineEllipsis="true"
|
||||
/>
|
||||
|
||||
<com.rengwuxian.materialedittext.MaterialEditText
|
||||
android:id="@+id/edtNewPassword"
|
||||
android:hint="Mật khẩu mới"
|
||||
android:inputType="textPassword"
|
||||
android:text=""
|
||||
android:textColor="@color/colorPrimary"
|
||||
android:textColorHint="@color/colorPrimary"
|
||||
android:textSize="24sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:met_baseColor="@color/colorPrimary"
|
||||
app:met_floatingLabel="highlight"
|
||||
app:met_primaryColor="@color/colorPrimary"
|
||||
app:met_singleLineEllipsis="true"
|
||||
/>
|
||||
|
||||
<com.rengwuxian.materialedittext.MaterialEditText
|
||||
android:id="@+id/edtRepeatPassword"
|
||||
android:hint="Nhập lại mật khẩu"
|
||||
android:inputType="textPassword"
|
||||
android:text=""
|
||||
android:textColor="@color/colorPrimary"
|
||||
android:textColorHint="@color/colorPrimary"
|
||||
android:textSize="24sp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:met_baseColor="@color/colorPrimary"
|
||||
app:met_floatingLabel="highlight"
|
||||
app:met_primaryColor="@color/colorPrimary"
|
||||
app:met_singleLineEllipsis="true"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
@@ -12,6 +12,13 @@
|
||||
android:id="@+id/nav_order"
|
||||
android:icon="@drawable/ic_baseline_access_time_24"
|
||||
android:title="Tình trạng đơn hàng" />
|
||||
|
||||
<item
|
||||
android:id="@+id/nav_change_pwd"
|
||||
android:icon="@drawable/ic_baseline_security_24"
|
||||
android:title="Đổi mật khẩu"
|
||||
android:iconTint="@color/white"
|
||||
/>
|
||||
<item
|
||||
android:id="@+id/nav_log_out"
|
||||
android:icon="@drawable/ic_baseline_exit_to_app_24"
|
||||
|
||||
@@ -4,7 +4,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.2.0'
|
||||
classpath 'com.android.tools.build:gradle:7.0.1'
|
||||
classpath 'com.google.gms:google-services:4.3.10'
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user