fixes #5170-feat(recover-password): use user #1300
|
@ -3,9 +3,9 @@ module.exports = Self => {
|
||||||
description: 'Send email to the user',
|
description: 'Send email to the user',
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'email',
|
arg: 'user',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
description: 'The email of user',
|
description: 'The user name or email',
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -15,11 +15,20 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.recoverPassword = async function(email) {
|
Self.recoverPassword = async function(user) {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
|
||||||
|
const usesEmail = user.indexOf('@') !== -1;
|
||||||
|
if (!usesEmail) {
|
||||||
|
const account = await models.Account.findOne({
|
||||||
|
fields: ['email'],
|
||||||
|
where: {name: user}
|
||||||
|
});
|
||||||
|
user = account.email;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await models.user.resetPassword({email, emailTemplate: 'recover-password'});
|
await models.user.resetPassword({email: user, emailTemplate: 'recover-password'});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code === 'EMAIL_NOT_FOUND')
|
if (err.code === 'EMAIL_NOT_FOUND')
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -31,7 +31,7 @@ export default {
|
||||||
},
|
},
|
||||||
recoverPassword: {
|
recoverPassword: {
|
||||||
recoverPasswordButton: 'vn-login a[ui-sref="recover-password"]',
|
recoverPasswordButton: 'vn-login a[ui-sref="recover-password"]',
|
||||||
email: 'vn-recover-password vn-textfield[ng-model="$ctrl.email"]',
|
email: 'vn-recover-password vn-textfield[ng-model="$ctrl.user"]',
|
||||||
sendEmailButton: 'vn-recover-password vn-submit',
|
sendEmailButton: 'vn-recover-password vn-submit',
|
||||||
},
|
},
|
||||||
accountIndex: {
|
accountIndex: {
|
||||||
|
|
|
@ -26,7 +26,7 @@ describe('RecoverPassword path', async() => {
|
||||||
expect(message.text).toContain('Notification sent!');
|
expect(message.text).toContain('Notification sent!');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send email', async() => {
|
it('should send email using email', async() => {
|
||||||
await page.waitForState('login');
|
await page.waitForState('login');
|
||||||
await page.waitToClick(selectors.recoverPassword.recoverPasswordButton);
|
await page.waitToClick(selectors.recoverPassword.recoverPasswordButton);
|
||||||
|
|
||||||
|
@ -37,4 +37,16 @@ describe('RecoverPassword path', async() => {
|
||||||
|
|
||||||
expect(message.text).toContain('Notification sent!');
|
expect(message.text).toContain('Notification sent!');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should send email using username', async() => {
|
||||||
|
await page.waitForState('login');
|
||||||
|
await page.waitToClick(selectors.recoverPassword.recoverPasswordButton);
|
||||||
|
|
||||||
|
await page.write(selectors.recoverPassword.email, 'BruceWayne');
|
||||||
|
await page.waitToClick(selectors.recoverPassword.sendEmailButton);
|
||||||
|
const message = await page.waitForSnackbar();
|
||||||
|
await page.waitForState('login');
|
||||||
|
|
||||||
|
expect(message.text).toContain('Notification sent!');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<h5 class="vn-mb-md vn-mt-lg" translate>Recover password</h5>
|
<h5 class="vn-mb-md vn-mt-lg" translate>Recover password</h5>
|
||||||
<vn-textfield
|
<vn-textfield
|
||||||
label="Email"
|
label="User or recovery email"
|
||||||
ng-model="$ctrl.email"
|
ng-model="$ctrl.user"
|
||||||
vn-focus>
|
vn-focus>
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -20,7 +20,7 @@ export default class Controller {
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
const params = {
|
const params = {
|
||||||
email: this.email
|
user: this.user
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$http.post('Accounts/recoverPassword', params)
|
this.$http.post('Accounts/recoverPassword', params)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
Recover password: Recuperar contraseña
|
Recover password: Recuperar contraseña
|
||||||
We will sent you an email to recover your password: Te enviaremos un correo para restablecer tu contraseña
|
We will sent you an email to recover your password: Te enviaremos un correo para restablecer tu contraseña
|
||||||
Notification sent!: ¡Notificación enviada!
|
Notification sent!: ¡Notificación enviada!
|
||||||
|
User or recovery email: Usuario o correo de recuperación
|
||||||
|
|
Loading…
Reference in New Issue