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 | |
| 8 | export class Auth { |
| 9 | constructor( |
| 10 | public username, |
| 11 | public password |
| 12 | ){ |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | @Component({ |
| 17 | selector: 'xos-login', |
| 18 | template: require('./login.html'), |
| 19 | providers: [AuthService], |
| 20 | }) |
| 21 | export class LoginComponent { |
| 22 | public auth:IAuthRequest; |
| 23 | public brandName; |
| 24 | constructor(private AuthService: AuthService, private router:Router) { |
| 25 | this.auth = new Auth('', ''); |
| 26 | this.brandName = StyleConfig.projectName; |
| 27 | } |
| 28 | |
| 29 | onSubmit(auth:IAuthRequest){ |
| 30 | this.AuthService.login(auth) |
| 31 | .subscribe( |
| 32 | (user:IAuthResponse) => { |
| 33 | this.router.navigate(['/']); |
| 34 | } |
| 35 | ) |
| 36 | } |
| 37 | } |
| 38 | |