blob: 334ad08abdaaad3862d106d68550f2d46c27cb55 [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 Scandolof6acdbe2016-12-13 10:29:37 -08004
5class LoginCtrl {
6 static $inject = ['AuthService', '$state'];
Matteo Scandolo99fface2016-12-21 15:37:23 -08007 public loginStyle: any;
8 public img: string;
Matteo Scandolof6acdbe2016-12-13 10:29:37 -08009 /** @ngInject */
10 constructor(
11 private authService: AuthService,
12 private $state: angular.ui.IStateService
13 ) {
Matteo Scandolo99fface2016-12-21 15:37:23 -080014 this.img = this.getImg(StyleConfig.background);
15
16 this.loginStyle = {
17 'background-image': `url('${this.getImg(StyleConfig.background)}')`
18 };
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080019 }
20
21 public login(username: string, password: string) {
22 this.authService.login({
23 username: username,
24 password: password
25 })
26 .then(res => {
Matteo Scandolo9f87f302016-12-13 18:11:10 -080027 this.$state.go('xos.dashboard');
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080028 })
29 .catch(e => console.error);
30 }
Matteo Scandolo99fface2016-12-21 15:37:23 -080031
32 private getImg(img: string) {
33 return require(`../../images/brand/${img}`);
34 }
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080035}
36
37export const xosLogin: angular.IComponentOptions = {
38 template: require('./login.html'),
39 controllerAs: 'vm',
40 controller: LoginCtrl
41};