You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.2 KiB
56 lines
1.2 KiB
import {Injectable} from '@angular/core';
|
|
import {CookieService} from 'ngx-cookie-service';
|
|
import {Router} from '@angular/router';
|
|
import {MessageService} from '../../message/message.service';
|
|
import {JSONRequest} from '../../interface/JSONRequest';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class LoginService extends JSONRequest {
|
|
|
|
constructor(
|
|
private cookieService: CookieService,
|
|
private router: Router,
|
|
private messageService: MessageService
|
|
) {
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* 检查登陆令牌是否有效
|
|
*/
|
|
checkToken(): boolean {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* 登陆
|
|
*/
|
|
login(body: string) {
|
|
if (this.checkToken()) {
|
|
this.router.navigateByUrl('/forum');
|
|
} else {
|
|
this.request(body);
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param body 请求表单
|
|
*/
|
|
request(body: string) {
|
|
// res => {
|
|
// this.message = res.message;
|
|
// if (res.result === 'OK') {
|
|
// this.messageStyle = 'info';
|
|
// this.cookieService.set(environment.tokenKey, res.body.token, 3600);
|
|
// this.router.navigateByUrl('/forum');
|
|
// } else {
|
|
// this.messageStyle = 'warning';
|
|
// }
|
|
// }
|
|
this.messageService.danger('登陆失败');
|
|
return false;
|
|
}
|
|
}
|
|
|