perf(salix): refs #6427 imrpove
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
8201d057f3
commit
9953df2f4f
|
@ -7,7 +7,7 @@ module.exports = Self => {
|
|||
accepts: [
|
||||
|
||||
{
|
||||
arg: 'userId',
|
||||
arg: 'user',
|
||||
type: 'string',
|
||||
description: 'The recoveryPhone user\'s',
|
||||
required: true
|
||||
|
@ -28,44 +28,36 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.recoverPasswordSMS = async function(userId, verificationCode, options) {
|
||||
Self.recoverPasswordSMS = async function(user, verificationCode, options) {
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const user = await Self.findOne({
|
||||
fields: ['id', 'name', 'email', 'name', 'recoveryPhone'],
|
||||
where: {
|
||||
or: [
|
||||
{id: userId},
|
||||
{nickname: userId},
|
||||
{name: userId},
|
||||
{email: userId},
|
||||
]
|
||||
}
|
||||
const usesEmail = user.indexOf('@') !== -1;
|
||||
const filter = usesEmail ? {email: user} : {name: user};
|
||||
// if (!usesEmail) {
|
||||
const account = await models.VnUser.findOne({
|
||||
fields: ['id', 'name', 'recoveryPhone'],
|
||||
where: filter
|
||||
});
|
||||
if (!user) throw new UserError('Credentials not valid');
|
||||
if (!account) return;
|
||||
user = account;
|
||||
// }
|
||||
|
||||
try {
|
||||
if (verificationCode) {
|
||||
await Self.validateCode(user.name, verificationCode);
|
||||
if (verificationCode) {
|
||||
await Self.validateCode(user.name, verificationCode);
|
||||
|
||||
return {
|
||||
token: await user.accessTokens.create({})
|
||||
};
|
||||
}
|
||||
|
||||
const code = await authCode(user, myOptions);
|
||||
|
||||
if (isProduction(true))
|
||||
return {code};
|
||||
await Self.app.models.Sms.send({req: {accessToken: {userId}}}, +userId, code);
|
||||
} catch (err) {
|
||||
if (err.code === 'EMAIL_NOT_FOUND')
|
||||
return;
|
||||
else
|
||||
throw err;
|
||||
return {
|
||||
token: await user.accessTokens.create({})
|
||||
};
|
||||
}
|
||||
|
||||
const code = await authCode(user, myOptions);
|
||||
|
||||
if (isProduction(true))
|
||||
return {code};
|
||||
await Self.app.models.Sms.send({req: {accessToken: {user: user.id}}}, +user.recoveryPhone, code);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -8,6 +8,10 @@ fdescribe('RecoverPassword path', async() => {
|
|||
beforeAll(async() => {
|
||||
browser = await getBrowser();
|
||||
page = browser.page;
|
||||
});
|
||||
|
||||
beforeEach(async() => {
|
||||
await page.waitForState('login');
|
||||
|
||||
await page.waitToClick(selectors.recoverPassword.recoverPasswordButton);
|
||||
await page.waitForState('recover-password');
|
||||
|
@ -33,47 +37,33 @@ fdescribe('RecoverPassword path', async() => {
|
|||
});
|
||||
|
||||
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');
|
||||
|
||||
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.emailOption);
|
||||
await page.waitToClick(selectors.recoverPassword.sendEmailButton);
|
||||
const message = await page.waitForSnackbar();
|
||||
await page.waitForState('login');
|
||||
|
||||
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.smsOption);
|
||||
await page.waitToClick(selectors.recoverPassword.sendEmailButton);
|
||||
|
||||
const message = await page.waitForSnackbar();
|
||||
|
||||
expect(message.text).toContain('Credentials not valid');
|
||||
expect(await page.getState()).toContain('recover-password');
|
||||
expect(message.text).toContain('Notification sent!');
|
||||
});
|
||||
|
||||
it('should send sms using username', async() => {
|
||||
await page.clearInput(selectors.recoverPassword.email);
|
||||
|
||||
await page.write(selectors.recoverPassword.email, 'BruceWayne');
|
||||
await page.waitToClick(selectors.recoverPassword.smsOption);
|
||||
await page.waitToClick(selectors.recoverPassword.sendEmailButton);
|
||||
|
|
|
@ -33,19 +33,16 @@ export default class Controller {
|
|||
'email': {
|
||||
url: 'VnUsers/recoverPassword',
|
||||
data: {user: this.user},
|
||||
cb: data => {
|
||||
if (data === '') this.goToLogin();
|
||||
}
|
||||
|
||||
},
|
||||
'sms': {
|
||||
url: 'VnUsers/recoverPasswordSMS',
|
||||
data: {userId: this.user, verificationCode: this.verificationCode},
|
||||
data: {user: this.user, verificationCode: this.verificationCode},
|
||||
cb: data => {
|
||||
if (this.method && this.code) {
|
||||
data.token && this.goToChangePassword(data);
|
||||
!data.token && this.goToLogin();
|
||||
} else
|
||||
|
||||
data.code && this.handleCode(data.code);
|
||||
}
|
||||
},
|
||||
|
@ -57,7 +54,7 @@ export default class Controller {
|
|||
throw new UserError(`Credentials not valid`);
|
||||
const method = this.methodsAvailables()[this.method];
|
||||
this.$http.post(method.url, method.data)
|
||||
.then(({data}) => method.cb(data));
|
||||
.then(({data}) => data === '' ? this.goToLogin() : method.cb(data));
|
||||
}
|
||||
}
|
||||
Controller.$inject = ['$scope', '$element', '$http', 'vnApp', '$translate', '$state', '$location'];
|
||||
|
|
Loading…
Reference in New Issue