/** * @param Request $request * @param VerificationRepository $repository * @return Response */ public function send(Request $request, VerificationRepository $repository) { $validator = Validator::make($request->all(), Verification::$rules); if ($validator->fails()) { return $this->respondWithErrorMessage($validator); } $verification = $repository->findWithAttributes(['phone_number' => $request->input('phone_number'), 'client_user_id' => $request->input('client_user_id')]); $repository->setAwaitingVerificationStatus($verification); $this->dispatch(new SendCodeJob($verification)); return $this->respondWithSuccessCodeSent($verification); }
/** * @param Request $request * @param VerificationRepository $repository * @return Response */ public function verify(Request $request, VerificationRepository $repository) { $validator = Validator::make($request->all(), array_merge(Verification::$rules, Code::$rules)); if ($validator->fails()) { return $this->respondWithErrorMessage($validator); } $phoneNumber = $request->input('phone_number'); $clientUserId = $request->input('client_user_id'); $verification = $repository->findWithAttributes(['phone_number' => $phoneNumber, 'client_user_id' => $clientUserId]); $isValidCode = $repository->isValidCode($verification, $request->input('code')); if ($isValidCode) { $verification->verification_status = 'verified'; $verification->save(); return $this->respondWithVerified($phoneNumber, $clientUserId); } return $this->respondWithNotVerified($phoneNumber, $clientUserId); }