This commit is contained in:
parent
a01637414e
commit
d534ee423b
|
@ -35,8 +35,15 @@ module.exports = Self => {
|
|||
Object.assign(myOptions, options);
|
||||
|
||||
const user = await Self.findOne({
|
||||
fields: ['id', 'userId', 'email', 'name', 'recoveryPhone'],
|
||||
where: {userId}
|
||||
fields: ['id', 'name', 'email', 'name', 'recoveryPhone'],
|
||||
where: {
|
||||
or: [
|
||||
{id: userId},
|
||||
{nickname: userId},
|
||||
{name: userId},
|
||||
{email: userId},
|
||||
]
|
||||
}
|
||||
});
|
||||
if (!user) throw new UserError('Credentials not valid');
|
||||
|
||||
|
@ -51,9 +58,9 @@ module.exports = Self => {
|
|||
|
||||
const code = await authCode(user, myOptions);
|
||||
|
||||
if (!isProduction())
|
||||
if (isProduction(true))
|
||||
return {code};
|
||||
await Self.app.models.Sms.send({req: {accessToken: {userId: id}}}, +userId, code);
|
||||
await Self.app.models.Sms.send({req: {accessToken: {userId}}}, +userId, code);
|
||||
} catch (err) {
|
||||
if (err.code === 'EMAIL_NOT_FOUND')
|
||||
return;
|
||||
|
|
|
@ -33,7 +33,11 @@ export default {
|
|||
recoverPassword: {
|
||||
recoverPasswordButton: 'vn-login a[ui-sref="recover-password"]',
|
||||
email: 'vn-recover-password vn-textfield[ng-model="$ctrl.user"]',
|
||||
code: 'vn-recover-password vn-textfield[ng-model="$ctrl.verificationCode"]',
|
||||
sendEmailButton: 'vn-recover-password vn-submit',
|
||||
smsOption: 'vn-recover-password vn-radio[val="sms"]',
|
||||
emailOption: 'vn-recover-password vn-radio[val="email"]',
|
||||
|
||||
},
|
||||
accountIndex: {
|
||||
addAccount: 'vn-user-index button vn-icon[icon="add"]',
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import selectors from '../../helpers/selectors';
|
||||
import getBrowser from '../../helpers/puppeteer';
|
||||
|
||||
describe('RecoverPassword path', async() => {
|
||||
fdescribe('RecoverPassword path', async() => {
|
||||
let browser;
|
||||
let page;
|
||||
|
||||
|
@ -17,8 +17,9 @@ describe('RecoverPassword path', async() => {
|
|||
await browser.close();
|
||||
});
|
||||
|
||||
it('should not throw error if not exist user', async() => {
|
||||
it('should not throw error if not exist user when select email option', async() => {
|
||||
await page.write(selectors.recoverPassword.email, 'fakeEmail@mydomain.com');
|
||||
await page.waitToClick(selectors.recoverPassword.emailOption);
|
||||
await page.waitToClick(selectors.recoverPassword.sendEmailButton);
|
||||
|
||||
const message = await page.waitForSnackbar();
|
||||
|
@ -26,11 +27,27 @@ describe('RecoverPassword path', async() => {
|
|||
expect(message.text).toContain('Notification sent!');
|
||||
});
|
||||
|
||||
it('should not throw error if not exist user when select sms option', async() => {
|
||||
await page.waitForState('login');
|
||||
await page.waitToClick(selectors.recoverPassword.recoverPasswordButton);
|
||||
await page.write(selectors.recoverPassword.email, 'fakeEmail@mydomain.com');
|
||||
await page.waitToClick(selectors.recoverPassword.emailOption);
|
||||
// await page.waitToClick(selectors.recoverPassword.smsOption);
|
||||
await page.waitToClick(selectors.recoverPassword.sendEmailButton);
|
||||
|
||||
const message = await page.waitForSnackbar();
|
||||
// await page.waitForState('login');
|
||||
|
||||
expect(message.text).toContain('Credentials not valid');
|
||||
expect(await page.getState()).toContain('recover-password');
|
||||
});
|
||||
|
||||
it('should send email using email', async() => {
|
||||
await page.waitForState('login');
|
||||
await page.waitToClick(selectors.recoverPassword.recoverPasswordButton);
|
||||
|
||||
await page.write(selectors.recoverPassword.email, 'BruceWayne@mydomain.com');
|
||||
await page.waitToClick(selectors.recoverPassword.emailOption);
|
||||
await page.waitToClick(selectors.recoverPassword.sendEmailButton);
|
||||
const message = await page.waitForSnackbar();
|
||||
await page.waitForState('login');
|
||||
|
@ -43,10 +60,29 @@ describe('RecoverPassword path', async() => {
|
|||
await page.waitToClick(selectors.recoverPassword.recoverPasswordButton);
|
||||
|
||||
await page.write(selectors.recoverPassword.email, 'BruceWayne');
|
||||
await page.waitToClick(selectors.recoverPassword.emailOption);
|
||||
await page.waitToClick(selectors.recoverPassword.sendEmailButton);
|
||||
const message = await page.waitForSnackbar();
|
||||
await page.waitForState('login');
|
||||
|
||||
expect(message.text).toContain('Notification sent!');
|
||||
});
|
||||
|
||||
it('should send sms 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.smsOption);
|
||||
await page.waitToClick(selectors.recoverPassword.sendEmailButton);
|
||||
const httpDataResponse = await page.waitForResponse(response => {
|
||||
return response.status() === 200 && response.url().includes(`VnUsers/recoverPasswordSMS`);
|
||||
});
|
||||
const {code} = await httpDataResponse.json();
|
||||
await page.write(selectors.recoverPassword.code, code);
|
||||
await page.waitToClick(selectors.recoverPassword.sendEmailButton);
|
||||
await page.waitForState('reset-password');
|
||||
|
||||
expect(await page.getState()).toContain('reset-password');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
<h5 class="vn-mb-md vn-mt-lg" translate>Recover password</h5>
|
||||
<vn-textfield
|
||||
disabled="$ctrl.code"
|
||||
disabled="$ctrl.code"
|
||||
label="User or recovery email"
|
||||
ng-model="$ctrl.user"
|
||||
vn-focus>
|
||||
vn-focus
|
||||
>
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
ng-if="$ctrl.code"
|
||||
|
@ -11,22 +12,26 @@ disabled="$ctrl.code"
|
|||
ng-model="$ctrl.verificationCode"
|
||||
vn-name="verificationCode"
|
||||
autocomplete="false"
|
||||
class="vn-mt-md">
|
||||
class="vn-mt-md"
|
||||
>
|
||||
</vn-textfield>
|
||||
<vn-one>
|
||||
<vn-vertical class="vn-mb-sm">
|
||||
<vn-radio
|
||||
disabled="$ctrl.code"
|
||||
label="Móvil"
|
||||
val="sms"
|
||||
ng-model="$ctrl.method" >
|
||||
</vn-radio>
|
||||
<vn-radio
|
||||
disabled="$ctrl.code"
|
||||
label="Correo de recuperación"
|
||||
val="email"
|
||||
ng-model="$ctrl.method" >
|
||||
</vn-radio></vn-vertical></vn-one>
|
||||
<vn-radio
|
||||
disabled="$ctrl.code"
|
||||
label="Móvil"
|
||||
val="sms"
|
||||
ng-model="$ctrl.method"
|
||||
>
|
||||
</vn-radio>
|
||||
<vn-radio
|
||||
disabled="$ctrl.code"
|
||||
label="Correo de recuperación"
|
||||
val="email"
|
||||
ng-model="$ctrl.method"
|
||||
>
|
||||
</vn-radio></vn-vertical
|
||||
></vn-one>
|
||||
<div class="text-secondary" ng-if="$ctrl.method && $ctrl.user">
|
||||
<span ng-if="$ctrl.method ==='sms'" translate>
|
||||
We will sent you a sms to recover your password
|
||||
|
@ -36,7 +41,11 @@ ng-model="$ctrl.method" >
|
|||
</span>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<vn-submit disabled="!$ctrl.user || !$ctrl.method || ($ctrl.code&&!$ctrl.verificationCode)" label="Recover password" ng-click="$ctrl.submit()"></vn-submit>
|
||||
<vn-submit
|
||||
disabled="!$ctrl.user || !$ctrl.method || ($ctrl.code&&!$ctrl.verificationCode)"
|
||||
label="Recover password"
|
||||
ng-click="$ctrl.submit()"
|
||||
></vn-submit>
|
||||
<div class="spinner-wrapper">
|
||||
<vn-spinner enable="$ctrl.loading"></vn-spinner>
|
||||
</div>
|
||||
|
|
|
@ -24,10 +24,9 @@ export default class Controller {
|
|||
else
|
||||
this.$location.path('/reset-password').search('access_token', token.id);
|
||||
}
|
||||
goToOTP(code) {
|
||||
handleCode(code) {
|
||||
this.code = true;
|
||||
this.$state.params.verificationCode = code;
|
||||
// this.code = null;
|
||||
}
|
||||
methodsAvailables() {
|
||||
return {
|
||||
|
@ -49,8 +48,10 @@ export default class Controller {
|
|||
if (this.method && this.code) {
|
||||
data.token && this.goToChangePassword(data);
|
||||
!data.token && this.goToLogin();
|
||||
} else
|
||||
data.code && this.goToOTP(data.code);
|
||||
} else {
|
||||
if (data === '') this.goToLogin();
|
||||
data.code && this.handleCode(data.code);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -227,5 +227,6 @@
|
|||
"They're not your subordinate": "They're not your subordinate",
|
||||
"InvoiceIn is already booked": "InvoiceIn is already booked",
|
||||
"This workCenter is already assigned to this agency": "This workCenter is already assigned to this agency",
|
||||
"You can only have one PDA": "You can only have one PDA"
|
||||
"You can only have one PDA": "You can only have one PDA",
|
||||
"Credentials not valid": "Credentials not valid"
|
||||
}
|
|
@ -359,5 +359,6 @@
|
|||
"It was not able to create the invoice": "No se pudo crear la factura",
|
||||
"ticketCommercial": "El ticket {{ ticket }} para el vendedor {{ salesMan }} está en preparación. (mensaje generado automáticamente)",
|
||||
"This PDA is already assigned to another user": "Este PDA ya está asignado a otro usuario",
|
||||
"You can only have one PDA": "Solo puedes tener un PDA"
|
||||
}
|
||||
"You can only have one PDA": "Solo puedes tener un PDA",
|
||||
"Credentials not valid": "Credentials not valid"
|
||||
}
|
Loading…
Reference in New Issue