server/api/integrations/integrations.controller.js
/**
 * Attempt to verify a user's phone number with the verification code.
 *
 * @param {Koa context} ctx
 */
Attempt to verify a user's phone number with the verification code.
@param {Koa context} ctx
Attempt to verify a user ' s phone number with the verification code . @param { Koa context } ctx
async function verifySMS (ctx) {
  const code = ctx.request.body.verificationCode;
  if (!code) {
    logger.error(
      `Failed to verify SMS for ${
        ctx.state.user.rcs_id
      }: Request body missing verificationCode.`
    );
    return ctx.badRequest('You did not enter the verification code!');
  }
  if (ctx.state.user.integrations.sms.verificationCode !== code) {
    logger.error(
      `Failed to verify SMS for ${
        ctx.state.user.rcs_id
      }: Incorrect verification code.`
    );
    return ctx.unauthorized('Incorrect verification code.');
  }
  ctx.state.user.integrations.sms.verificationCode = undefined;
  ctx.state.user.integrations.sms.verified = true;
  ctx.state.user.setup.integrations = true;
  try {
    await ctx.state.user.save();
  } catch (e) {
    logger.error(
      `Failed to verify phone number of ${ctx.state.user.rcs_id}: ${e}`
    );
    return ctx.badRequest('There was an error verifying your phone number.');
  }
  ctx.ok({ updatedUser: ctx.state.user });
}
async function verifySMS ( ctx ) { const code = ctx . request . body . verificationCode ; if ( ! code ) { logger . error ( ` ${ ctx . state . user . rcs_id } ` ) ; return ctx . badRequest ( 'You did not enter the verification code!' ) ; } if ( ctx . state . user . integrations . sms . verificationCode !== code ) { logger . error ( ` ${ ctx . state . user . rcs_id } ` ) ; return ctx . unauthorized ( 'Incorrect verification code.' ) ; } ctx . state . user . integrations . sms . verificationCode = undefined ; ctx . state . user . integrations . sms . verified = true ; ctx . state . user . setup . integrations = true ; try { await ctx . state . user . save ( ) ; } catch ( e ) { logger . error ( ` ${ ctx . state . user . rcs_id } ${ e } ` ) ; return ctx . badRequest ( 'There was an error verifying your phone number.' ) ; } ctx . ok ( { updatedUser : ctx . state . user } ) ; }
Attempt to verify a user's phone number with the verification code.
Attempt to verify a user ' s phone number with the verification code .