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 | 0f77c50 | 2016-12-06 16:46:00 -0800 | [diff] [blame^] | 8 | import {AppConfig} from '../../config/app.config'; |
| 9 | |
Matteo Scandolo | 43ffb67 | 2016-12-02 14:49:58 -0800 | [diff] [blame] | 10 | export class Auth { |
| 11 | constructor( |
| 12 | public username, |
| 13 | public password |
| 14 | ){ |
| 15 | } |
| 16 | } |
| 17 | |
| 18 | @Component({ |
| 19 | selector: 'xos-login', |
| 20 | template: require('./login.html'), |
| 21 | providers: [AuthService], |
| 22 | }) |
| 23 | export class LoginComponent { |
| 24 | public auth:IAuthRequest; |
| 25 | public brandName; |
| 26 | constructor(private AuthService: AuthService, private router:Router) { |
| 27 | this.auth = new Auth('', ''); |
| 28 | this.brandName = StyleConfig.projectName; |
| 29 | } |
| 30 | |
| 31 | onSubmit(auth:IAuthRequest){ |
| 32 | this.AuthService.login(auth) |
| 33 | .subscribe( |
| 34 | (user:IAuthResponse) => { |
| 35 | this.router.navigate(['/']); |
| 36 | } |
| 37 | ) |
| 38 | } |
| 39 | } |
| 40 | |