This commit is contained in:
parent
9a7bee8ded
commit
ef8a711ed6
|
@ -4,11 +4,6 @@ module.exports = Self => {
|
||||||
Self.remoteMethod('recoverPasswordSMS', {
|
Self.remoteMethod('recoverPasswordSMS', {
|
||||||
description: 'Send SMS to the user',
|
description: 'Send SMS to the user',
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
|
||||||
arg: 'ctx',
|
|
||||||
type: 'Object',
|
|
||||||
http: {source: 'context'}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'string',
|
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 = {};
|
const myOptions = {};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const usesPhone = new RegExp(/([+]\d{2})?\d{9}/, 'g').test(+phone);
|
const user = await Self.findOne({
|
||||||
|
fields: ['id', 'recoveryPhone', 'email', 'name'],
|
||||||
if (!usesPhone) throw new UserError('Phone not valid');
|
where: {id, recoveryPhone: phone}
|
||||||
|
});
|
||||||
let query = {
|
|
||||||
fields: ['id', 'phone', 'email', 'name'],
|
|
||||||
where: {id, phone}
|
|
||||||
};
|
|
||||||
|
|
||||||
const user = await Self.findOne(query);
|
|
||||||
if (!user) throw new UserError('Credentials not valid');
|
if (!user) throw new UserError('Credentials not valid');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (_otp) {
|
if (otp) {
|
||||||
await Self.validateCode(user.name, _otp);
|
await Self.validateCode(user.name, otp);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
token: await user.accessTokens.create({})
|
token: await user.accessTokens.create({})
|
||||||
|
|
|
@ -26,9 +26,9 @@ module.exports = Self => {
|
||||||
message: 'This locker has already been assigned'
|
message: 'This locker has already been assigned'
|
||||||
});
|
});
|
||||||
|
|
||||||
// Self.validateAsync('fi', tinIsValid, {
|
Self.validateAsync('fi', tinIsValid, {
|
||||||
// message: 'Invalid TIN'
|
message: 'Invalid TIN'
|
||||||
// });
|
});
|
||||||
|
|
||||||
async function tinIsValid(err, done) {
|
async function tinIsValid(err, done) {
|
||||||
const filter = {
|
const filter = {
|
||||||
|
|
Loading…
Reference in New Issue