| | |
| | | import { error } from 'selenium-webdriver'; |
| | | import { HttpErrorResponse } from '@angular/common/http'; |
| | | import { Authorization } from '@business/entity/token'; |
| | | import { LoginService } from '@business/services/http/login.service'; |
| | | import { SettingsService } from '@delon/theme'; |
| | |
| | | selector: 'passport-login', |
| | | templateUrl: './login.component.html', |
| | | styleUrls: [ './login.component.less' ], |
| | | providers: [ SocialService,CookieService] |
| | | providers: [ SocialService, CookieService] |
| | | }) |
| | | export class UserLoginComponent implements OnDestroy { |
| | | |
| | |
| | | private settingsService: SettingsService, |
| | | private socialService: SocialService, |
| | | @Optional() @Inject(ReuseTabService) private reuseTabService: ReuseTabService, |
| | | private loginService:LoginService, |
| | | private loginService: LoginService, |
| | | @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService) { |
| | | this.form = fb.group({ |
| | | userName: [null, [Validators.required, Validators.minLength(5)]], |
| | |
| | | if (this.mobile.invalid || this.captcha.invalid) return; |
| | | } |
| | | this.loading = true; |
| | | this.loginService.validate(this.userName.value,this.password.value).subscribe( |
| | | (res:Authorization) => { |
| | | if(res.token!=null){ |
| | | this.loginService.validate(this.userName.value, this.password.value).subscribe( |
| | | (res: Authorization) => { |
| | | if (res.token != null) { |
| | | // 清空路由复用信息 |
| | | this.reuseTabService.clear(); |
| | | this.tokenService.set({ |
| | |
| | | this.router.navigate(['/']); |
| | | } |
| | | }, |
| | | (err) => { |
| | | // console.log(err); |
| | | if(err instanceof ProgressEvent){ |
| | | const error = <ProgressEvent>err; |
| | | let xmlHttp = error.target; |
| | | if(xmlHttp instanceof XMLHttpRequest){ |
| | | const xmlHttpRequest = <XMLHttpRequest> xmlHttp; |
| | | console.log(xmlHttpRequest.response); |
| | | const response = JSON.parse(xmlHttpRequest.response); |
| | | if(response.status == 401&&response.errorCode==10){ |
| | | this.validateError["password_incorrect"]=true; |
| | | this.loading = false; |
| | | } else if(response.status == 401&&response.errorCode==12) { |
| | | this.validateError["account_expired"]=true; |
| | | this.loading = false; |
| | | } |
| | | } |
| | | } |
| | | (err: HttpErrorResponse) => { |
| | | if (!!err) { |
| | | const errMsg = err.error; |
| | | console.log(errMsg); |
| | | if (errMsg.status === 401 && errMsg.errorCode === 10) { |
| | | this.validateError['password_incorrect'] = true; |
| | | this.loading = false; |
| | | } else if (errMsg.status === 401 && errMsg.errorCode === 12) { |
| | | this.validateError['account_expired'] = true; |
| | | this.loading = false; |
| | | } |
| | | } |
| | | } |
| | | ); |
| | | |
| | | } |
| | | public validateError:{[s:string]:boolean} = {}; |
| | | public validateError: {[s: string]: boolean} = {}; |
| | | // region: social |
| | | |
| | | open(type: string, openType: SocialOpenType = 'href') { |