Browse Source

[完善]忘记密码短信修改

beijing
邵佳豪 2 years ago
parent
commit
981682844c
  1. 4
      src/app/pages/change-password/change-password.component.ts
  2. 15
      src/app/pages/home/home.component.ts
  3. 10
      src/app/pages/login/forget/forget.component.html
  4. 82
      src/app/pages/login/forget/forget.component.ts
  5. 18
      src/app/pages/login/login.component.ts

4
src/app/pages/change-password/change-password.component.ts

@ -33,7 +33,7 @@ export class MyValidators extends Validators {
return null; return null;
} }
return isPassword(value) ? null : { mobile: { 'zh-cn': `长度 12 位以上,包含①大写字母、②小写字母、③数字、④特殊字符四种中的三种组合`, en: `Password phone number is not valid` } }; return isPassword(value) ? null : { mobile: { 'zh-cn': `长度至少 8 位,必须包含大写字母、小写字母、数字、符号四种中的三种,且口令禁止包含 sinochem、sino、zhonghua (含大小写变体) 等中国中化相关字符`, en: `Password phone number is not valid` } };
} }
} }
@ -41,5 +41,5 @@ function isEmptyInputValue(value: NzSafeAny): boolean {
return value == null || value.length === 0; return value == null || value.length === 0;
} }
function isPassword(value: string): boolean { function isPassword(value: string): boolean {
return typeof value === 'string' && /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{12,99}$/.test(value); return typeof value === 'string' && /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)(?!.*[sS][iI][nN][oO].*)(?!.*[zZ][hH][oO][nN][gG][hH][uU][aA].*)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{8,99}$/.test(value);
} }

15
src/app/pages/home/home.component.ts

@ -503,13 +503,12 @@ export class HomeComponent implements OnInit {
} }
} }
} }
// this.router.navigate([this.menuList2[0].url]) if (this.menuList2.length == 0) {
if (this.menuList2[0].url) {
window.open(this.menuList2[0].url)
} else {
this.message.create('warning', '未分配系统管理菜单'); this.message.create('warning', '未分配系统管理菜单');
return
} else {
window.open(this.menuList2[0].url)
} }
} }
goback() { goback() {
this.router.navigate(['/plan']) this.router.navigate(['/plan'])
@ -568,10 +567,14 @@ export class HomeComponent implements OnInit {
nzComponentParams: {}, nzComponentParams: {},
nzOnOk: async () => { nzOnOk: async () => {
if (instance.validateForm.valid) { if (instance.validateForm.valid) {
let word = JSON.parse(JSON.stringify(instance.validateForm.value.newpassword)).toLowerCase()
if (instance.validateForm.value.newpassword != instance.validateForm.value.affirmpassword) { if (instance.validateForm.value.newpassword != instance.validateForm.value.affirmpassword) {
this.message.create('warning', '两次密码输入不一致!'); this.message.create('warning', '两次密码输入不一致!');
return false return false
} else { } if (word.indexOf('sino') != -1 || word.indexOf('zhonghua') != -1) {
this.message.create('warning', '口令禁止包含 sinochem、sino、zhonghua (含大小写变体) 等中国中化相关字符');
return false
} else {
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
let body = { let body = {
currentPassword: instance.validateForm.value.oldpassword, currentPassword: instance.validateForm.value.oldpassword,

10
src/app/pages/login/forget/forget.component.html

@ -14,7 +14,8 @@
</div> </div>
<div class="step2" *ngIf="currentStep == 2"> <div class="step2" *ngIf="currentStep == 2">
<div class="phonebox"> <div class="phonebox">
该账号绑定的手机号为:13864340193 <button type="button" nz-button nzType="primary">点击获取验证码</button> 该账号绑定的手机号为:{{phoneNum}} <button [nzLoading]="codeCountDown != 0" type="button" nz-button nzType="primary"
(click)="code()">{{ codeCountDown == 0 ? '点击获取验证码' : codeCountDown + '秒后可重新获取'}}</button>
</div> </div>
<form nz-form [formGroup]="validateForm2" (ngSubmit)="step2()"> <form nz-form [formGroup]="validateForm2" (ngSubmit)="step2()">
<nz-form-item> <nz-form-item>
@ -30,13 +31,6 @@
</div> </div>
<div class="step3" *ngIf="currentStep == 3"> <div class="step3" *ngIf="currentStep == 3">
<form nz-form [formGroup]="validateForm3" (ngSubmit)="step3()"> <form nz-form [formGroup]="validateForm3" (ngSubmit)="step3()">
<nz-form-item>
<!-- <nz-form-label nzRequired nzFor="">请输入原密码</nz-form-label> -->
<nz-form-control>
<input name="oldpassword" nz-input type="password" formControlName="oldpassword"
placeholder="请输入原密码" autocomplete="off" />
</nz-form-control>
</nz-form-item>
<nz-form-item> <nz-form-item>
<!-- <nz-form-label nzRequired nzFor="">请输入新密码</nz-form-label> --> <!-- <nz-form-label nzRequired nzFor="">请输入新密码</nz-form-label> -->
<nz-form-control> <nz-form-control>

82
src/app/pages/login/forget/forget.component.ts

@ -3,6 +3,7 @@ import { FormBuilder, FormGroup, Validators, AbstractControl } from '@angular/fo
import { NzMessageService } from 'ng-zorro-antd/message'; import { NzMessageService } from 'ng-zorro-antd/message';
import { NzSafeAny } from 'ng-zorro-antd/core/types'; import { NzSafeAny } from 'ng-zorro-antd/core/types';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { NzModalRef } from 'ng-zorro-antd/modal';
@Component({ @Component({
selector: 'app-forget', selector: 'app-forget',
templateUrl: './forget.component.html', templateUrl: './forget.component.html',
@ -12,7 +13,7 @@ export class ForgetComponent implements OnInit {
validateForm!: FormGroup; validateForm!: FormGroup;
validateForm2!: FormGroup; validateForm2!: FormGroup;
validateForm3!: FormGroup; validateForm3!: FormGroup;
constructor(private fb: FormBuilder, private message: NzMessageService, private http: HttpClient) { } constructor(private fb: FormBuilder, private message: NzMessageService, private http: HttpClient, private modal: NzModalRef) { }
ngOnInit(): void { ngOnInit(): void {
this.validateForm = this.fb.group({ this.validateForm = this.fb.group({
@ -23,47 +24,92 @@ export class ForgetComponent implements OnInit {
}); });
const { password } = MyValidators; const { password } = MyValidators;
this.validateForm3 = this.fb.group({ this.validateForm3 = this.fb.group({
oldpassword: [null, [Validators.required]],
newpassword: [null, [Validators.required, password]], newpassword: [null, [Validators.required, password]],
affirmpassword: [null, [Validators.required, password]] affirmpassword: [null, [Validators.required, password]]
}); });
} }
currentStep = 1 currentStep = 1
phoneNum: string
step1() { step1() {
console.log(this.validateForm) console.log(this.validateForm)
if (this.validateForm.invalid) { if (this.validateForm.invalid) {
this.message.create('warning', '请填写完整'); this.message.create('warning', '请填写完整');
} else { } else {
this.currentStep = 2 this.http.get('/api/services/app/User/GetPhoneNumber', {
params: {
userName: this.validateForm.value.account
}
}).subscribe({
next: (data: any) => {
this.phoneNum = data.result
this.currentStep = 2
}
})
} }
} }
//发送验证码
codeCountDown = 0
code() {
let params = {
userName: this.validateForm.value.account,
}
this.http.post('/api/services/app/User/SendVerificationCode', null, { params: params }).subscribe({
next: (data: any) => {
this.message.create('success', '已发送');
//按钮倒计时
this.codeCountDown = 30
let codesetInterval = setInterval(() => {
this.codeCountDown = this.codeCountDown - 1
if (this.codeCountDown == 0) {
clearInterval(codesetInterval)
}
}, 1000);
}
})
}
step2() { step2() {
if (this.validateForm2.invalid) { if (this.validateForm2.invalid) {
this.message.create('warning', '请填写完整'); this.message.create('warning', '请填写完整');
} else { } else {
this.currentStep = 3 console.log(this.validateForm.value.account)
let params = {
userName: this.validateForm.value.account,
code: this.validateForm2.value.code
}
this.http.get('/api/services/app/User/VerifyVerificationCode', { params: params }).subscribe({
next: (data: any) => {
this.currentStep = 3
}
})
} }
} }
step3() { step3() {
if (this.validateForm3.valid) { if (this.validateForm3.valid) {
let word = JSON.parse(JSON.stringify(this.validateForm3.value.newpassword)).toLowerCase()
if (this.validateForm3.value.newpassword != this.validateForm3.value.affirmpassword) { if (this.validateForm3.value.newpassword != this.validateForm3.value.affirmpassword) {
this.message.create('warning', '两次密码输入不一致!'); this.message.create('warning', '两次密码输入不一致!');
return false return false
} if (word.indexOf('sino') != -1 || word.indexOf('zhonghua') != -1) {
this.message.create('warning', '口令禁止包含 sinochem、sino、zhonghua (含大小写变体) 等中国中化相关字符');
return false
} else { } else {
// let body = { let body = {
// currentPassword: this.validateForm3.value.oldpassword, userName: this.validateForm.value.account,
// newPassword: this.validateForm3.value.newpassword code: this.validateForm2.value.code,
// } newPassword: this.validateForm3.value.newpassword,
// this.http.post('/api/services/app/User/ChangePassword', body).subscribe(data => { }
this.http.post('/api/services/app/User/ChangePasswordBySms', body).subscribe(data => {
// this.message.create('success', '修改成功!'); this.message.create('success', '修改成功!');
// return true this.modal.close()
// }, err => { return true
// this.message.create('warning', err.error.error.message); }, err => {
// return false return false
// }) })
} }
@ -86,7 +132,7 @@ export class MyValidators extends Validators {
return null; return null;
} }
return isPassword(value) ? null : { mobile: { 'zh-cn': `长度 12 位以上,包含①大写字母、②小写字母、③数字、④特殊字符四种中的三种组合`, en: `Password phone number is not valid` } }; return isPassword(value) ? null : { mobile: { 'zh-cn': `长度至少 8 位,必须包含大写字母、小写字母、数字、符号四种中的三种,且口令禁止包含 sinochem、sino、zhonghua (含大小写变体) 等中国中化相关字符`, en: `Password phone number is not valid` } };
} }
} }
@ -94,5 +140,5 @@ function isEmptyInputValue(value: NzSafeAny): boolean {
return value == null || value.length === 0; return value == null || value.length === 0;
} }
function isPassword(value: string): boolean { function isPassword(value: string): boolean {
return typeof value === 'string' && /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{12,99}$/.test(value); return typeof value === 'string' && /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)(?!.*[sS][iI][nN][oO].*)(?!.*[zZ][hH][oO][nN][gG][hH][uU][aA].*)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{8,99}$/.test(value);
} }

18
src/app/pages/login/login.component.ts

@ -236,15 +236,15 @@ export class LoginComponent implements OnInit {
return menuList return menuList
} }
forget() { forget() {
this.message.create('warning', `请联系管理员`); // this.message.create('warning', `请联系管理员`);
// this.modal.create({ this.modal.create({
// nzTitle: '忘记密码', nzTitle: '忘记密码',
// nzContent: ForgetComponent, nzContent: ForgetComponent,
// nzViewContainerRef: this.viewContainerRef, nzViewContainerRef: this.viewContainerRef,
// nzWidth: 288, nzWidth: 288,
// nzComponentParams: {}, nzComponentParams: {},
// nzFooter: null nzFooter: null
// }); });
} }
} }

Loading…
Cancel
Save