Matteo Scandolo | 43ffb67 | 2016-12-02 14:49:58 -0800 | [diff] [blame] | 1 | /// <reference path="../../../../typings/index.d.ts"/> |
| 2 | import {Component} from '@angular/core'; |
| 3 | import {Router} from '@angular/router'; |
| 4 | import {IAuthRequest, IAuthResponse} from '../../interfaces/auth.interface'; |
| 5 | import {StyleConfig} from '../../config/style.config'; |
| 6 | import {AuthService} from '../../services/rest/auth.service'; |
| 7 | |
Matteo Scandolo | 43ffb67 | 2016-12-02 14:49:58 -0800 | [diff] [blame] | 8 | export class Auth { |
| 9 | constructor( |
Matteo Scandolo | 40f8fa9 | 2016-12-07 09:21:35 -0800 | [diff] [blame] | 10 | public username: string, |
| 11 | public password: string |
| 12 | ) { |
Matteo Scandolo | 43ffb67 | 2016-12-02 14:49:58 -0800 | [diff] [blame] | 13 | } |
| 14 | } |
| 15 | |
| 16 | @Component({ |
| 17 | selector: 'xos-login', |
| 18 | template: require('./login.html'), |
| 19 | providers: [AuthService], |
| 20 | }) |
| 21 | export class LoginComponent { |
Matteo Scandolo | 40f8fa9 | 2016-12-07 09:21:35 -0800 | [diff] [blame] | 22 | public auth: IAuthRequest; |
Matteo Scandolo | 43ffb67 | 2016-12-02 14:49:58 -0800 | [diff] [blame] | 23 | public brandName; |
Matteo Scandolo | 40f8fa9 | 2016-12-07 09:21:35 -0800 | [diff] [blame] | 24 | constructor(private AuthService: AuthService, private router: Router) { |
Matteo Scandolo | 43ffb67 | 2016-12-02 14:49:58 -0800 | [diff] [blame] | 25 | this.auth = new Auth('', ''); |
| 26 | this.brandName = StyleConfig.projectName; |
| 27 | } |
| 28 | |
Matteo Scandolo | 40f8fa9 | 2016-12-07 09:21:35 -0800 | [diff] [blame] | 29 | onSubmit(auth: IAuthRequest) { |
Matteo Scandolo | 43ffb67 | 2016-12-02 14:49:58 -0800 | [diff] [blame] | 30 | this.AuthService.login(auth) |
| 31 | .subscribe( |
Matteo Scandolo | 40f8fa9 | 2016-12-07 09:21:35 -0800 | [diff] [blame] | 32 | (user: IAuthResponse) => { |
Matteo Scandolo | 43ffb67 | 2016-12-02 14:49:58 -0800 | [diff] [blame] | 33 | this.router.navigate(['/']); |
| 34 | } |
Matteo Scandolo | 40f8fa9 | 2016-12-07 09:21:35 -0800 | [diff] [blame] | 35 | ); |
Matteo Scandolo | 43ffb67 | 2016-12-02 14:49:58 -0800 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |