一、登录token携带
private getHeaders() {
const headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET,POST,OPTIONS,DELETE,PUT',
accept: 'application/json',
publicKey: this.auth.publicKey,
};
if (this.auth.jwtKeyValue) {
headers[this.auth.jwtKeyName] = this.auth.jwtKeyValue;
}
return new HttpHeaders(headers);
}
二、登录
preLogin() {
return this.dataService.prePost(`/json`)
.pipe(map((data: TypeResult<Auth>) => {
this.dataService.auth = data.data;
this.userService.publickey = data.data.publicKey;
return data.data;
}));
}
login(usercode, pwd) {
this.preLogin().subscribe((d) => {
this.data = d;
if (!d) {
return;
}
const pubKey = `-----BEGIN PUBLIC KEY-----\n${this.dataService.auth.publicKey}\n-----END PUBLIC KEY-----`;
const encrypt = this.encryptService.getBase64Encrypted(pwd, pubKey);
this.dataService.postForm(`/test/login`, {usercode, pwd: encrypt})
.subscribe((data: TypeResult<any>) => {
this.dataService.auth.jwtKeyValue = data.data[this.dataService.auth.jwtKeyName];
this.login$.next(data.data);
});
});
}
三、 修改密码
resetPassword(usercode, pwd, newPwd) {
const pubKey = `-----BEGIN PUBLIC KEY-----\n${this.dataService.auth.publicKey}\n-----END PUBLIC KEY-----`;
const pwdencrypt = this.encryptService.getBase64Encrypted(pwd, pubKey);
const npwdencrypt = this.encryptService.getBase64Encrypted(newPwd, pubKey);
return this.dataService.postForm(`/test/updatePwd`, {pwd: pwdencrypt, newPwd: npwdencrypt})
.pipe(map(data => {
console.log(data);
return data
}))
}