-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
修改: 删除: 完成: 下一个目标:
- Loading branch information
Showing
8 changed files
with
226 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |