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 | b4b74a8 | 2017-01-12 13:12:26 -0800 | [diff] [blame] | 4 | import {IXosModelSetupService} from '../services/helpers/model-setup.helpers'; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 5 | |
| 6 | class LoginCtrl { |
Matteo Scandolo | b4b74a8 | 2017-01-12 13:12:26 -0800 | [diff] [blame] | 7 | static $inject = ['AuthService', '$state', 'ModelSetup']; |
Matteo Scandolo | 99fface | 2016-12-21 15:37:23 -0800 | [diff] [blame] | 8 | public loginStyle: any; |
| 9 | public img: string; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 10 | /** @ngInject */ |
| 11 | constructor( |
| 12 | private authService: AuthService, |
Matteo Scandolo | b4b74a8 | 2017-01-12 13:12:26 -0800 | [diff] [blame] | 13 | private $state: angular.ui.IStateService, |
| 14 | private ModelSetup: IXosModelSetupService |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 15 | ) { |
Matteo Scandolo | 99fface | 2016-12-21 15:37:23 -0800 | [diff] [blame] | 16 | this.img = this.getImg(StyleConfig.background); |
| 17 | |
| 18 | this.loginStyle = { |
| 19 | 'background-image': `url('${this.getImg(StyleConfig.background)}')` |
| 20 | }; |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | public login(username: string, password: string) { |
| 24 | this.authService.login({ |
| 25 | username: username, |
| 26 | password: password |
| 27 | }) |
| 28 | .then(res => { |
Matteo Scandolo | b4b74a8 | 2017-01-12 13:12:26 -0800 | [diff] [blame] | 29 | // after login set up models |
| 30 | return this.ModelSetup.setup(); |
| 31 | }) |
| 32 | .then(() => { |
Matteo Scandolo | 9f87f30 | 2016-12-13 18:11:10 -0800 | [diff] [blame] | 33 | this.$state.go('xos.dashboard'); |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 34 | }) |
| 35 | .catch(e => console.error); |
| 36 | } |
Matteo Scandolo | 99fface | 2016-12-21 15:37:23 -0800 | [diff] [blame] | 37 | |
| 38 | private getImg(img: string) { |
| 39 | return require(`../../images/brand/${img}`); |
| 40 | } |
Matteo Scandolo | f6acdbe | 2016-12-13 10:29:37 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | export const xosLogin: angular.IComponentOptions = { |
| 44 | template: require('./login.html'), |
| 45 | controllerAs: 'vm', |
| 46 | controller: LoginCtrl |
| 47 | }; |