Example #1
0
 private function resetSms()
 {
     $token = ResetPassword::where('mobile', '=', $this->mobile)->where('active', '=', 1)->first();
     if (!empty($token->id)) {
         $token->active = 0;
         $token->save();
     }
     $newToken = rand(100000, 999999);
     $resetPasswd = new ResetPassword();
     $resetPasswd->mobile = $this->mobile;
     $resetPasswd->token = $newToken;
     $resetPasswd->deliver_at = date('Y-m-d H:i:s');
     $res = $resetPasswd->save();
     if ($res) {
         $post_data = array('appid' => $this->appid, 'signature' => $this->signature, 'project' => $this->pro_reset, 'vars' => "{ \"token\": \"{$resetPasswd->token}\"}", 'to' => $this->mobile);
         return $this->send('post', $this->mobile, $post_data);
     }
     return null;
 }
 /**
  * Сброс пароля через электронную
  * почту
  *
  * @param $token
  * @param $password
  * @return \yii\web\Response
  * @throws BadRequestHttpException
  */
 public function actionReset($token, $password)
 {
     try {
         $model = new ResetPassword($token, $password);
     } catch (InvalidParamException $e) {
         throw new BadRequestHttpException($e->getMessage());
     }
     if ($user_id = $model->resetPassword()) {
         Yii::$app->user->login(User::findIdentity($user_id));
     }
     return $this->redirect(['/']);
 }
Example #3
0
 public function actionResetPassword()
 {
     $model = new ResetPassword();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         if (ResetPassword::isEmail($model->email)) {
             $pass = User::getPasswordByEmail($model->email);
             $hash = $model->email;
             for ($i = 0; $i < 13; ++$i) {
                 $hash = sha1(md5($hash) . $model->email . $pass . sha1($model->email));
             }
             $id = User::getIdByEmail($model->email);
             $text = '<a href="http://fotonastiya.com/reset/' . $id . '/' . $hash . '">Відновити пароль</a>';
             Yii::$app->mailer->compose()->setFrom('*****@*****.**')->setTo($model->email)->setSubject('register')->setTextBody($text)->setHtmlBody($text)->send();
             return $this->render('success-resed-p');
         } else {
             $model->addError('email', 'Користувача з даним email не знайдено');
         }
     }
     return $this->render('reset_password', ['model' => $model]);
 }
Example #4
0
  public function postPasswdreset(Request $request) 
  {
    $user = User::where('mobile', '=', $request->input('mobile'))->first();

    if (empty($user->id)) {

      if (!empty($request->input('mb'))) {
      
      
      } else {

        return redirect('/user/password');

      }

    }

    $validate = Validator::make($request->input(), [
    
      'reset_code' => 'required',

      'newpassword' => 'required|min:6|max:18',

      'confirmpassword' => 'required|min:6|max:18',
    
    ]); 

    if ($validate->fails()) {

      $failed = $validate->failed();

      return $this->failResponse($failed);

    }

    $inputs = $request->input();

    $rp = ResetPassword::where('token', '=', $inputs['reset_code'])

      ->where('active', '=', 1)

      ->first();

    if (empty($rp->id)) {

      return $this->failResponse([ 'reset_code' => 'not_found' ]);

    }

    if ($inputs['newpassword'] != $inputs['confirmpassword']) {

      return $this->failResponse('not_match');

    }

    $rp->active = 0;

    $rp->status = 1;

    $rp->save();

    $user->password = bcrypt($inputs['newpassword']);
  
    $res = $user->save();

    if ($res) {

      return $this->successResponse();

    } else {

      return $this->failResponse('save_failed');

    }
  
  }