diff options
author | crupest <crupest@outlook.com> | 2019-03-04 20:41:17 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-03-04 20:41:17 +0800 |
commit | b7ce3f7139798a734905b6df7530feb8c5d0c373 (patch) | |
tree | c8c6de525e5ae805b364ef015473343ae15371fa /Timeline/ClientApp/src/app/user-dialog/user-dialog.component.ts | |
parent | 4daf2ce80df373fa38d32c74ee475f33a07b18f1 (diff) | |
download | timeline-b7ce3f7139798a734905b6df7530feb8c5d0c373.tar.gz timeline-b7ce3f7139798a734905b6df7530feb8c5d0c373.tar.bz2 timeline-b7ce3f7139798a734905b6df7530feb8c5d0c373.zip |
...
Diffstat (limited to 'Timeline/ClientApp/src/app/user-dialog/user-dialog.component.ts')
-rw-r--r-- | Timeline/ClientApp/src/app/user-dialog/user-dialog.component.ts | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/Timeline/ClientApp/src/app/user-dialog/user-dialog.component.ts b/Timeline/ClientApp/src/app/user-dialog/user-dialog.component.ts index 1d9536c8..6fe5b6d9 100644 --- a/Timeline/ClientApp/src/app/user-dialog/user-dialog.component.ts +++ b/Timeline/ClientApp/src/app/user-dialog/user-dialog.component.ts @@ -1,4 +1,6 @@ import { Component, OnInit } from '@angular/core'; +import { UserService, UserInfo } from './user.service'; +import { LoginEvent } from '../user-login/user-login.component'; @Component({ selector: 'app-user-dialog', @@ -7,14 +9,36 @@ import { Component, OnInit } from '@angular/core'; }) export class UserDialogComponent implements OnInit { - constructor() { } + constructor(private userService: UserService) { } - state: 'login' | 'success' = 'login'; + state: 'loading' | 'login' | 'success' = 'loading'; + + loginMessage: string; + + userInfo: UserInfo; ngOnInit() { + this.userService.validateUserLoginState().subscribe(result => { + if (result.state === 'success') { + this.userInfo = result.userInfo; + this.state = 'success'; + } else { + if (result.state === 'invalid') { + this.loginMessage = 'Your login is no longer valid'; + } else { + this.loginMessage = 'You haven\'t logged in.'; + } + this.state = 'login'; + } + }); } - login() { - + login(event: LoginEvent) { + this.userService.tryLogin(event.username, event.password).subscribe(result => { + this.userInfo = result; + this.state = 'success'; + }, (error: Error) => { + this.loginMessage = error.message; + }); } } |