validatePhone($request); // We will send the Disposable Password // to send the Disposable Password , we will examine the response then see the message we // need to show to the user. Finally, we'll send out a proper response. return $this->generateAndSendCode($request); } /** * Check Disposable Password And Login * * @param \Illuminate\Http\Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function checkDisposablePassword(Request $request) { if ( \Cache::has($request->code) ) { $userid = \Cache::pull($request->code); $user = User::where('id', $userid)->first(); if($user) { $password = rand(10000000, 999999999); $user->password = \Hash::make($password); $user->save(); $request->merge([ 'cell_number' => $user->cell_number, 'password' => $password ]); return (new LoginController())->login($request); } return MessageResponse::error('User Not Found'); } return MessageResponse::error('Error'); } protected function generateAndSendCode($request) { $user = User::where('cell_number', $request->cell_number)->where('status', 'Active')->first(); if ($user) { $code = rand(100000, 999999); \Cache::put($code, $user->id, Carbon::now()->addMinutes(30)); SMSSender::instance()->patternSend($request->cell_number, 'jqomyn42wo', ["verification-code" => $code]); return MessageResponse::success('Send Disposable Password'); } return MessageResponse::error('User Not Found'); } /** * Validate the email for the given request. * * @param \Illuminate\Http\Request $request * @return void */ protected function validatePhone(Request $request) { $request->validate(['cell_number' => 'required|digits:11']); } }