Commit 921c2e94 authored by wangqinghua's avatar wangqinghua

update

parent 1fe82deb
......@@ -4,6 +4,8 @@ import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {NzMessageComponent, NzMessageService} from 'ng-zorro-antd';
import {LayoutService} from '../../layouts/layout.service';
import {LoginService} from '../../shared';
import {Base64} from 'js-base64';
import {LocalStorageService} from 'ngx-webstorage';
@Component({
selector: 'smart-modify-password',
......@@ -16,11 +18,14 @@ export class ModifyPasswordComponent implements OnInit {
isOkLoading = false;
title = '修改密码';
validateForm: FormGroup;
reg = new RegExp(/^(?=[a-zA-Z]+\d+)\w{8,20}$/);
groupid;
constructor(private fb: FormBuilder, private layoutSer: LayoutService,
private message: NzMessageService,private loginService:LoginService) {}
private $localStorage: LocalStorageService,
private message: NzMessageService, private loginService: LoginService) {
}
ngOnInit() {
this.initForm();
......@@ -38,18 +43,47 @@ export class ModifyPasswordComponent implements OnInit {
if (this.validateForm.invalid) {
return false;
}
if(this.validateForm.value.newPassword != this.validateForm.value.realPassword){
this.message.error("两次输入密码不一致");
if (this.validateForm.value.newPassword != this.validateForm.value.realPassword) {
this.message.error('两次输入密码不一致');
return false;
}
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() {
let formData = new FormData();
formData.append('newPassword',this.validateForm.value.realPassword);
formData.append('oldPassword',this.validateForm.value.oldPassword);
formData.append('newPassword', this.validateForm.value.realPassword);
formData.append('oldPassword', this.validateForm.value.oldPassword);
this.layoutSer.modifyPassword(formData).subscribe(
(res) => {
if (res.errCode == 10000) {
......@@ -72,8 +106,8 @@ export class ModifyPasswordComponent implements OnInit {
initForm() {
this.validateForm = this.fb.group({
oldPassword: [null, [Validators.required]],
newPassword: [null, [Validators.required,Validators.minLength(6),Validators.maxLength(12)]],
realPassword: [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)]],
});
}
}
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