4077-login_recover-password & account_verifyEmail #1063
|
@ -0,0 +1,40 @@
|
|||
const UserError = require('vn-loopback/util/user-error');
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('recoverPassword', {
|
||||
description: 'Send email to the user',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'email',
|
||||
type: 'string',
|
||||
description: 'The email of user',
|
||||
required: false
|
||||
}
|
||||
],
|
||||
http: {
|
||||
path: `/recoverPassword`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.recoverPassword = async function(email) {
|
||||
console.log('ENTRY');
|
||||
const models = Self.app.models;
|
||||
const user = await models.User.findOne({
|
||||
where: {
|
||||
email: email
|
||||
}
|
||||
});
|
||||
|
||||
if (!user)
|
||||
throw new UserError(`This email does not belong to a user`);
|
||||
|
||||
const token = await models.Account.login({
|
||||
user: email,
|
||||
password: user.password
|
||||
});
|
||||
|
||||
await Self.rawSql(`CALL vn.mail_insert(?,?,?,?)`,
|
||||
[email, null, 'Recovery Password', `?token=${token}`]);
|
||||
};
|
||||
};
|
|
@ -6,6 +6,7 @@ module.exports = Self => {
|
|||
require('../methods/account/acl')(Self);
|
||||
require('../methods/account/change-password')(Self);
|
||||
require('../methods/account/set-password')(Self);
|
||||
require('../methods/account/recover-password')(Self);
|
||||
require('../methods/account/validate-token')(Self);
|
||||
|
||||
// Validations
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
|
||||
VALUES
|
||||
('Account', 'recoverPassword', 'READ', 'ALLOW', 'ROLE', 'account');
|
|
@ -30,9 +30,7 @@ export default class Auth {
|
|||
return true;
|
||||
|
||||
let redirectToLogin = () => {
|
||||
return transition.router.stateService.target('login', {
|
||||
continue: this.$window.location.hash
|
||||
});
|
||||
return transition.router.stateService.target('login');
|
||||
};
|
||||
|
||||
if (this.vnToken.token) {
|
||||
|
|
|
@ -5,16 +5,24 @@ import './style.scss';
|
|||
* A simple login form.
|
||||
*/
|
||||
export default class Controller {
|
||||
constructor($, $element) {
|
||||
constructor($, $element, $http) {
|
||||
Object.assign(this, {
|
||||
$,
|
||||
$element,
|
||||
user: localStorage.getItem('lastUser'),
|
||||
remember: true
|
||||
$http
|
||||
});
|
||||
}
|
||||
|
||||
submit() {
|
||||
const params = {
|
||||
email: this.email
|
||||
};
|
||||
|
||||
this.$http.get('Accounts/recoverPassword', params)
|
||||
.then(() => console.log('try')); // this.vnApp.showMessage(this.$t('Notification sent!')));
|
||||
}
|
||||
}
|
||||
Controller.$inject = ['$scope', '$element'];
|
||||
Controller.$inject = ['$scope', '$element', '$http'];
|
||||
|
||||
ngModule.vnComponent('vnRecoverPassword', {
|
||||
template: require('./recover-password.html'),
|
||||
|
|
|
@ -232,5 +232,6 @@
|
|||
"Fichadas impares": "Fichadas impares",
|
||||
"Descanso diario 12h.": "Descanso diario 12h.",
|
||||
"Descanso semanal 36h. / 72h.": "Descanso semanal 36h. / 72h.",
|
||||
"Dirección incorrecta": "Dirección incorrecta"
|
||||
"Dirección incorrecta": "Dirección incorrecta",
|
||||
"This email does not belong to a user": "This email does not belong to a user"
|
||||
}
|
Loading…
Reference in New Issue