This commit is contained in:
parent
9a7bee8ded
commit
ef8a711ed6
|
@ -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({})
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in New Issue