#981 Login fixes

This commit is contained in:
Juan Ferrer 2019-01-25 15:09:29 +01:00
parent e76d0aaf71
commit 95c15a0ee9
12 changed files with 54 additions and 49 deletions

View File

@ -46,7 +46,7 @@ module.exports = Self => {
let filter = {where: {name: user}};
let instance = await Self.findOne(filter);
if (!instance || instance.password !== md5(password))
if (!instance || instance.password !== md5(password || ''))
throw err;
let where = {id: instance.id};

View File

@ -169,9 +169,9 @@ export default class Watcher extends Component {
*/
check() {
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)
throw new UserError(this._.instant('No changes to save'));
throw new UserError('No changes to save');
}
/**

View File

@ -7,9 +7,10 @@ import UserError from 'core/lib/user-error';
* @property {Boolean} loggedIn Whether the user is currently logged
*/
export default class Auth {
constructor($http, $state, $transitions, $window, vnToken, vnModules, aclService) {
constructor($http, $q, $state, $transitions, $window, vnToken, vnModules, aclService) {
Object.assign(this, {
$http,
$q,
$state,
$transitions,
$window,
@ -43,7 +44,7 @@ export default class Auth {
}
login(user, password, remember) {
if (!user)
throw new UserError('Please insert your user and password');
return this.$q.reject(new UserError('Please enter your username'));
let params = {
user,
@ -51,8 +52,7 @@ export default class Auth {
};
return this.$http.post('/api/Accounts/login', params).then(
json => this.onLoginOk(json, remember),
json => this.onLoginErr(json));
json => this.onLoginOk(json, remember));
}
onLoginOk(json, remember) {
this.vnToken.set(json.data.token, remember);
@ -65,22 +65,6 @@ export default class Auth {
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() {
let promise = this.$http.post('/api/Accounts/logout', null, {
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);

View File

@ -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

View File

@ -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

View File

@ -3,7 +3,6 @@ import '@babel/polyfill';
import * as ng from 'angular';
export {ng};
import 'angular-cookies';
import 'angular-translate';
import 'angular-translate-loader-partial';
import '@uirouter/angularjs';
@ -11,7 +10,6 @@ import 'mg-crud';
import 'oclazyload';
export const ngDeps = [
'ngCookies',
'pascalprecht.translate',
'ui.router',
'mgCrud',

View File

@ -31,11 +31,6 @@
"resolved": "https://registry.npmjs.org/angular/-/angular-1.7.5.tgz",
"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": {
"version": "2.18.1",
"resolved": "https://registry.npmjs.org/angular-translate/-/angular-translate-2.18.1.tgz",

View File

@ -11,7 +11,6 @@
"@babel/polyfill": "^7.2.5",
"@uirouter/angularjs": "^1.0.20",
"angular": "^1.7.5",
"angular-cookies": "^1.7.5",
"angular-translate": "^2.18.1",
"angular-translate-loader-partial": "^2.18.1",
"flatpickr": "^4.5.2",

View File

@ -21,11 +21,11 @@ export default class Controller {
localStorage.setItem('lastUser', this.user);
this.loading = false;
})
.catch(error => {
.catch(err => {
this.loading = false;
this.password = '';
this.focusUser();
throw error;
throw err;
});
}
focusUser() {

View File

@ -5,7 +5,6 @@ Logout: Logout
Change language: Change language
Profile: Profile
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
Clients: Clients
Modules access: Modules access

View File

@ -1,5 +1,4 @@
Applications: Aplicaciones
Can't contact with server: No se pudo contactar con el servidor
Change language: Cambiar idioma
Client Frozen: Cliente congelado
Client has debt: Cliente con riesgo

View File

@ -66,10 +66,12 @@ ngModule.config(config);
// Unhandled exceptions
$exceptionHandler.$inject = ['vnApp', '$window', '$state'];
function $exceptionHandler(vnApp, $window, $state) {
$exceptionHandler.$inject = ['vnApp', '$window', '$state', '$injector'];
function $exceptionHandler(vnApp, $window, $state, $injector) {
return function(exception, cause) {
let message;
let messageT;
let $translate = $injector.get('$translate');
if (exception.name == 'HttpError') {
switch (exception.xhrStatus) {
@ -78,27 +80,44 @@ function $exceptionHandler(vnApp, $window, $state) {
return;
}
let data = exception.data;
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 (data && data.error instanceof Object)
message = data.error.message;
else if (exception.status === -1)
message = `Can't contact with server`;
else
message = `${exception.status}: ${exception.statusText}`;
if (!messageT) {
let data = exception.data;
if (exception.status === 401 && $state.current.name != 'login') {
let params = {continue: $window.location.hash};
$state.go('login', params);
if (data && data.error instanceof Object)
message = data.error.message;
else
message = `${exception.status}: ${exception.statusText}`;
}
} else if (exception.name == 'UserError')
message = exception.message;
messageT = exception.message;
else {
vnApp.showError('Ups! Something went wrong');
console.error(exception);
throw exception;
}
if (messageT)
message = $translate.instant(messageT);
vnApp.showError(message);
};
}