Commit 921c2e94 authored by wangqinghua's avatar wangqinghua

update

parent 1fe82deb
...@@ -4,6 +4,8 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms'; ...@@ -4,6 +4,8 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {NzMessageComponent, NzMessageService} from 'ng-zorro-antd'; import {NzMessageComponent, NzMessageService} from 'ng-zorro-antd';
import {LayoutService} from '../../layouts/layout.service'; import {LayoutService} from '../../layouts/layout.service';
import {LoginService} from '../../shared'; import {LoginService} from '../../shared';
import {Base64} from 'js-base64';
import {LocalStorageService} from 'ngx-webstorage';
@Component({ @Component({
selector: 'smart-modify-password', selector: 'smart-modify-password',
...@@ -16,11 +18,14 @@ export class ModifyPasswordComponent implements OnInit { ...@@ -16,11 +18,14 @@ export class ModifyPasswordComponent implements OnInit {
isOkLoading = false; isOkLoading = false;
title = '修改密码'; title = '修改密码';
validateForm: FormGroup; validateForm: FormGroup;
reg = new RegExp(/^(?=[a-zA-Z]+\d+)\w{8,20}$/);
groupid; groupid;
constructor(private fb: FormBuilder, private layoutSer: LayoutService, constructor(private fb: FormBuilder, private layoutSer: LayoutService,
private message: NzMessageService,private loginService:LoginService) {} private $localStorage: LocalStorageService,
private message: NzMessageService, private loginService: LoginService) {
}
ngOnInit() { ngOnInit() {
this.initForm(); this.initForm();
...@@ -38,18 +43,47 @@ export class ModifyPasswordComponent implements OnInit { ...@@ -38,18 +43,47 @@ export class ModifyPasswordComponent implements OnInit {
if (this.validateForm.invalid) { if (this.validateForm.invalid) {
return false; return false;
} }
if(this.validateForm.value.newPassword != this.validateForm.value.realPassword){ if (this.validateForm.value.newPassword != this.validateForm.value.realPassword) {
this.message.error("两次输入密码不一致"); this.message.error('两次输入密码不一致');
return false; return false;
} }
this.isOkLoading = true; this.isOkLoading = true;
this.update(); this.getOldEncodepassword();
}
//获取旧密码加密
getOldEncodepassword() {
const data = {
userName: this.$localStorage.retrieve('userInfo').userName,
password: Base64.encode(this.validateForm.value.oldPassword)
};
this.layoutSer.encodePassword(data).subscribe(
(res) => {
this.validateForm.patchValue({oldPassword: res.data});
this.getNewEncodepassword();
}
);
}
//获取新密码加密
getNewEncodepassword() {
const data = {
userName: this.$localStorage.retrieve('userInfo').userName,
password: Base64.encode(this.validateForm.value.realPassword)
};
this.layoutSer.encodePassword(data).subscribe(
(res) => {
this.validateForm.patchValue({realPassword: res.data});
this.validateForm.patchValue({newPassword: res.data});
this.update();
}
);
} }
update() { update() {
let formData = new FormData(); let formData = new FormData();
formData.append('newPassword',this.validateForm.value.realPassword); formData.append('newPassword', this.validateForm.value.realPassword);
formData.append('oldPassword',this.validateForm.value.oldPassword); formData.append('oldPassword', this.validateForm.value.oldPassword);
this.layoutSer.modifyPassword(formData).subscribe( this.layoutSer.modifyPassword(formData).subscribe(
(res) => { (res) => {
if (res.errCode == 10000) { if (res.errCode == 10000) {
...@@ -72,8 +106,8 @@ export class ModifyPasswordComponent implements OnInit { ...@@ -72,8 +106,8 @@ export class ModifyPasswordComponent implements OnInit {
initForm() { initForm() {
this.validateForm = this.fb.group({ this.validateForm = this.fb.group({
oldPassword: [null, [Validators.required]], oldPassword: [null, [Validators.required]],
newPassword: [null, [Validators.required,Validators.minLength(6),Validators.maxLength(12)]], newPassword: [null, [Validators.required, Validators.minLength(6), Validators.maxLength(12)]],
realPassword: [null, [Validators.required,Validators.minLength(6),Validators.maxLength(12)]], realPassword: [null, [Validators.required, Validators.minLength(6), Validators.maxLength(12)]],
}); });
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment