blob: 11642f12f97af28904e35881099b7008703c3768 [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) {
Matteo Scandolo266907e2016-12-20 13:41:42 -080022 console.log(username, password);
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080023 this.authService.login({
24 username: username,
25 password: password
26 })
27 .then(res => {
Matteo Scandolo9f87f302016-12-13 18:11:10 -080028 this.$state.go('xos.dashboard');
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080029 })
30 .catch(e => console.error);
31 }
Matteo Scandolo99fface2016-12-21 15:37:23 -080032
33 private getImg(img: string) {
34 return require(`../../images/brand/${img}`);
35 }
Matteo Scandolof6acdbe2016-12-13 10:29:37 -080036}
37
38export const xosLogin: angular.IComponentOptions = {
39 template: require('./login.html'),
40 controllerAs: 'vm',
41 controller: LoginCtrl
42};