Skip to content

Commit

Permalink
新增:修改密码功能和逻辑
Browse files Browse the repository at this point in the history
修改:
删除:
完成:
下一个目标:
  • Loading branch information
ACodeHX committed Jun 9, 2024
1 parent a1c851d commit 2af1a8e
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
minSdk 22
targetSdk 32
versionCode 1
versionName "1.1.0"
versionName "1.3.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/aa/takeout/DatabaseHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.aa.takeout;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import net.sqlcipher.database.SQLiteDatabase;
Expand Down Expand Up @@ -70,4 +71,13 @@ public boolean isUserExists(String username) {
db.close();
return exists;
}
//修改密码
public boolean updatePassword(String username, String newPassword) {
SQLiteDatabase db = getWritableDatabase(PASSPHRASE);
ContentValues contentValues = new ContentValues();
contentValues.put(COLUMN_PASSWORD, newPassword);
int result = db.update(TABLE_NAME, contentValues, COLUMN_USERNAME + " = ?", new String[]{username});
db.close();
return result > 0;
}
}
96 changes: 96 additions & 0 deletions app/src/main/java/com/aa/takeout/ForgetPasswd.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,109 @@
package com.aa.takeout;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import java.util.Random;

public class ForgetPasswd extends AppCompatActivity {
private EditText user, email, passwd, repasswd, authCode;
private Button sendCodeButton, modificationButton, reLogin;
private int authCodeValue;
private DatabaseHelper userDate;

@Override
protected void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.forgetpasswd);

user = findViewById(R.id.username);
email = findViewById(R.id.email1);
passwd = findViewById(R.id.passwd1);
repasswd = findViewById(R.id.mpasswd);
authCode = findViewById(R.id.authcode1);
sendCodeButton = findViewById(R.id.sendcode1);
modificationButton = findViewById(R.id.modifficationpasswd);
reLogin = findViewById(R.id.relogin);
userDate = new DatabaseHelper(this);


//发送短信
sendCodeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String emailValue = email.getText().toString();
String Emailregex = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$";
Boolean judgeEmail = false;
judgeEmail = emailValue != null && emailValue.matches(Emailregex);
if (judgeEmail) {
//设置验证码的逻辑
Random random = new Random();
authCodeValue = 100000 + random.nextInt(900000);
AlertDialog.Builder builder = new AlertDialog.Builder(ForgetPasswd.this);
builder.setTitle("请在5分钟输入你的验证码")
.setMessage("您的验证码为: " + authCodeValue)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
}).show();
} else if(emailValue.isEmpty()) {
Toast.makeText(ForgetPasswd.this, "请输入邮箱", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(ForgetPasswd.this, "请输入正确的邮箱", Toast.LENGTH_SHORT).show();
}
}
});

//修改密码
modificationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String userValue = user.getText().toString();
String emailValue = email.getText().toString();
String passValue = passwd.getText().toString();
String rePassValue = repasswd.getText().toString();
String codeValue = authCode.getText().toString();

String judgeValue = userValue.isEmpty() ? "请输入账号":
emailValue.isEmpty() ? "请输入邮箱" :
passValue.isEmpty() ? "请输入密码" :
rePassValue.isEmpty() ? "请再次输入密码" :
codeValue.isEmpty() ? "请输入验证码" :
!passValue.equals(rePassValue) ? "密码不一致" :
authCodeValue != Integer.parseInt(authCode.getText().toString()) ? "验证码不正确" :
!userDate.isUserExists(userValue) ? "用户不存在" :
null;

//判断输入是否为空
if (judgeValue != null) {
Toast.makeText(ForgetPasswd.this, judgeValue, Toast.LENGTH_SHORT).show();
return;
}

boolean isUpdated = userDate.updatePassword(userValue, passValue);
if (isUpdated) {
Toast.makeText(ForgetPasswd.this, "修改成功", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(ForgetPasswd.this, "密码修改失败", Toast.LENGTH_LONG).show();
}
}
});

//返回按键
reLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
}
}
8 changes: 4 additions & 4 deletions app/src/main/java/com/aa/takeout/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
import net.sqlcipher.database.SQLiteDatabase;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private EditText user;
private EditText password;
private EditText user, password;
private TextView forgetPasswd;
private Button loginBUT;
private Button singUpBut;
private Button loginBUT, singUpBut;
private DatabaseHelper userData;

@Override
Expand Down Expand Up @@ -51,6 +49,7 @@ public void onClick(View view) {
Toast.makeText(MainActivity.this, "登陆成功", Toast.LENGTH_SHORT).show();
Intent StoIntent = new Intent(MainActivity.this, Store.class);
startActivity(StoIntent);
finish();
} else {
Toast.makeText(MainActivity.this, "登陆失败", Toast.LENGTH_SHORT).show();
}
Expand All @@ -59,6 +58,7 @@ public void onClick(View view) {
}
}
});
//忘记密码功能
forgetPasswd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/aa/takeout/RegisterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void onClick(View view) {
if (judgeEmail) {
//设置验证码的逻辑
Random random = new Random();
authCodeValue = random.nextInt(100000);
authCodeValue = 100000 + random.nextInt(900000);
AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
builder.setTitle("请在5分钟输入你的验证码")
.setMessage("您的验证码为: " + authCodeValue)
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/aa/takeout/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public class Store extends AppCompatActivity {
private StoreAdapter storeAdapter;
private List<StoreMinute> itemList;
private TextView showStore;
private ImageView showImage;
private ImageView backLogin;
private ImageView showImage, backLogin;
private Button skipTakeout;

@Override
Expand Down
112 changes: 112 additions & 0 deletions app/src/main/res/layout/forgetpasswd.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/FF9C1A">


<TextView
android:id="@+id/textView"
android:layout_width="147dp"
android:layout_height="69dp"
android:layout_marginStart="30dp"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="修改密码"
android:textSize="20dp"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toTopOf="@+id/guideline6" />

<EditText
android:id="@+id/email1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="请输入邮箱"
android:ems="10"
android:inputType="textEmailAddress"
android:minHeight="48dp"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/username" />

<Button
android:id="@+id/sendcode1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="120dp"
android:text="发送短信"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/email1"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<EditText
android:id="@+id/passwd1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="请输入新密码"
android:ems="10"
android:inputType="textPassword"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/email1" />

<EditText
android:id="@+id/mpasswd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="请再次输入密码"
android:ems="10"
android:inputType="textPassword"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/passwd1" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="80dp" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="100dp" />

<Button
android:id="@+id/modifficationpasswd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="20dp"
android:text="修改密码"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/authcode1" />

<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:hint="请输入账号"
android:ems="10"
android:inputType="textEmailAddress"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<EditText
android:id="@+id/authcode1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="请输入验证码"
android:ems="10"
android:inputType="number"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/mpasswd" />

<Button
android:id="@+id/relogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="返回"
app:layout_constraintStart_toEndOf="@+id/modifficationpasswd"
app:layout_constraintTop_toBottomOf="@+id/authcode1" />

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 2af1a8e

Please sign in to comment.