refs #5472 try change-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
728ef965c4
commit
73fb940c63
|
@ -110,25 +110,28 @@ module.exports = function(Self) {
|
|||
|
||||
const _setPassword = Self.setPassword;
|
||||
Self.setPassword = async function(id, newPassword, options, cb) {
|
||||
console.log('Entry in override SET_PASSWORD');
|
||||
await Self.rawSql(`CALL account.user_setPassword(?, ?)`,
|
||||
[id, newPassword]);
|
||||
console.log('Entry in override SET_PASSWORD');
|
||||
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 = 9, oldPassword, newPassword, options, cb) {
|
||||
console.log(id, oldPassword, newPassword);
|
||||
Self.changePassword = async function(id, oldPassword, newPassword, options, cb) {
|
||||
if (options && options.id) id = options.id;
|
||||
console.log(id, oldPassword, newPassword, options);
|
||||
|
||||
await Self.rawSql(`CALL account.user_changePassword(?, ?, ?)`,
|
||||
[id, oldPassword, newPassword]);
|
||||
console.log('Entry in override CHANGE_PASSWORD');
|
||||
await _changePassword.call(this, id, oldPassword, newPassword, options, cb);
|
||||
return;
|
||||
|
||||
const user = await Self.findById(id);
|
||||
await user.updateAttribute('passExpired', null);
|
||||
};
|
||||
|
||||
// FIX THIS
|
||||
|
|
|
@ -1 +1,21 @@
|
|||
ALTER TABLE `account`.`user` ADD passExpired DATE DEFAULT NULL;
|
||||
|
||||
DROP TRIGGER IF EXISTS `account`.`user_beforeUpdate`;
|
||||
USE account;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE DEFINER=`root`@`localhost` TRIGGER `account`.`user_beforeUpdate`
|
||||
BEFORE UPDATE ON `user`
|
||||
FOR EACH ROW
|
||||
BEGIN
|
||||
IF !(NEW.`name` <=> OLD.`name`) THEN
|
||||
CALL user_checkName (NEW.`name`);
|
||||
END IF;
|
||||
|
||||
IF !(NEW.`password` <=> OLD.`password`) THEN
|
||||
SET NEW.lastPassChange = util.VN_NOW();
|
||||
END IF;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
USE vn;
|
||||
|
|
|
@ -71,8 +71,8 @@ INSERT INTO `account`.`roleConfig`(`id`, `mysqlPassword`, `rolePrefix`, `userPre
|
|||
|
||||
CALL `account`.`role_sync`;
|
||||
|
||||
INSERT INTO `account`.`user`(`id`,`name`, `nickname`, `password`,`role`,`active`,`email`, `lang`, `image`, `bcryptPassword`)
|
||||
SELECT id, name, CONCAT(name, 'Nick'),MD5('nightmare'), id, 1, CONCAT(name, '@mydomain.com'), 'en', '4fa3ada0-3ac4-11eb-9ab8-27f6fc3b85fd', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2'
|
||||
INSERT INTO `account`.`user`(`id`,`name`, `nickname`, `password`,`role`,`active`,`email`, `lang`, `image`, `bcryptPassword`, `passExpired`)
|
||||
SELECT id, name, CONCAT(name, 'Nick'),MD5('nightmare'), id, 1, CONCAT(name, '@mydomain.com'), 'en', '4fa3ada0-3ac4-11eb-9ab8-27f6fc3b85fd', '$2b$10$UzQHth.9UUQ1T5aiQJ21lOU0oVlbxoqH4PFM9V8T90KNSAcg0eEL2', '1999-01-01'
|
||||
FROM `account`.`role` WHERE id <> 20
|
||||
ORDER BY id;
|
||||
|
||||
|
|
|
@ -15,6 +15,9 @@ export default class Controller {
|
|||
}
|
||||
|
||||
$onInit() {
|
||||
if (!this.$state.params || !this.$state.params.id)
|
||||
this.$state.go('login');
|
||||
|
||||
this.$http.get('UserPasswords/findOne')
|
||||
.then(res => {
|
||||
this.passRequirements = res.data;
|
||||
|
@ -31,10 +34,25 @@ export default class Controller {
|
|||
throw new UserError(`Passwords don't match`);
|
||||
|
||||
const headers = {
|
||||
Authorization: {principalType: 'VnUser'}
|
||||
Authorization: {id: 9},
|
||||
id: 9
|
||||
};
|
||||
|
||||
this.$http.post('VnUsers/change-password', {oldPassword, newPassword}, {headers})
|
||||
console.log(this.$state.params.id);
|
||||
const id = this.$state.params.id;
|
||||
this.$http.post('VnUsers/change-password',
|
||||
{
|
||||
id: 9,
|
||||
oldPassword,
|
||||
newPassword,
|
||||
accessToken: 'hola5',
|
||||
options: {
|
||||
id: 9,
|
||||
accessToken: {id: 9}
|
||||
}
|
||||
},
|
||||
{headers, id: 9},
|
||||
{id: 9})
|
||||
.then(() => {
|
||||
this.vnApp.showSuccess(this.$translate.instant('Password updated!'));
|
||||
this.$state.go('login');
|
||||
|
@ -45,5 +63,8 @@ Controller.$inject = ['$scope', '$element', '$http', 'vnApp', '$translate', '$st
|
|||
|
||||
ngModule.vnComponent('vnChangePassword', {
|
||||
template: require('./index.html'),
|
||||
controller: Controller
|
||||
controller: Controller,
|
||||
bindings: {
|
||||
id: '<'
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import ngModule from '../../module';
|
||||
import './style.scss';
|
||||
import UserError from 'core/lib/user-error';
|
||||
|
||||
/**
|
||||
* A simple login form.
|
||||
|
@ -28,11 +27,11 @@ export default class Controller {
|
|||
this.loading = false;
|
||||
this.password = '';
|
||||
this.focusUser();
|
||||
// console.log(req.data.error);
|
||||
// console.log(req.data.error.code);
|
||||
|
||||
if (req.data.error.code == 'passExpired')
|
||||
this.$state.go('change-password');
|
||||
if (req.data.error.code == 'passExpired') {
|
||||
const [args] = req.data.error.translateArgs;
|
||||
this.$state.go('change-password', args);
|
||||
}
|
||||
|
||||
throw req;
|
||||
});
|
||||
|
|
|
@ -35,7 +35,7 @@ function config($stateProvider, $urlRouterProvider) {
|
|||
})
|
||||
.state('change-password', {
|
||||
parent: 'outLayout',
|
||||
url: '/change-password',
|
||||
url: '/change-password?id',
|
||||
description: 'Change password',
|
||||
template: '<vn-change-password></vn-change-password>'
|
||||
})
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
describe('account changePassword()', () => {
|
||||
fdescribe('account changePassword()', () => {
|
||||
it('should throw an error when old password is wrong', async() => {
|
||||
let err;
|
||||
await models.Account.changePassword(1, 'wrongPassword', 'nightmare.9999')
|
||||
|
@ -9,4 +9,12 @@ describe('account changePassword()', () => {
|
|||
expect(err).toBeDefined();
|
||||
expect(err).toEqual('Invalid password');
|
||||
});
|
||||
|
||||
it('should change password', async() => {
|
||||
try {
|
||||
await models.Account.changePassword(70, 'nightmare', 'nightmare.9999');
|
||||
} catch (e) {
|
||||
expect(e).toBeUndefined();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue