diff options
Diffstat (limited to 'client/app/users/login')
-rw-r--r-- | client/app/users/login/index.ts | 1 | ||||
-rw-r--r-- | client/app/users/login/login.component.html | 14 | ||||
-rw-r--r-- | client/app/users/login/login.component.scss | 0 | ||||
-rw-r--r-- | client/app/users/login/login.component.ts | 34 |
4 files changed, 49 insertions, 0 deletions
diff --git a/client/app/users/login/index.ts b/client/app/users/login/index.ts new file mode 100644 index 000000000..69c16441f --- /dev/null +++ b/client/app/users/login/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './login.component'; | |||
diff --git a/client/app/users/login/login.component.html b/client/app/users/login/login.component.html new file mode 100644 index 000000000..940694515 --- /dev/null +++ b/client/app/users/login/login.component.html | |||
@@ -0,0 +1,14 @@ | |||
1 | <h3>Login</h3> | ||
2 | <form role="form" (submit)="login(username.value, password.value)"> | ||
3 | <div class="form-group"> | ||
4 | <label for="username">Username</label> | ||
5 | <input type="text" #username class="form-control" id="username" placeholder="Username"> | ||
6 | </div> | ||
7 | |||
8 | <div class="form-group"> | ||
9 | <label for="password">Password</label> | ||
10 | <input type="password" #password class="form-control" id="password" placeholder="Password"> | ||
11 | </div> | ||
12 | |||
13 | <input type="submit" value="Login" class="btn btn-default"> | ||
14 | </form> | ||
diff --git a/client/app/users/login/login.component.scss b/client/app/users/login/login.component.scss new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/client/app/users/login/login.component.scss | |||
diff --git a/client/app/users/login/login.component.ts b/client/app/users/login/login.component.ts new file mode 100644 index 000000000..33590ad4c --- /dev/null +++ b/client/app/users/login/login.component.ts | |||
@@ -0,0 +1,34 @@ | |||
1 | import { Component } from '@angular/core'; | ||
2 | import { Router } from '@angular/router-deprecated'; | ||
3 | |||
4 | import { AuthService, AuthStatus, User } from '../shared/index'; | ||
5 | |||
6 | @Component({ | ||
7 | selector: 'my-user-login', | ||
8 | styleUrls: [ 'client/app/users/login/login.component.css' ], | ||
9 | templateUrl: 'client/app/users/login/login.component.html' | ||
10 | }) | ||
11 | |||
12 | export class UserLoginComponent { | ||
13 | constructor(private _authService: AuthService, private _router: Router) {} | ||
14 | |||
15 | login(username: string, password: string) { | ||
16 | this._authService.login(username, password).subscribe( | ||
17 | result => { | ||
18 | const user = new User(username, result); | ||
19 | user.save(); | ||
20 | |||
21 | this._authService.setStatus(AuthStatus.LoggedIn); | ||
22 | |||
23 | this._router.navigate(['VideosList']); | ||
24 | }, | ||
25 | error => { | ||
26 | if (error.error === 'invalid_grant') { | ||
27 | alert('Credentials are invalid.'); | ||
28 | } else { | ||
29 | alert(`${error.error}: ${error.error_description}`); | ||
30 | } | ||
31 | } | ||
32 | ); | ||
33 | } | ||
34 | } | ||