diff --git a/src/app/api/api.service.ts b/src/app/api/api.service.ts index 83ac859..5e07c7e 100644 --- a/src/app/api/api.service.ts +++ b/src/app/api/api.service.ts @@ -582,4 +582,16 @@ export class ApiService extends HttpService { }); } + setPwd(pwdStr: string, newPwdStr: string, confirmPwdStr: string,) { + return super.Service({ + path: '/user/setPwd', + method: 'POST', + queryParam: { + pwd: pwdStr, + newPwd: newPwdStr, + confirmPwd: confirmPwdStr, + } + }); + } + } diff --git a/src/app/components/admin-header/admin-header.component.html b/src/app/components/admin-header/admin-header.component.html index 2cd9cd6..00be1c9 100644 --- a/src/app/components/admin-header/admin-header.component.html +++ b/src/app/components/admin-header/admin-header.component.html @@ -11,7 +11,9 @@
- + + {{user.displayName}}
diff --git a/src/app/components/admin-header/admin-header.component.ts b/src/app/components/admin-header/admin-header.component.ts index 17d26a2..cd4d6c8 100644 --- a/src/app/components/admin-header/admin-header.component.ts +++ b/src/app/components/admin-header/admin-header.component.ts @@ -14,7 +14,7 @@ export class AdminHeaderComponent implements OnInit { user: User @Output() infoClicked = new EventEmitter() - + noAvatarUrl = 'https://cdn.celess.cn/' logout = () => this.userService.logout(); infoClickedEvent = () => this.infoClicked.emit(); diff --git a/src/app/components/header/header.component.html b/src/app/components/header/header.component.html index fb3a512..71fa69c 100644 --- a/src/app/components/header/header.component.html +++ b/src/app/components/header/header.component.html @@ -18,9 +18,9 @@
- + + *ngIf="userInfo.avatarImgUrl===noAvatarUrl"> + +
- {{user&&user.email}} + {{user && user.email}}
- {{user&&user.displayName}} + {{user && user.displayName}}
- {{user.desc}} + {{user.desc}} + + + ********* + +
@@ -147,6 +164,43 @@ + +
+ + 原密码 + + + + + + 新密码 + + + + +
新密码不可为空
+
新密码最短6位
+
新密码最长16位
+
新密码范围[数字,大小写字母,下划线和减号]
+
+
+ + 确认密码 + + + + +
确认密码不可为空
+
确认密码最短6位
+
确认密码最长16位
+
确认密码范围[数字,大小写字母,下划线和减号]
+
确认密码应和新密码相同
+
+
+
+
+ diff --git a/src/app/view/admin/admin.component.ts b/src/app/view/admin/admin.component.ts index 543fcec..c79df40 100644 --- a/src/app/view/admin/admin.component.ts +++ b/src/app/view/admin/admin.component.ts @@ -1,10 +1,13 @@ import {Component, OnInit} from '@angular/core'; -import {FormControl, FormGroup} from '@angular/forms'; -import {NzMessageService} from 'ng-zorro-antd'; +import {AbstractControl, FormControl, FormGroup, Validators} from '@angular/forms'; +import {NzMessageService, UploadFile} from 'ng-zorro-antd'; import {Router} from '@angular/router'; import {GlobalUserService} from '../../services/global-user.service'; import {User} from '../../class/User'; import {ApiService} from '../../api/api.service'; +import {environment} from '../../../environments/environment'; +import {Observable} from 'rxjs'; +import {LocalStorageService} from '../../services/local-storage.service'; @Component({ selector: 'app-admin', @@ -14,17 +17,33 @@ import {ApiService} from '../../api/api.service'; export class AdminComponent implements OnInit { constructor(public gUserService: GlobalUserService, private apiService: ApiService, private messageService: NzMessageService, - private router: Router) { + private router: Router, private localStorageService: LocalStorageService) { this.gUserService.watchUserInfo({ complete: () => null, error: (err) => null, next: data => { console.log('更新user') this.user = data.result + this.user.avatarImgUrl += '?t=' + Date.now(); if (data.result) this.initHelloWords() } } - ) + ); + this.editInfoFormGroup = new FormGroup({ + desc: new FormControl(), + displayName: new FormControl(), + email: new FormControl({value: null, disabled: true}) + }); + this.resetPwdFormGroup = new FormGroup({ + originPwd: new FormControl(null, [Validators.required]), + newPwd: new FormControl(null, [ + Validators.required, Validators.minLength(6), Validators.maxLength(16), Validators.pattern(/^[\w_-]{6,16}$/) + ]), + newPwdConfirm: new FormControl(null, [ + Validators.required, Validators.minLength(6), Validators.maxLength(16), Validators.pattern(/^[\w_-]{6,16}$/), + this.checkSamePwd() + ]), + }) } user: User; @@ -32,8 +51,11 @@ export class AdminComponent implements OnInit { infoDrawerVisible: boolean = false; sayHelloContent: string; editInfoModalVisible: boolean = false; + resetPwdModalVisible: boolean = false; editInfoFormGroup: FormGroup; - + resetPwdFormGroup: FormGroup; + noAvatarUrl = 'https://cdn.celess.cn/' + host: string showInfoDrawer = () => this.infoDrawerVisible = !this.infoDrawerVisible; logout() { @@ -42,13 +64,20 @@ export class AdminComponent implements OnInit { } ngOnInit(): void { - this.editInfoFormGroup = new FormGroup({ - desc: new FormControl(), - displayName: new FormControl(), - email: new FormControl({value: null, disabled: true}) - }); + this.host = environment.host; } + checkSamePwd = () => { + return (control: AbstractControl): { [key: string]: any } | null => { + console.log('a') + const newPwd = this.resetPwdFormGroup && this.resetPwdFormGroup.value.newPwd; + return control.value !== newPwd ? {pwdNotSame: true} : null; + }; + } + uploadHeader = (file: UploadFile): object | Observable<{}> => { + return {Authorization: this.localStorageService.getToken()} + }; + private initHelloWords() { const hours = new Date().getHours(); if (hours < 6) { @@ -89,4 +118,30 @@ export class AdminComponent implements OnInit { this.editInfoModalVisible = false; } + resetPwdConfirm() { + // this.apiService + const data = this.resetPwdFormGroup.value; + this.apiService.setPwd(data.originPwd, data.newPwd, data.newPwdConfirm).subscribe({ + next: respData => { + this.messageService.success('修改密码成功,请牢记你修改的密码'); + this.gUserService.refreshUserInfo(); + }, + error: err => { + this.messageService.error('修改密码失败,' + err.msg); + } + }) + this.resetPwdModalVisible = false; + } + + showResetPwdModal() { + this.resetPwdModalVisible = true; + this.infoDrawerVisible = false + } + + avatarUpload(info: any) { + if (info.type === 'success' && info.file.response.code === 0) { + const time = new Date().valueOf(); + this.gUserService.refreshUserInfo(); + } + } } diff --git a/src/app/view/admin/auth.guard.ts b/src/app/view/admin/auth.guard.ts index 8ff2032..4a3dc78 100644 --- a/src/app/view/admin/auth.guard.ts +++ b/src/app/view/admin/auth.guard.ts @@ -67,8 +67,8 @@ export class AuthGuard implements CanActivate { case '/admin/visitor': if (this.userInfo && this.userInfo.role !== 'admin') { observer.next(false); - observer.complete(); if (this.visitCount === 1) this.router.navigateByUrl('/admin') + observer.complete(); return; } }