refs #5472 feat(vn-user): override change-password & set-password
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2023-05-04 15:01:29 +02:00
parent a22a8a6bd8
commit 2da4289695
15 changed files with 60 additions and 111 deletions

View File

@ -43,14 +43,14 @@ module.exports = Self => {
? {email: user}
: {name: user};
const vnUser = await Self.findOne({
fields: ['active', 'passExpired'],
fields: ['id', 'active', 'passExpired'],
where
});
const today = Date.vnNew();
today.setHours(0, 0, 0, 0);
if (vnUser.passExpired && vnUser.passExpired.getTime() <= today.getTime())
throw new UserError('Pass expired');
throw new UserError('Pass expired', 'passExpired', {'id': vnUser.id});
const validCredentials = instance
&& await instance.hasPassword(password);

View File

@ -110,13 +110,25 @@ module.exports = function(Self) {
const _setPassword = Self.setPassword;
Self.setPassword = async function(id, newPassword, options, cb) {
// await Self.rawSql(`CALL account.user_checkPassword(?)`, [newPassword]);
// await Self.rawSql(`CALL account.user_setPassword(?, ?)`,
// [id, newPassword]);
await Self.app.models.Account.syncById(id, newPassword);
await _setPassword.call(this, id, newPassword, options, cb);
const user = await Self.findById(id);
await user.updateAttribute('passExpired', null);
return;
};
const _changePassword = Self.changePassword;
Self.changePassword = async function(id, oldPassword, newPassword, options, cb) {
// await Self.rawSql(`CALL account.user_changePassword(?, ?, ?)`,
// [id, oldPassword, newPassword]);
await Self.app.models.Account.syncById(id, newPassword);
await _changePassword.call(this, id, oldPassword, newPassword, options, cb);
return;
};
// FIX THIS
Self.afterRemote('prototype.patchAttributes', async(ctx, instance) => {
if (!ctx.args || !ctx.args.data.email) return;

View File

@ -3,7 +3,6 @@
label="Old password"
ng-model="$ctrl.oldPassword"
type="password"
info="{{'Password requirements' | translate:$ctrl.passRequirements}}"
vn-focus>
</vn-textfield>
<vn-textfield
@ -11,22 +10,16 @@
ng-model="$ctrl.newPassword"
type="password"
info="{{'Password requirements' | translate:$ctrl.passRequirements}}"
vn-focus>
</vn-textfield>
<vn-textfield
label="New password"
ng-model="$ctrl.newPassword"
type="password"
info="{{'Password requirements' | translate:$ctrl.passRequirements}}"
vn-focus>
autocomplete="false">
</vn-textfield>
<vn-textfield
label="Repeat password"
ng-model="$ctrl.repeatPassword"
type="password">
type="password"
autocomplete="false">
</vn-textfield>
<div class="footer">
<vn-submit label="Reset password" ng-click="$ctrl.submit()"></vn-submit>
<vn-submit label="Change password" ng-click="$ctrl.submit()"></vn-submit>
<div class="spinner-wrapper">
<vn-spinner enable="$ctrl.loading"></vn-spinner>
</div>

View File

@ -1,5 +1,4 @@
import ngModule from '../../module';
import './style.scss';
const UserError = require('vn-loopback/util/user-error');
export default class Controller {
@ -23,18 +22,18 @@ export default class Controller {
}
submit() {
if (!this.newPassword)
const newPassword = this.newPassword;
if (!newPassword)
throw new UserError(`You must enter a new password`);
if (this.newPassword != this.repeatPassword)
if (newPassword != this.repeatPassword)
throw new UserError(`Passwords don't match`);
const headers = {
Authorization: this.$location.$$search.access_token
};
const newPassword = this.newPassword;
this.$http.post('VnUsers/reset-password', {newPassword}, {headers})
this.$http.post('VnUsers/change-password', {newPassword}, {headers})
.then(() => {
this.vnApp.showSuccess(this.$translate.instant('Password changed!'));
this.$state.go('login');

View File

@ -1,7 +1,8 @@
Reset password: Restrablecer contraseña
Change password: Cambiar contraseña
Old password: Antigua contraseña
New password: Nueva contraseña
Repeat password: Repetir contraseña
Password changed!: ¡Contraseña cambiada!
Password changed!: ¡Contraseña actualizada!
Password requirements: >
La contraseña debe tener al menos {{ length }} caracteres de longitud,
{{nAlpha}} caracteres alfabéticos, {{nUpper}} letras mayúsculas, {{nDigits}}

View File

@ -1,24 +0,0 @@
@import "variables";
vn-reset-password{
.footer {
margin-top: 32px;
text-align: center;
position: relative;
& > .vn-submit {
display: block;
& > input {
display: block;
width: 100%;
}
}
& > .spinner-wrapper {
position: absolute;
width: 0;
top: 3px;
right: -8px;
overflow: visible;
}
}
}

View File

@ -5,10 +5,11 @@ import './style.scss';
* A simple login form.
*/
export default class Controller {
constructor($, $element, vnAuth) {
constructor($, $element, $state, vnAuth) {
Object.assign(this, {
$,
$element,
$state,
vnAuth,
user: localStorage.getItem('lastUser'),
remember: true
@ -22,15 +23,15 @@ export default class Controller {
localStorage.setItem('lastUser', this.user);
this.loading = false;
})
.catch(err => {
.catch(req => {
this.loading = false;
this.password = '';
this.focusUser();
console.log('hola');
console.log(err);
console.log(err.message);
console.log(err.stack);
throw err;
console.log(req.data.error);
console.log(req.data.error.code);
throw req;
if (req.data.error.code = 'passExpired')
this.$state.go('change-password');
});
}
@ -39,7 +40,7 @@ export default class Controller {
this.$.userField.focus();
}
}
Controller.$inject = ['$scope', '$element', 'vnAuth'];
Controller.$inject = ['$scope', '$element', '$state', 'vnAuth'];
ngModule.vnComponent('vnLogin', {
template: require('./index.html'),

View File

@ -64,4 +64,25 @@ vn-out-layout{
a{
color: $color-primary;
}
.footer {
margin-top: 32px;
text-align: center;
position: relative;
& > .vn-submit {
display: block;
& > input {
display: block;
width: 100%;
}
}
& > .spinner-wrapper {
position: absolute;
width: 0;
top: 3px;
right: -8px;
overflow: visible;
}
}
}

View File

@ -1,5 +1,4 @@
import ngModule from '../../module';
import './style.scss';
export default class Controller {
constructor($scope, $element, $http, vnApp, $translate, $state) {

View File

@ -1,24 +0,0 @@
@import "variables";
vn-recover-password{
.footer {
margin-top: 32px;
text-align: center;
position: relative;
& > .vn-submit {
display: block;
& > input {
display: block;
width: 100%;
}
}
& > .spinner-wrapper {
position: absolute;
width: 0;
top: 3px;
right: -8px;
overflow: visible;
}
}
}

View File

@ -1,5 +1,4 @@
import ngModule from '../../module';
import './style.scss';
const UserError = require('vn-loopback/util/user-error');
export default class Controller {

View File

@ -1,24 +0,0 @@
@import "variables";
vn-reset-password{
.footer {
margin-top: 32px;
text-align: center;
position: relative;
& > .vn-submit {
display: block;
& > input {
display: block;
width: 100%;
}
}
& > .spinner-wrapper {
position: absolute;
width: 0;
top: 3px;
right: -8px;
overflow: visible;
}
}
}

View File

@ -28,8 +28,6 @@ module.exports = Self => {
});
Self.changePassword = async function(id, oldPassword, newPassword) {
await Self.rawSql(`CALL account.user_changePassword(?, ?, ?)`,
[id, oldPassword, newPassword]);
await Self.app.models.Account.syncById(id, newPassword);
await Self.app.models.VnUser.changePassword(id, oldPassword, newPassword);
};
};

View File

@ -22,8 +22,6 @@ module.exports = Self => {
});
Self.setPassword = async function(id, newPassword) {
await Self.rawSql(`CALL account.user_setPassword(?, ?)`,
[id, newPassword]);
await Self.app.models.Account.syncById(id, newPassword);
await Self.app.models.VnUser.setPassword(id, newPassword);
};
};

View File

@ -33,7 +33,7 @@ module.exports = Self => {
const isSync = !await models.UserSync.exists(userName);
if (!force && isSync && user) return;
await models.AccountConfig.syncUser(userName, password);
// await models.AccountConfig.syncUser(userName, password);
await models.UserSync.destroyById(userName);
};
};