public function postChangePassword() { $post = Input::all(); $validator = User::validateChangePassword($post); if ($validator->fails()) { return Redirect::to('cambiarContrasena')->withErrors($validator)->withInput(); } else { if (!Hash::check($post['current_pass'], Auth::user()->password)) { Session::flash('error', 'La contraseƱa actual es incorrecta'); return Redirect::to('cambiarContrasena'); } else { $user = Auth::user(); $user->password = Hash::make($post['password']); $user->password_changed = true; $user->save(); return Redirect::to('/'); } } }
public function actionUpdate2($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); //if($model->password== md5($_POST['User']->oldpassword)){ if (isset($_POST['User'])) { if ($model->comparePassword($_POST['oldpw'])) { if (User::validateChangePassword($_POST['password'], $_POST['repassword'])) { $model->attributes = $_POST['User']; $model->password = MD5($_POST['password']); if ($model->save()) { $this->redirect(array('/site/index')); } } else { Yii::app()->user->setFlash('errorPassword', "Type correctly the new password"); } } else { Yii::app()->user->setFlash('errorPassword', "Re-check your current password"); } } /* } else{ $this->render('update2', array( 'model' => $model, )); }*/ $this->render('update2', array('model' => $model)); }