blob: c091e430488debd8188d0a5eca5dd8a67202e1bd [file] [log] [blame]
Matteo Scandolo035c5932016-12-14 09:55:15 -08001import {AuthService} from '../../datasources/rest/auth.rest';
Matteo Scandolo99fface2016-12-21 15:37:23 -08002import {StyleConfig} from '../../config/style.config';
3import './login.scss';
Matteo Scandolob4b74a82017-01-12 13:12:26 -08004import {IXosModelSetupService} from '../services/helpers/model-setup.helpers';
Matteo Scandolof6acdbe2016-12-13 10:29:37 -08005
6class LoginCtrl {
Matteo Scandolob4b74a82017-01-12 13:12:26 -08007 static $inject = ['AuthService', '$state', 'ModelSetup'];
Matteo Scandolo99fface2016-12-21 15:37:23 -08008 public loginStyle: any;
9 public img: string;
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080010 /** @ngInject */
11 constructor(
12 private authService: AuthService,
Matteo Scandolob4b74a82017-01-12 13:12:26 -080013 private $state: angular.ui.IStateService,
14 private ModelSetup: IXosModelSetupService
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080015 ) {
Matteo Scandolo99fface2016-12-21 15:37:23 -080016 this.img = this.getImg(StyleConfig.background);
17
18 this.loginStyle = {
19 'background-image': `url('${this.getImg(StyleConfig.background)}')`
20 };
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080021 }
22
23 public login(username: string, password: string) {
24 this.authService.login({
25 username: username,
26 password: password
27 })
28 .then(res => {
Matteo Scandolob4b74a82017-01-12 13:12:26 -080029 // after login set up models
30 return this.ModelSetup.setup();
31 })
32 .then(() => {
Matteo Scandolo9f87f302016-12-13 18:11:10 -080033 this.$state.go('xos.dashboard');
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080034 })
35 .catch(e => console.error);
36 }
Matteo Scandolo99fface2016-12-21 15:37:23 -080037
38 private getImg(img: string) {
39 return require(`../../images/brand/${img}`);
40 }
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080041}
42
43export const xosLogin: angular.IComponentOptions = {
44 template: require('./login.html'),
45 controllerAs: 'vm',
46 controller: LoginCtrl
47};