示例#1
0
 public function resetPassword()
 {
     $this->_methodName = 'checkToken';
     $this->resolveParams();
     if (isset($this->_request_params['reset_code'])) {
         $arNeed = ['reset_code' => 'required'];
         $this->checkAttr($arNeed);
         $reg_user = \App\Users::whereReset_code($this->_request_params['reset_code'])->first();
         if (is_null($reg_user)) {
             throw new \App\Exceptions\ExceptionApiUserNotFound($this->_request_params, $this->_typeName, $this->_methodName);
         }
         $password = $this->generateCode(8);
         $reg_user->password = Hash::make($password);
         $this->_email = $reg_user->email;
         $reg_user->reset_code = "";
         $reg_user->save();
         Mail::send('mail.welcome', ['data' => ['email' => $reg_user->email, 'password' => $password]], function ($message) {
             $message->to($this->_email)->subject('Добро пожаловать!');
         });
         return $this;
     } else {
         $arNeed = ['email' => 'required|email'];
         $this->checkAttr($arNeed);
         $reg_user = \App\Users::whereEmail($this->_request_params['email'])->first();
         if (is_null($reg_user)) {
             throw new \App\Exceptions\ExceptionApiUserNotFound($this->_request_params, $this->_typeName, $this->_methodName);
         }
         $reg_user->reset_code = Hash::make(time() . $reg_user->email);
         $this->_email = $reg_user->email;
         $reg_user->save();
         Mail::send('mail.resetPassword', ["data" => ["code" => $reg_user->reset_code]], function ($message) {
             $message->to($this->_email)->subject('Сброс пароля');
         });
         return $this;
     }
 }