2016-12-01 11:40:28 +02:00
|
|
|
/*
|
2018-03-05 17:34:13 +02:00
|
|
|
* Copyright © 2016-2018 The Thingsboard Authors
|
2016-12-01 11:40:28 +02:00
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
2018-02-19 15:52:26 +02:00
|
|
|
/* eslint-disable import/no-unresolved, import/default */
|
|
|
|
|
|
|
|
|
|
import logoSvg from '../../svg/logo_title_white.svg';
|
|
|
|
|
|
|
|
|
|
/* eslint-enable import/no-unresolved, import/default */
|
|
|
|
|
|
2016-12-01 11:40:28 +02:00
|
|
|
/*@ngInject*/
|
2018-11-09 22:58:11 +02:00
|
|
|
export default function LoginController(toast, loginService, userService, $state, $stateParams, $rootScope) {
|
2016-12-01 11:40:28 +02:00
|
|
|
var vm = this;
|
|
|
|
|
|
2018-02-19 15:52:26 +02:00
|
|
|
vm.logoSvg = logoSvg;
|
|
|
|
|
|
2016-12-01 11:40:28 +02:00
|
|
|
vm.user = {
|
|
|
|
|
name: '',
|
|
|
|
|
password: ''
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-09 22:58:11 +02:00
|
|
|
vm.params = $stateParams;
|
2016-12-01 11:40:28 +02:00
|
|
|
vm.login = login;
|
|
|
|
|
|
|
|
|
|
function doLogin() {
|
|
|
|
|
loginService.login(vm.user).then(function success(response) {
|
|
|
|
|
var token = response.data.token;
|
|
|
|
|
var refreshToken = response.data.refreshToken;
|
2018-11-09 22:58:11 +02:00
|
|
|
userService.setUserFromJwtToken(token, refreshToken, true).then(function() {
|
|
|
|
|
if (vm.params.toName && vm.params.toName !== 'login') {
|
|
|
|
|
if (vm.params.toName == 'home.dashboards.dashboard' && $rootScope.forceFullscreen) {
|
|
|
|
|
$state.go('dashboard', vm.params.params)
|
|
|
|
|
} else {
|
|
|
|
|
$state.go(vm.params.toName, vm.params.params)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-12-01 11:40:28 +02:00
|
|
|
}, function fail(/*response*/) {
|
|
|
|
|
/*if (response && response.data && response.data.message) {
|
|
|
|
|
toast.showError(response.data.message);
|
|
|
|
|
} else if (response && response.statusText) {
|
|
|
|
|
toast.showError(response.statusText);
|
|
|
|
|
} else {
|
|
|
|
|
toast.showError($translate.instant('error.unknown-error'));
|
|
|
|
|
}*/
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function login() {
|
|
|
|
|
doLogin();
|
|
|
|
|
}
|
|
|
|
|
}
|