#981 Login fixes
This commit is contained in:
parent
e76d0aaf71
commit
95c15a0ee9
|
@ -46,7 +46,7 @@ module.exports = Self => {
|
||||||
let filter = {where: {name: user}};
|
let filter = {where: {name: user}};
|
||||||
let instance = await Self.findOne(filter);
|
let instance = await Self.findOne(filter);
|
||||||
|
|
||||||
if (!instance || instance.password !== md5(password))
|
if (!instance || instance.password !== md5(password || ''))
|
||||||
throw err;
|
throw err;
|
||||||
|
|
||||||
let where = {id: instance.id};
|
let where = {id: instance.id};
|
||||||
|
|
|
@ -169,9 +169,9 @@ export default class Watcher extends Component {
|
||||||
*/
|
*/
|
||||||
check() {
|
check() {
|
||||||
if (this.form && this.form.$invalid)
|
if (this.form && this.form.$invalid)
|
||||||
throw new UserError(this._.instant('Some fields are invalid'));
|
throw new UserError('Some fields are invalid');
|
||||||
if (!this.dirty)
|
if (!this.dirty)
|
||||||
throw new UserError(this._.instant('No changes to save'));
|
throw new UserError('No changes to save');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,9 +7,10 @@ import UserError from 'core/lib/user-error';
|
||||||
* @property {Boolean} loggedIn Whether the user is currently logged
|
* @property {Boolean} loggedIn Whether the user is currently logged
|
||||||
*/
|
*/
|
||||||
export default class Auth {
|
export default class Auth {
|
||||||
constructor($http, $state, $transitions, $window, vnToken, vnModules, aclService) {
|
constructor($http, $q, $state, $transitions, $window, vnToken, vnModules, aclService) {
|
||||||
Object.assign(this, {
|
Object.assign(this, {
|
||||||
$http,
|
$http,
|
||||||
|
$q,
|
||||||
$state,
|
$state,
|
||||||
$transitions,
|
$transitions,
|
||||||
$window,
|
$window,
|
||||||
|
@ -43,7 +44,7 @@ export default class Auth {
|
||||||
}
|
}
|
||||||
login(user, password, remember) {
|
login(user, password, remember) {
|
||||||
if (!user)
|
if (!user)
|
||||||
throw new UserError('Please insert your user and password');
|
return this.$q.reject(new UserError('Please enter your username'));
|
||||||
|
|
||||||
let params = {
|
let params = {
|
||||||
user,
|
user,
|
||||||
|
@ -51,8 +52,7 @@ export default class Auth {
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.$http.post('/api/Accounts/login', params).then(
|
return this.$http.post('/api/Accounts/login', params).then(
|
||||||
json => this.onLoginOk(json, remember),
|
json => this.onLoginOk(json, remember));
|
||||||
json => this.onLoginErr(json));
|
|
||||||
}
|
}
|
||||||
onLoginOk(json, remember) {
|
onLoginOk(json, remember) {
|
||||||
this.vnToken.set(json.data.token, remember);
|
this.vnToken.set(json.data.token, remember);
|
||||||
|
@ -65,22 +65,6 @@ export default class Auth {
|
||||||
this.$state.go('home');
|
this.$state.go('home');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
onLoginErr(json) {
|
|
||||||
let message;
|
|
||||||
|
|
||||||
switch (json.status) {
|
|
||||||
case 401:
|
|
||||||
message = 'Invalid credentials';
|
|
||||||
break;
|
|
||||||
case -1:
|
|
||||||
message = 'Can\'t contact with server';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
message = 'Something went wrong';
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new UserError(message);
|
|
||||||
}
|
|
||||||
logout() {
|
logout() {
|
||||||
let promise = this.$http.post('/api/Accounts/logout', null, {
|
let promise = this.$http.post('/api/Accounts/logout', null, {
|
||||||
headers: {Authorization: this.vnToken.token}
|
headers: {Authorization: this.vnToken.token}
|
||||||
|
@ -106,6 +90,6 @@ export default class Auth {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Auth.$inject = ['$http', '$state', '$transitions', '$window', 'vnToken', 'vnModules', 'aclService'];
|
Auth.$inject = ['$http', '$q', '$state', '$transitions', '$window', 'vnToken', 'vnModules', 'aclService'];
|
||||||
|
|
||||||
ngModule.service('vnAuth', Auth);
|
ngModule.service('vnAuth', Auth);
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
Invalid login: Invalid login, remember that distinction is made between uppercase and lowercase
|
||||||
|
Could not contact the server: Could not contact the server, make sure you have a connection to the network
|
||||||
|
Please enter your username: Please enter your username
|
||||||
|
It seems that the server has fall down: It seems that the server has fall down, wait a few minutes and try again
|
||||||
|
Your session has expired: Your session has expired
|
||||||
|
Access denied: Access denied
|
|
@ -0,0 +1,6 @@
|
||||||
|
Invalid login: Usuario o contraseña incorrectos, recuerda que se hace distinción entre mayúsculas y minúsculas
|
||||||
|
Could not contact the server: No se ha podido contactar con el servidor, asegurate de que dispones de conexión con la red
|
||||||
|
Please enter your username: Por favor introduce tu nombre de usuario
|
||||||
|
It seems that the server has fall down: Parece que el servidor se ha caído, espera unos minutos e inténtalo de nuevo
|
||||||
|
Your session has expired: Tu sesión ha expirado
|
||||||
|
Access denied: Acción no permitida
|
|
@ -3,7 +3,6 @@ import '@babel/polyfill';
|
||||||
import * as ng from 'angular';
|
import * as ng from 'angular';
|
||||||
export {ng};
|
export {ng};
|
||||||
|
|
||||||
import 'angular-cookies';
|
|
||||||
import 'angular-translate';
|
import 'angular-translate';
|
||||||
import 'angular-translate-loader-partial';
|
import 'angular-translate-loader-partial';
|
||||||
import '@uirouter/angularjs';
|
import '@uirouter/angularjs';
|
||||||
|
@ -11,7 +10,6 @@ import 'mg-crud';
|
||||||
import 'oclazyload';
|
import 'oclazyload';
|
||||||
|
|
||||||
export const ngDeps = [
|
export const ngDeps = [
|
||||||
'ngCookies',
|
|
||||||
'pascalprecht.translate',
|
'pascalprecht.translate',
|
||||||
'ui.router',
|
'ui.router',
|
||||||
'mgCrud',
|
'mgCrud',
|
||||||
|
|
|
@ -31,11 +31,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/angular/-/angular-1.7.5.tgz",
|
"resolved": "https://registry.npmjs.org/angular/-/angular-1.7.5.tgz",
|
||||||
"integrity": "sha512-760183yxtGzni740IBTieNuWLtPNAoMqvmC0Z62UoU0I3nqk+VJuO3JbQAXOyvo3Oy/ZsdNQwrSTh/B0OQZjNw=="
|
"integrity": "sha512-760183yxtGzni740IBTieNuWLtPNAoMqvmC0Z62UoU0I3nqk+VJuO3JbQAXOyvo3Oy/ZsdNQwrSTh/B0OQZjNw=="
|
||||||
},
|
},
|
||||||
"angular-cookies": {
|
|
||||||
"version": "1.7.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/angular-cookies/-/angular-cookies-1.7.5.tgz",
|
|
||||||
"integrity": "sha512-/8xvvSl/Z9Vwu8ChRm+OQE3vmli8Icwl8uTYkHqD7j7cknJP9kNaf7SgsENlsLVtOqLE/I7TCFYrSx3bmSeNQA=="
|
|
||||||
},
|
|
||||||
"angular-translate": {
|
"angular-translate": {
|
||||||
"version": "2.18.1",
|
"version": "2.18.1",
|
||||||
"resolved": "https://registry.npmjs.org/angular-translate/-/angular-translate-2.18.1.tgz",
|
"resolved": "https://registry.npmjs.org/angular-translate/-/angular-translate-2.18.1.tgz",
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
"@babel/polyfill": "^7.2.5",
|
"@babel/polyfill": "^7.2.5",
|
||||||
"@uirouter/angularjs": "^1.0.20",
|
"@uirouter/angularjs": "^1.0.20",
|
||||||
"angular": "^1.7.5",
|
"angular": "^1.7.5",
|
||||||
"angular-cookies": "^1.7.5",
|
|
||||||
"angular-translate": "^2.18.1",
|
"angular-translate": "^2.18.1",
|
||||||
"angular-translate-loader-partial": "^2.18.1",
|
"angular-translate-loader-partial": "^2.18.1",
|
||||||
"flatpickr": "^4.5.2",
|
"flatpickr": "^4.5.2",
|
||||||
|
|
|
@ -21,11 +21,11 @@ export default class Controller {
|
||||||
localStorage.setItem('lastUser', this.user);
|
localStorage.setItem('lastUser', this.user);
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(err => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.password = '';
|
this.password = '';
|
||||||
this.focusUser();
|
this.focusUser();
|
||||||
throw error;
|
throw err;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
focusUser() {
|
focusUser() {
|
||||||
|
|
|
@ -5,7 +5,6 @@ Logout: Logout
|
||||||
Change language: Change language
|
Change language: Change language
|
||||||
Profile: Profile
|
Profile: Profile
|
||||||
Data saved!: Data saved!
|
Data saved!: Data saved!
|
||||||
Can't contact with server: Can't contact with server
|
|
||||||
Push on applications menu: To open a module push on applications menu
|
Push on applications menu: To open a module push on applications menu
|
||||||
Clients: Clients
|
Clients: Clients
|
||||||
Modules access: Modules access
|
Modules access: Modules access
|
|
@ -1,5 +1,4 @@
|
||||||
Applications: Aplicaciones
|
Applications: Aplicaciones
|
||||||
Can't contact with server: No se pudo contactar con el servidor
|
|
||||||
Change language: Cambiar idioma
|
Change language: Cambiar idioma
|
||||||
Client Frozen: Cliente congelado
|
Client Frozen: Cliente congelado
|
||||||
Client has debt: Cliente con riesgo
|
Client has debt: Cliente con riesgo
|
||||||
|
|
|
@ -66,10 +66,12 @@ ngModule.config(config);
|
||||||
|
|
||||||
// Unhandled exceptions
|
// Unhandled exceptions
|
||||||
|
|
||||||
$exceptionHandler.$inject = ['vnApp', '$window', '$state'];
|
$exceptionHandler.$inject = ['vnApp', '$window', '$state', '$injector'];
|
||||||
function $exceptionHandler(vnApp, $window, $state) {
|
function $exceptionHandler(vnApp, $window, $state, $injector) {
|
||||||
return function(exception, cause) {
|
return function(exception, cause) {
|
||||||
let message;
|
let message;
|
||||||
|
let messageT;
|
||||||
|
let $translate = $injector.get('$translate');
|
||||||
|
|
||||||
if (exception.name == 'HttpError') {
|
if (exception.name == 'HttpError') {
|
||||||
switch (exception.xhrStatus) {
|
switch (exception.xhrStatus) {
|
||||||
|
@ -78,27 +80,44 @@ function $exceptionHandler(vnApp, $window, $state) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (exception.status) {
|
||||||
|
case 401:
|
||||||
|
if ($state.current.name != 'login') {
|
||||||
|
messageT = 'Your session has expired';
|
||||||
|
let params = {continue: $window.location.hash};
|
||||||
|
$state.go('login', params);
|
||||||
|
} else
|
||||||
|
messageT = 'Invalid login';
|
||||||
|
break;
|
||||||
|
case 403:
|
||||||
|
messageT = 'Access denied';
|
||||||
|
break;
|
||||||
|
case 502:
|
||||||
|
messageT = 'It seems that the server has fall down';
|
||||||
|
break;
|
||||||
|
case -1:
|
||||||
|
messageT = 'Could not contact the server';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!messageT) {
|
||||||
let data = exception.data;
|
let data = exception.data;
|
||||||
|
|
||||||
if (data && data.error instanceof Object)
|
if (data && data.error instanceof Object)
|
||||||
message = data.error.message;
|
message = data.error.message;
|
||||||
else if (exception.status === -1)
|
|
||||||
message = `Can't contact with server`;
|
|
||||||
else
|
else
|
||||||
message = `${exception.status}: ${exception.statusText}`;
|
message = `${exception.status}: ${exception.statusText}`;
|
||||||
|
|
||||||
if (exception.status === 401 && $state.current.name != 'login') {
|
|
||||||
let params = {continue: $window.location.hash};
|
|
||||||
$state.go('login', params);
|
|
||||||
}
|
}
|
||||||
} else if (exception.name == 'UserError')
|
} else if (exception.name == 'UserError')
|
||||||
message = exception.message;
|
messageT = exception.message;
|
||||||
else {
|
else {
|
||||||
vnApp.showError('Ups! Something went wrong');
|
vnApp.showError('Ups! Something went wrong');
|
||||||
console.error(exception);
|
console.error(exception);
|
||||||
throw exception;
|
throw exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (messageT)
|
||||||
|
message = $translate.instant(messageT);
|
||||||
vnApp.showError(message);
|
vnApp.showError(message);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue