feat(salix): refs #6427 updates
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Javier Segarra 2024-04-22 07:57:23 +02:00
parent 9a7bee8ded
commit ef8a711ed6
2 changed files with 10 additions and 21 deletions

View File

@ -4,11 +4,6 @@ module.exports = Self => {
Self.remoteMethod('recoverPasswordSMS', {
description: 'Send SMS to the user',
accepts: [
{
arg: 'ctx',
type: 'Object',
http: {source: 'context'}
},
{
arg: 'id',
type: 'string',
@ -37,27 +32,21 @@ module.exports = Self => {
}
});
Self.recoverPasswordSMS = async function(ctx, id, phone, _otp, options) {
Self.recoverPasswordSMS = async function(id, phone, otp, options) {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const usesPhone = new RegExp(/([+]\d{2})?\d{9}/, 'g').test(+phone);
if (!usesPhone) throw new UserError('Phone not valid');
let query = {
fields: ['id', 'phone', 'email', 'name'],
where: {id, phone}
};
const user = await Self.findOne(query);
const user = await Self.findOne({
fields: ['id', 'recoveryPhone', 'email', 'name'],
where: {id, recoveryPhone: phone}
});
if (!user) throw new UserError('Credentials not valid');
try {
if (_otp) {
await Self.validateCode(user.name, _otp);
if (otp) {
await Self.validateCode(user.name, otp);
return {
token: await user.accessTokens.create({})

View File

@ -26,9 +26,9 @@ module.exports = Self => {
message: 'This locker has already been assigned'
});
// Self.validateAsync('fi', tinIsValid, {
// message: 'Invalid TIN'
// });
Self.validateAsync('fi', tinIsValid, {
message: 'Invalid TIN'
});
async function tinIsValid(err, done) {
const filter = {