refs #5472 feat(vn-user): override change-password & set-password
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
a22a8a6bd8
commit
2da4289695
|
@ -43,14 +43,14 @@ module.exports = Self => {
|
||||||
? {email: user}
|
? {email: user}
|
||||||
: {name: user};
|
: {name: user};
|
||||||
const vnUser = await Self.findOne({
|
const vnUser = await Self.findOne({
|
||||||
fields: ['active', 'passExpired'],
|
fields: ['id', 'active', 'passExpired'],
|
||||||
where
|
where
|
||||||
});
|
});
|
||||||
|
|
||||||
const today = Date.vnNew();
|
const today = Date.vnNew();
|
||||||
today.setHours(0, 0, 0, 0);
|
today.setHours(0, 0, 0, 0);
|
||||||
if (vnUser.passExpired && vnUser.passExpired.getTime() <= today.getTime())
|
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
|
const validCredentials = instance
|
||||||
&& await instance.hasPassword(password);
|
&& await instance.hasPassword(password);
|
||||||
|
|
|
@ -110,13 +110,25 @@ module.exports = function(Self) {
|
||||||
|
|
||||||
const _setPassword = Self.setPassword;
|
const _setPassword = Self.setPassword;
|
||||||
Self.setPassword = async function(id, newPassword, options, cb) {
|
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);
|
await _setPassword.call(this, id, newPassword, options, cb);
|
||||||
|
|
||||||
const user = await Self.findById(id);
|
const user = await Self.findById(id);
|
||||||
await user.updateAttribute('passExpired', null);
|
await user.updateAttribute('passExpired', null);
|
||||||
return;
|
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
|
// FIX THIS
|
||||||
Self.afterRemote('prototype.patchAttributes', async(ctx, instance) => {
|
Self.afterRemote('prototype.patchAttributes', async(ctx, instance) => {
|
||||||
if (!ctx.args || !ctx.args.data.email) return;
|
if (!ctx.args || !ctx.args.data.email) return;
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
label="Old password"
|
label="Old password"
|
||||||
ng-model="$ctrl.oldPassword"
|
ng-model="$ctrl.oldPassword"
|
||||||
type="password"
|
type="password"
|
||||||
info="{{'Password requirements' | translate:$ctrl.passRequirements}}"
|
|
||||||
vn-focus>
|
vn-focus>
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
|
@ -11,22 +10,16 @@
|
||||||
ng-model="$ctrl.newPassword"
|
ng-model="$ctrl.newPassword"
|
||||||
type="password"
|
type="password"
|
||||||
info="{{'Password requirements' | translate:$ctrl.passRequirements}}"
|
info="{{'Password requirements' | translate:$ctrl.passRequirements}}"
|
||||||
vn-focus>
|
autocomplete="false">
|
||||||
</vn-textfield>
|
|
||||||
<vn-textfield
|
|
||||||
label="New password"
|
|
||||||
ng-model="$ctrl.newPassword"
|
|
||||||
type="password"
|
|
||||||
info="{{'Password requirements' | translate:$ctrl.passRequirements}}"
|
|
||||||
vn-focus>
|
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
label="Repeat password"
|
label="Repeat password"
|
||||||
ng-model="$ctrl.repeatPassword"
|
ng-model="$ctrl.repeatPassword"
|
||||||
type="password">
|
type="password"
|
||||||
|
autocomplete="false">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<div class="footer">
|
<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">
|
<div class="spinner-wrapper">
|
||||||
<vn-spinner enable="$ctrl.loading"></vn-spinner>
|
<vn-spinner enable="$ctrl.loading"></vn-spinner>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import ngModule from '../../module';
|
import ngModule from '../../module';
|
||||||
import './style.scss';
|
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
export default class Controller {
|
export default class Controller {
|
||||||
|
@ -23,18 +22,18 @@ export default class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
if (!this.newPassword)
|
const newPassword = this.newPassword;
|
||||||
|
|
||||||
|
if (!newPassword)
|
||||||
throw new UserError(`You must enter a new password`);
|
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`);
|
throw new UserError(`Passwords don't match`);
|
||||||
|
|
||||||
const headers = {
|
const headers = {
|
||||||
Authorization: this.$location.$$search.access_token
|
Authorization: this.$location.$$search.access_token
|
||||||
};
|
};
|
||||||
|
|
||||||
const newPassword = this.newPassword;
|
this.$http.post('VnUsers/change-password', {newPassword}, {headers})
|
||||||
|
|
||||||
this.$http.post('VnUsers/reset-password', {newPassword}, {headers})
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.vnApp.showSuccess(this.$translate.instant('Password changed!'));
|
this.vnApp.showSuccess(this.$translate.instant('Password changed!'));
|
||||||
this.$state.go('login');
|
this.$state.go('login');
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
Reset password: Restrablecer contraseña
|
Change password: Cambiar contraseña
|
||||||
|
Old password: Antigua contraseña
|
||||||
New password: Nueva contraseña
|
New password: Nueva contraseña
|
||||||
Repeat password: Repetir contraseña
|
Repeat password: Repetir contraseña
|
||||||
Password changed!: ¡Contraseña cambiada!
|
Password changed!: ¡Contraseña actualizada!
|
||||||
Password requirements: >
|
Password requirements: >
|
||||||
La contraseña debe tener al menos {{ length }} caracteres de longitud,
|
La contraseña debe tener al menos {{ length }} caracteres de longitud,
|
||||||
{{nAlpha}} caracteres alfabéticos, {{nUpper}} letras mayúsculas, {{nDigits}}
|
{{nAlpha}} caracteres alfabéticos, {{nUpper}} letras mayúsculas, {{nDigits}}
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,10 +5,11 @@ import './style.scss';
|
||||||
* A simple login form.
|
* A simple login form.
|
||||||
*/
|
*/
|
||||||
export default class Controller {
|
export default class Controller {
|
||||||
constructor($, $element, vnAuth) {
|
constructor($, $element, $state, vnAuth) {
|
||||||
Object.assign(this, {
|
Object.assign(this, {
|
||||||
$,
|
$,
|
||||||
$element,
|
$element,
|
||||||
|
$state,
|
||||||
vnAuth,
|
vnAuth,
|
||||||
user: localStorage.getItem('lastUser'),
|
user: localStorage.getItem('lastUser'),
|
||||||
remember: true
|
remember: true
|
||||||
|
@ -22,15 +23,15 @@ export default class Controller {
|
||||||
localStorage.setItem('lastUser', this.user);
|
localStorage.setItem('lastUser', this.user);
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(req => {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
this.password = '';
|
this.password = '';
|
||||||
this.focusUser();
|
this.focusUser();
|
||||||
console.log('hola');
|
console.log(req.data.error);
|
||||||
console.log(err);
|
console.log(req.data.error.code);
|
||||||
console.log(err.message);
|
throw req;
|
||||||
console.log(err.stack);
|
if (req.data.error.code = 'passExpired')
|
||||||
throw err;
|
this.$state.go('change-password');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ export default class Controller {
|
||||||
this.$.userField.focus();
|
this.$.userField.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Controller.$inject = ['$scope', '$element', 'vnAuth'];
|
Controller.$inject = ['$scope', '$element', '$state', 'vnAuth'];
|
||||||
|
|
||||||
ngModule.vnComponent('vnLogin', {
|
ngModule.vnComponent('vnLogin', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
|
|
|
@ -64,4 +64,25 @@ vn-out-layout{
|
||||||
a{
|
a{
|
||||||
color: $color-primary;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import ngModule from '../../module';
|
import ngModule from '../../module';
|
||||||
import './style.scss';
|
|
||||||
|
|
||||||
export default class Controller {
|
export default class Controller {
|
||||||
constructor($scope, $element, $http, vnApp, $translate, $state) {
|
constructor($scope, $element, $http, vnApp, $translate, $state) {
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,4 @@
|
||||||
import ngModule from '../../module';
|
import ngModule from '../../module';
|
||||||
import './style.scss';
|
|
||||||
const UserError = require('vn-loopback/util/user-error');
|
const UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
export default class Controller {
|
export default class Controller {
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -28,8 +28,6 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.changePassword = async function(id, oldPassword, newPassword) {
|
Self.changePassword = async function(id, oldPassword, newPassword) {
|
||||||
await Self.rawSql(`CALL account.user_changePassword(?, ?, ?)`,
|
await Self.app.models.VnUser.changePassword(id, oldPassword, newPassword);
|
||||||
[id, oldPassword, newPassword]);
|
|
||||||
await Self.app.models.Account.syncById(id, newPassword);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -22,8 +22,6 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.setPassword = async function(id, newPassword) {
|
Self.setPassword = async function(id, newPassword) {
|
||||||
await Self.rawSql(`CALL account.user_setPassword(?, ?)`,
|
await Self.app.models.VnUser.setPassword(id, newPassword);
|
||||||
[id, newPassword]);
|
|
||||||
await Self.app.models.Account.syncById(id, newPassword);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,7 +33,7 @@ module.exports = Self => {
|
||||||
const isSync = !await models.UserSync.exists(userName);
|
const isSync = !await models.UserSync.exists(userName);
|
||||||
|
|
||||||
if (!force && isSync && user) return;
|
if (!force && isSync && user) return;
|
||||||
await models.AccountConfig.syncUser(userName, password);
|
// await models.AccountConfig.syncUser(userName, password);
|
||||||
await models.UserSync.destroyById(userName);
|
await models.UserSync.destroyById(userName);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue