Matteo Scandolo | 035c593 | 2016-12-14 09:55:15 -0800 | [diff] [blame] | 1 | import {AuthService} from '../../datasources/rest/auth.rest'; |
Matteo Scandolo | 99fface | 2016-12-21 15:37:23 -0800 | [diff] [blame] | 2 | import {StyleConfig} from '../../config/style.config'; |
| 3 | import './login.scss'; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 4 | |
| 5 | class LoginCtrl { |
| 6 | static $inject = ['AuthService', '$state']; |
Matteo Scandolo | 99fface | 2016-12-21 15:37:23 -0800 | [diff] [blame] | 7 | public loginStyle: any; |
| 8 | public img: string; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 9 | /** @ngInject */ |
| 10 | constructor( |
| 11 | private authService: AuthService, |
| 12 | private $state: angular.ui.IStateService |
| 13 | ) { |
Matteo Scandolo | 99fface | 2016-12-21 15:37:23 -0800 | [diff] [blame] | 14 | this.img = this.getImg(StyleConfig.background); |
| 15 | |
| 16 | this.loginStyle = { |
| 17 | 'background-image': `url('${this.getImg(StyleConfig.background)}')` |
| 18 | }; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | public login(username: string, password: string) { |
| 22 | this.authService.login({ |
| 23 | username: username, |
| 24 | password: password |
| 25 | }) |
| 26 | .then(res => { |
Matteo Scandolo | 9f87f30 | 2016-12-13 18:11:10 -0800 | [diff] [blame] | 27 | this.$state.go('xos.dashboard'); |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 28 | }) |
| 29 | .catch(e => console.error); |
| 30 | } |
Matteo Scandolo | 99fface | 2016-12-21 15:37:23 -0800 | [diff] [blame] | 31 | |
| 32 | private getImg(img: string) { |
| 33 | return require(`../../images/brand/${img}`); |
| 34 | } |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | export const xosLogin: angular.IComponentOptions = { |
| 38 | template: require('./login.html'), |
| 39 | controllerAs: 'vm', |
| 40 | controller: LoginCtrl |
| 41 | }; |