Ejemplo n.º 1
0
 /**
  * Display profile start page
  */
 public function actionIndex()
 {
     Yii::import('application.modules.users.forms.ChangePasswordForm');
     $request = Yii::app()->request;
     $user = Yii::app()->user->getModel();
     $profile = $user->profile;
     $changePasswordForm = new ChangePasswordForm();
     $changePasswordForm->user = $user;
     if (Yii::app()->request->isPostRequest) {
         if ($request->getPost('UserProfile') || $request->getPost('User')) {
             $profile->attributes = $request->getPost('UserProfile');
             $user->email = isset($_POST['User']['email']) ? $_POST['User']['email'] : null;
             $valid = $profile->validate();
             $valid = $user->validate() && $valid;
             if ($valid) {
                 $user->save();
                 $profile->save();
                 $this->addFlashMessage(Yii::t('UsersModule.core', 'Изменения успешно сохранены.'));
                 $this->refresh();
             }
         }
         if ($request->getPost('ChangePasswordForm')) {
             $changePasswordForm->attributes = $request->getPost('ChangePasswordForm');
             if ($changePasswordForm->validate()) {
                 $user->password = User::encodePassword($changePasswordForm->new_password);
                 $user->save(false);
                 $this->addFlashMessage(Yii::t('UsersModule.core', 'Пароль успешно изменен.'));
                 $this->refresh();
             }
         }
     }
     $this->render('index', array('user' => $user, 'profile' => $profile, 'changePasswordForm' => $changePasswordForm));
 }
Ejemplo n.º 2
0
 public function run()
 {
     $this->controller->layout = 'admin';
     $form = new ChangePasswordForm();
     if (!empty($_POST['ChangePasswordForm']) && is_array($_POST['ChangePasswordForm'])) {
         $form->attributes = $_POST['ChangePasswordForm'];
         if ($form->validate()) {
             $loggedUser = Yii::app()->user;
             /*
              * Save new password.
              */
             $user = User::model()->findByAttributes(array('username' => $loggedUser->name));
             if ($user === null) {
                 throw new CException('User not found.');
             }
             $user->password = md5($form->newPassword);
             $user->save();
             $loggedUser->setFlash('generalMessage', 'New password was set successfully.');
             $this->controller->refresh();
         } else {
             $form->currentPassword = '';
             $form->newPassword = '';
             $form->newPasswordConfirm = '';
         }
     }
     $this->controller->render('changePassword', array('form' => $form));
 }
 /**
  * Стартуем экшен сброса пароля
  * @param string $token - токен-сброса пароля
  * @throws CHttpException
  */
 public function run($token)
 {
     if (Yii::app()->user->isAuthenticated()) {
         $this->controller->redirect(Yii::app()->user->returnUrl);
     }
     $module = Yii::app()->getModule('user');
     // Если запрещено восстановление - печалька ;)
     if ($module->recoveryDisabled) {
         throw new CHttpException(404, Yii::t('UserModule.user', 'requested page was not found!'));
     }
     // Если включено автоматическое восстановление пароля:
     if ((int) $module->autoRecoveryPassword === WebModule::CHOICE_YES) {
         if (Yii::app()->userManager->activatePassword($token)) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'New password was sent to your email'));
             $this->controller->redirect(array('/user/account/backendlogin'));
         } else {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'Error when changing password!'));
             $this->controller->redirect(array('/user/account/recovery'));
         }
     }
     // Форма смены пароля:
     $changePasswordForm = new ChangePasswordForm();
     // Получаем данные POST если таковые имеются:
     if (($data = Yii::app()->getRequest()->getPost('ChangePasswordForm')) !== null) {
         $changePasswordForm->setAttributes($data);
         // Проводим валидацию формы:
         if ($changePasswordForm->validate() && Yii::app()->userManager->activatePassword($token, $changePasswordForm->password)) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Password recover successfully'));
             $this->controller->redirect(array('/user/account/backendlogin'));
         }
     }
     // Отрисовываем форму:
     $this->controller->render('changePassword', array('model' => $changePasswordForm));
 }
Ejemplo n.º 4
0
 public function run($code)
 {
     $recovery = RecoveryPassword::model()->with('user')->find('code = :code', array(':code' => $code));
     if (!$recovery) {
         Yii::log(Yii::t('user', 'Код восстановления пароля {code} не найден!', array('{code}' => $code)), CLogger::LEVEL_ERROR, UserModule::$logCategory);
         Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('user', 'Код восстановления пароля не найден! Попробуйте еще раз!'));
         $this->controller->redirect(array('/user/account/recovery'));
     }
     // автоматическое восстановление пароля
     if (Yii::app()->getModule('user')->autoRecoveryPassword) {
         $newPassword = Registration::model()->generateRandomPassword();
         $recovery->user->password = Registration::model()->hashPassword($newPassword, $recovery->user->salt);
         $transaction = Yii::app()->db->beginTransaction();
         try {
             if ($recovery->user->save() && RecoveryPassword::model()->deleteAll('user_id = :user_id', array(':user_id' => $recovery->user->id))) {
                 $transaction->commit();
                 $emailBody = $this->controller->renderPartial('application.modules.user.views.email.passwordAutoRecoverySuccessEmail', array('model' => $recovery->user, 'password' => $newPassword), true);
                 Yii::app()->mail->send(Yii::app()->getModule('user')->notifyEmailFrom, $recovery->user->email, Yii::t('user', 'Успешное восстановление пароля!'), $emailBody);
                 Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('user', 'Новый пароль отправлен Вам на email!'));
                 Yii::log(Yii::t('user', 'Успешное восстановление пароля!'), CLogger::LEVEL_ERROR, UserModule::$logCategory);
                 $this->controller->redirect(array('/user/account/login'));
             }
         } catch (CDbException $e) {
             $transaction->rollback();
             Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('user', 'Ошибка при смене пароля!'));
             Yii::log(Yii::t('user', 'Ошибка при автоматической смене пароля {error}!', array('{error}' => $e->getMessage())), CLogger::LEVEL_ERROR, UserModule::$logCategory);
             $this->controller->redirect(array('/user/account/recovery'));
         }
     }
     // выбор своего пароля
     $changePasswordForm = new ChangePasswordForm();
     // если отправили фому с новым паролем
     if (Yii::app()->request->isPostRequest && isset($_POST['ChangePasswordForm'])) {
         $changePasswordForm->setAttributes($_POST['ChangePasswordForm']);
         if ($changePasswordForm->validate()) {
             $transaction = Yii::app()->db->beginTransaction();
             try {
                 // смена пароля пользователя
                 $recovery->user->password = Registration::model()->hashPassword($changePasswordForm->password, $recovery->user->salt);
                 // удалить все запросы на восстановление для данного пользователя
                 if ($recovery->user->save() && RecoveryPassword::model()->deleteAll('user_id = :user_id', array(':user_id' => $recovery->user->id))) {
                     $transaction->commit();
                     Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('user', 'Пароль изменен!'));
                     Yii::log(Yii::t('user', 'Успешная смена пароля для пользоателя {user}!', array('{user}' => $recovery->user->id)), CLogger::LEVEL_INFO, UserModule::$logCategory);
                     $emailBody = $this->controller->renderPartial('application.modules.user.views.email.passwordRecoverySuccessEmail', array('model' => $recovery->user), true);
                     Yii::app()->mail->send(Yii::app()->getModule('user')->notifyEmailFrom, $recovery->user->email, Yii::t('user', 'Успешное восстановление пароля!'), $emailBody);
                     $this->controller->redirect(array('/user/account/login'));
                 }
             } catch (CDbException $e) {
                 $transaction->rollback();
                 Yii::app()->user->setFlash(YFlashMessages::ERROR_MESSAGE, Yii::t('user', 'Ошибка при смене пароля!'));
                 Yii::log(Yii::t('Ошибка при смене пароля {error}!', array('{error}' => $e->getMessage())), CLogger::LEVEL_ERROR, UserModule::$logCategory);
                 $this->controller->redirect(array('/user/account/recovery'));
             }
         }
     }
     $this->controller->render('changePassword', array('model' => $changePasswordForm));
 }
 /**
  * Экшен смены пароля:
  *
  * @param int $id - record ID
  * 
  * @return void
  */
 public function actionChangepassword($id)
 {
     $model = $this->loadModel($id);
     $form = new ChangePasswordForm();
     if (($data = Yii::app()->getRequest()->getPost('ChangePasswordForm')) !== null) {
         $form->setAttributes($data);
         if ($form->validate() && Yii::app()->userManager->changeUserPassword($model, $form->password)) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Пароль успешно изменен!'));
             $this->redirect(Yii::app()->user->getState('prevUrl'));
         }
     }
     $this->render('changepassword', array('model' => $model, 'changePasswordForm' => $form));
 }
Ejemplo n.º 6
0
 /**
  * Экшен смены пароля:
  *
  * @param int $id - record ID
  *
  * @return void
  */
 public function actionChangepassword($id)
 {
     $model = $this->loadModel($id);
     $form = new ChangePasswordForm();
     if (($data = Yii::app()->getRequest()->getPost('ChangePasswordForm')) !== null) {
         $form->setAttributes($data);
         if ($form->validate() && Yii::app()->userManager->changeUserPassword($model, $form->password)) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Password was changed successfully'));
             $this->redirect(array('/user/userBackend/view', 'id' => $model->id));
         }
     }
     $this->render('changepassword', array('model' => $model, 'changePasswordForm' => $form));
 }
Ejemplo n.º 7
0
 /**
  * Provides ability to change password and email address.
  * If user want to change email it will be changed after confirmation of
  * new email address.
  * 
  * @throws CException
  */
 public function actionEdit()
 {
     $identity = Identity::model()->findByAttributes(array('user_id' => Yii::app()->user->id));
     $newPassword = new ChangePasswordForm();
     if ($this->request->isPostRequest) {
         if ($identity->identity !== $_POST['Identity']['identity']) {
             $newEmail = $_POST['Identity']['identity'];
             $storedIdentity = clone $identity;
             $identity->identity = $newEmail;
         }
         $newPassword->attributes = $_POST['ChangePasswordForm'];
         $isFormValid = $newPassword->validate();
         if ($isFormValid && $newEmail) {
             $isFormValid = $identity->validate();
         }
         if ($isFormValid && isset($newEmail)) {
             $identity->status = Identity::STATUS_NEED_CONFIRMATION;
             $identity->isNewRecord = true;
             $identity->id = null;
             $identity->save();
             $confirmation = $identity->startConfirmation(IdentityConfirmation::TYPE_EMAIL_REPLACE_CONFIRMATION);
             $activationUrl = $this->createAbsoluteUrl($this->module->confirmationUrl, array('key' => $confirmation->key));
             $email = new YiiMailer('changeEmail', $data = array('activationUrl' => $activationUrl, 'description' => $description = 'Email change confirmation'));
             $email->setSubject($description);
             $email->setTo($identity->identity);
             $email->setFrom(Yii::app()->params['noreplyAddress'], Yii::app()->name, FALSE);
             Yii::log('Sendign email change confirmation to ' . $identity->identity . ' with data: ' . var_export($data, true));
             // @TODO: catch mailing exceptions here, to give user right messages
             if ($email->send()) {
                 Yii::log('Ok');
             } else {
                 Yii::log('Failed');
                 throw new CException('Failed to send the email');
             }
             Yii::app()->user->setFlash('info', 'Your new email will be applied after confirmation. Please, check this email address ' . $newEmail . '. You should get confirmation mail there.');
         }
         if ($isFormValid) {
             $user = $identity->userAccount;
             if ($newPassword->password && !$user->passwordEquals($newPassword->password)) {
                 $user->setPassword($newPassword->password);
                 $user->save();
                 Yii::app()->user->setFlash('success', 'Password has been changed successfully');
             }
         }
         if ($isFormValid) {
             $this->redirect(array($this->module->afterIdentityEditedUrl));
         }
     }
     $this->render('edit', array('identity' => $identity, 'newPassword' => $newPassword));
 }
 public function run()
 {
     $formModel = new ChangePasswordForm();
     if (isset($_POST['ChangePasswordForm'])) {
         $formModel->attributes = $_POST['ChangePasswordForm'];
         if ($formModel->validate()) {
             $user = User::model()->findByPk(Yii::app()->user->getId());
             $user->password = md5($formModel->password);
             $user->save(false);
             Utility::setFlash('Password changed successfully.', 'success');
         }
     }
     $this->getController()->render('change_password', array('formModel' => $formModel));
 }
Ejemplo n.º 9
0
 public function actionChangepassword($id)
 {
     $model = $this->loadModel();
     $form = new ChangePasswordForm();
     if (Yii::app()->request->isPostRequest && !empty($_POST['ChangePasswordForm'])) {
         $form->setAttributes($_POST['ChangePasswordForm']);
         if ($form->validate() && $model->changePassword($form->password)) {
             $model->changePassword($form->password);
             Yii::app()->user->setFlash(YFlashMessages::NOTICE_MESSAGE, Yii::t('user', 'Пароль успешно изменен!'));
             $this->redirect(array('/user/default/view/', 'id' => $model->id));
         }
     }
     $this->render('changepassword', array('model' => $model, 'changePasswordForm' => $form));
 }
Ejemplo n.º 10
0
 public function actionIndex()
 {
     $model = new ChangePasswordForm();
     if (isset($_POST['ChangePasswordForm'])) {
         $model->setAttributes($_POST['ChangePasswordForm']);
         if ($model->validate()) {
             if ($model->changePassword()) {
                 user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'Пароль успешно изменен.'));
                 $this->refresh();
             } else {
                 user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Произошла ошибка! Попробуйте повторить позже.'));
             }
         }
     }
     $this->render('//cabinet/change-password', array('model' => $model));
 }
Ejemplo n.º 11
0
 /**
  * Action ChangePassword dùng để đổi mật khẩu cho user khi user quên mật khẩu với điều kiện user click url được gửi trong email
  */
 public function actionChangePassword()
 {
     // Validate Code forgot password
     if (isset($_GET['code']) && isset($_GET['email'])) {
         $strForgotPasswordCode = $_GET['code'];
         $strEmail = $_GET['email'];
         $user = User::model()->notsafe()->findByAttributes(array('email' => $strEmail));
         if (isset($user)) {
             // Check Code
             if ($strForgotPasswordCode == $user->activkey) {
                 $model = new ChangePasswordForm();
                 // Submit form
                 if (isset($_POST['ChangePasswordForm'])) {
                     $model->attributes = $_POST['ChangePasswordForm'];
                     // Validate new password
                     if ($model->validate()) {
                         // Create new Pasword
                         $user->encryptPassword($model->password);
                         // Delete forgot code in DB
                         $user->activkey = $user->createCodeActivation();
                         // Save new password to DB
                         if ($user->save()) {
                         }
                         /**
                          * @todo Change message email
                          */
                         $strMsgHTML = "Recovery Password Success";
                         Yii::import('application.extensions.phpmailer.HMailHelper');
                         HMailHelper::Send('Recovery Password', $strMsgHTML, array(array($user->email, $user->username)));
                         // Notice Recovery Password success
                         $this->setRedirectOptions(array("title" => UserModule::t('Recovery Password Success'), "message" => UserModule::t('The recovery password was successful!')));
                         $this->redirect(Yii::app()->user->loginUrl);
                     }
                 }
                 $this->render('changepassword', array('model' => $model));
                 Yii::app()->end();
             } else {
                 // Notice recovery password failure
                 $this->setRedirectOptions(array("title" => UserModule::t('Recovery Password Failure'), "message" => UserModule::t('Incorrect recovery URL or Recovery period has expired!')));
                 $this->redirect("/");
             }
         }
     }
     // Notice recovery password failure
     $this->setRedirectOptions(array("title" => UserModule::t('Recovery Password Failure'), "message" => UserModule::t('Incorrect recovery URL!')));
     $this->redirect("/");
 }
 public function actionChangePassword()
 {
     $model = new ChangePasswordForm();
     if (isset($_POST['ChangePasswordForm'])) {
         $model->attributes = $_POST['ChangePasswordForm'];
         if ($model->validate()) {
             //change password
             $user = User::model()->findByPk(Yii::app()->user->id);
             $user->password = $user->createHash($model->password);
             $user->save();
             //inform user
             $this->render('message', array('title' => 'Password Changed', 'message' => 'You have successfully changed your password.'));
             return;
         }
     }
     $this->render('changePassword', array('model' => $model));
 }
Ejemplo n.º 13
0
 public function actionPassword()
 {
     $data = array();
     $form = new ChangePasswordForm();
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $form->attributes = $_POST['ChangePasswordForm'];
         if ($form->validate()) {
             $uid = Yii::app()->session['user']['id'];
             $query = "UPDATE {{users}} SET password = :password WHERE id = " . $uid;
             $this->db->createCommand($query)->bindValues(array(':password' => md5($form->password)))->execute();
             Yii::app()->session['user']['password'] = md5($form->password);
             createMessage('Thay đổi mật khẩu thành công');
             $this->redirect($this->createUrl('password'));
         }
     }
     $data['form'] = $form;
     $this->render('password', array('data' => $data));
 }
 /**
  * Updates a password
  */
 public function actionChangePassword()
 {
     $model = new ChangePasswordForm();
     if (isset($_POST['ChangePasswordForm'])) {
         $model->attributes = $_POST['ChangePasswordForm'];
         if ($model->validate()) {
             // Change the password
             $user = $this->loadModel(Yii::app()->user->id);
             $user->password = $model->newPassword;
             $user->save();
             // Log and inform
             $this->log('"%s" updated his/her password', Yii::app()->user->name);
             Yii::app()->user->setFlash('success', Yii::t('User', 'Password successfully changed'));
             $this->redirect(array('movie/index'));
         }
     }
     $this->render('changePassword', array('model' => $model));
 }
 /**
  * Стартуем экшен сброса пароля
  * @param string $token - токен-сброса пароля
  * @throws CHttpException
  */
 public function run($token)
 {
     if (Yii::app()->user->isAuthenticated()) {
         $this->controller->redirect(Yii::app()->user->returnUrl);
     }
     $module = Yii::app()->getModule('user');
     // Если запрещено восстановление - печалька ;)
     if ($module->recoveryDisabled) {
         throw new CHttpException(404);
     }
     //Проверка токена
     $tokenModel = Yii::app()->userManager->tokenStorage->get($token, UserToken::TYPE_CHANGE_PASSWORD);
     if (null === $tokenModel) {
         throw new CHttpException(404);
     }
     // Если включено автоматическое восстановление пароля:
     if ((int) $module->autoRecoveryPassword === WebModule::CHOICE_YES) {
         if (Yii::app()->userManager->activatePassword($token, null, true)) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Пароль отправлен на ваш E-mail'));
             $this->controller->redirect(array('/user/account/login'));
         } else {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::ERROR_MESSAGE, Yii::t('UserModule.user', 'Ошибка восстановления пароля!'));
             $this->controller->redirect(array('/user/account/recovery'));
         }
     }
     // Форма смены пароля:
     $changePasswordForm = new ChangePasswordForm();
     // Получаем данные POST если таковые имеются:
     if (($data = Yii::app()->getRequest()->getPost('ChangePasswordForm')) !== null) {
         $changePasswordForm->setAttributes($data);
         // Проводим валидацию формы:
         if ($changePasswordForm->validate() && Yii::app()->userManager->activatePassword($token, $changePasswordForm->password, false)) {
             Yii::app()->user->setFlash(yupe\widgets\YFlashMessages::SUCCESS_MESSAGE, Yii::t('UserModule.user', 'Пароль успешно изменен'));
             $this->controller->redirect(array('/user/account/login'));
         }
     }
     // Отрисовываем форму:
     $this->controller->render('changePassword', array('model' => $changePasswordForm));
 }
Ejemplo n.º 16
0
 /**
  * Action ChangePassword dùng để đổi mật khẩu của user
  */
 public function actionChangePassword()
 {
     $model = new ChangePasswordForm('fullchange');
     // Submit form
     if (isset($_POST['ChangePasswordForm'])) {
         $user = User::model()->notsafe()->findByPk(Yii::app()->user->id);
         $model->user = $user;
         $model->attributes = $_POST['ChangePasswordForm'];
         // Validate info
         if ($model->validate()) {
             // Save new password
             $user->encryptPassword($model->password);
             // Save new password to DB
             if ($user->save()) {
                 // Notice Recovery Password success
                 $this->setRedirectOptions(array("title" => UserModule::t('Change Password Success'), "message" => UserModule::t('The change password was successful!')));
                 $this->redirect('/user/profile');
             }
         }
     }
     $this->render('changepassword', array('model' => $model));
 }
Ejemplo n.º 17
0
 /**
  * Save user's new password.
  * @param $args array
  * @param $request PKPRequest
  */
 function savePassword($args, &$request)
 {
     $this->validate();
     import('classes.user.form.ChangePasswordForm');
     if (checkPhpVersion('5.0.0')) {
         // WARNING: This form needs $this in constructor
         $passwordForm = new ChangePasswordForm();
     } else {
         $passwordForm =& new ChangePasswordForm();
     }
     $passwordForm->readInputData();
     $this->setupTemplate($request, true);
     if ($passwordForm->validate()) {
         $passwordForm->execute();
         $request->redirect(null, $request->getRequestedPage());
     } else {
         $passwordForm->display();
     }
 }
Ejemplo n.º 18
0
 public function actionPassword()
 {
     $model = new ChangePasswordForm();
     $model->id = Yii::app()->user->id;
     if (isset($_POST) && isset($_POST['ChangePasswordForm'])) {
         $model->attributes = $_POST['ChangePasswordForm'];
         if ($model->validate()) {
             // Generate Password here and redirect
             $tempPass = $model->newPassword;
             $user = UserCredentials::model()->findByPk(Yii::app()->user->id);
             if ($user) {
                 $user->salt = SecurityUtils::generateSalt($user->email_id);
                 $user->password = SecurityUtils::encryptPassword($tempPass, $user->salt);
                 if ($user->save()) {
                     Yii::app()->user->setFlash('success', "Your password has been modified.");
                     $this->redirect('/dashboard');
                 }
             }
         }
     }
     $this->render('password', array('model' => $model));
 }
Ejemplo n.º 19
0
 public function actionChangePassword()
 {
     if (Yii::app()->user->isGuest) {
         Yii::app()->request->redirect(basePath(''));
     }
     //do validation
     $model = new ChangePasswordForm();
     $model->setAttributes(array('password_change' => $_POST['password_change'], 'password_new' => $_POST['password_new'], 'password_new_confirm' => $_POST['password_new_confirm']));
     $model->validate();
     $errors = $model->getErrors();
     if (count($errors) != 0) {
         Yii::app()->user->setFlash('changepassworderror', true);
         foreach ($errors as $key => $value) {
             Yii::app()->user->setFlash($key, $value);
         }
         Yii::app()->request->redirect(basePath('app/myprofile'));
         return;
     }
     $user = User::model()->findByPk(Yii::app()->user->getState('id'));
     if ($user->password != $_POST['password_change']) {
         Yii::app()->user->setFlash('password_change', array('0' => 'Invalid password'));
         Yii::app()->request->redirect(basePath('app/myprofile'));
         return;
     }
     //update user's email
     $user->password = $model->password_new;
     $user->update();
     //update session state
     $userControl = new userControl();
     $userControl->update();
     //redirect user to my profile page
     Yii::app()->request->redirect(basePath('app/properties'));
 }
Ejemplo n.º 20
0
 /**
  * Display profile start page
  */
 public function actionIndex()
 {
     if (!Yii::app()->user->isGuest) {
         $this->pageName = Yii::t('UsersModule.default', 'PROFILE');
         $this->pageTitle = $this->pageName;
         $this->breadcrumbs = array($this->pageName);
         Yii::import('mod.users.forms.ChangePasswordForm');
         $request = Yii::app()->request;
         $user = Yii::app()->user->getModel();
         //  if(!isset($user->service)){
         $oldAvatar = $user->avatar;
         $changePasswordForm = new ChangePasswordForm();
         $changePasswordForm->user = $user;
         if (isset($_POST['User'])) {
             $user->attributes = $_POST['User'];
             //$user->email = isset($_POST['User']['email']) ? $_POST['User']['email'] : null;
             if ($user->validate()) {
                 /* $file = CUploadedFile::getInstance($user, 'avatar');
                    if (isset($file) && !empty($file)) {
                    var_dump($file);
                    $path = Yii::getPathOfAlias('webroot.uploads.users.avatar');
                    if (isset($oldAvatar) && file_exists($path . DS . $oldAvatar)) {
                    unlink($path . DS . $oldAvatar);
                    }
                    $newFile = time() . "." . $file->getExtensionName();
                    Yii::app()->img
                    ->load($file->tempName)
                    ->thumb(100, 100)
                    ->save($path . DS . $newFile, false, 100);
                    $user->avatar = $newFile;
                    }else{
                    $user->avatar = $oldAvatar;
                    } */
                 $user->uploadFile('avatar', 'webroot.uploads.users.avatar', $oldAvatar);
                 $user->save();
                 // $this->refresh();
             }
         }
         if ($request->getPost('ChangePasswordForm')) {
             $changePasswordForm->attributes = $request->getPost('ChangePasswordForm');
             if ($changePasswordForm->validate()) {
                 $user->password = User::encodePassword($changePasswordForm->new_password);
                 if ($user->save(false, false, false)) {
                     $forum = new CIntegrationForums();
                     $forum->changepassword($user->login, $changePasswordForm->new_password, $user->email);
                 }
                 $this->addFlashMessage(Yii::t('UsersModule.default', 'Пароль успешно изменен.'));
                 $this->redirect('post/read', array('#' => 'chagepass'));
             }
         }
         $uConfig = Yii::app()->settings->get('users');
         $tabsArray = array(Yii::t('UsersModule.default', 'PROFILE') => array('content' => $this->renderPartial('_profile', array('user' => $user), true), 'id' => 'profile', 'visible' => true), Yii::t('UsersModule.default', 'CHANGE_PASSWORD') => array('content' => $this->renderPartial('_changepass', array('changePasswordForm' => $changePasswordForm), true), 'id' => 'changepass', 'visible' => true), Yii::t('UsersModule.default', 'FAVORITES') => array('ajax' => $this->createAbsoluteUrl('favorites/index'), 'id' => 'favorites', 'visible' => $uConfig['favorites'] && false));
         $tabs = array();
         foreach ($tabsArray as $k => $tab) {
             if ($tabsArray[$k]['visible']) {
                 $tabs[$k] = $tabsArray[$k];
             }
         }
         $this->render('index', array('user' => $user, 'tabs' => $tabs, 'changePasswordForm' => $changePasswordForm));
     } else {
         $this->redirect(Yii::app()->user->returnUrl);
     }
 }
Ejemplo n.º 21
0
 /**
  * Save user's new password.
  * @param $args array
  * @param $request PKPRequest
  * @return JSONMessage JSON-formatted response
  */
 function savePassword($args, $request)
 {
     $this->setupTemplate($request);
     import('lib.pkp.classes.user.form.ChangePasswordForm');
     $passwordForm = new ChangePasswordForm($request->getUser(), $request->getSite());
     $passwordForm->readInputData();
     if ($passwordForm->validate()) {
         $passwordForm->execute($request);
         return new JSONMessage(true);
     }
     return new JSONMessage(true, $passwordForm->fetch($request));
 }
Ejemplo n.º 22
0
 public function actionChangePassword($changePasswordCode)
 {
     $this->layout = "tplLogin";
     $message = '';
     $model = new ChangePasswordForm();
     $idusers = 0;
     $aux = 0;
     try {
         $idusers = UsersDao::getInstance()->validChangeCodeInDataBase($changePasswordCode);
         if (isset($_POST['ChangePasswordForm'])) {
             $model->attributes = $_POST['ChangePasswordForm'];
             if ($model->validate()) {
                 self::serverValidationChangePasswordForm($model);
                 UsersDao::getInstance()->updatePasswordForUser($model->password, $idusers);
                 $this->redirect('index.php?r=site/login');
             }
         }
     } catch (Exception $e) {
         //Yii::log("Entre a la expetion: ".$e->getMessage(),"warning");
         Yii::app()->user->setFlash('enter', $e->getMessage());
         //$this->refresh();
     }
     $this->render('changePassword', array('model' => $model, "errorSummary" => $message));
 }
Ejemplo n.º 23
0
 /**
  * Changes the user's current password with the new one
  */
 public function actionChangePassword()
 {
     $model = new ChangePasswordForm();
     $processOutput = true;
     // collect user input data
     if (isset($_POST['ChangePasswordForm'])) {
         $model->attributes = $_POST['ChangePasswordForm'];
         // validate user input and if ok return json data and end application.
         if ($model->validate()) {
             //$users=Users::model()->findByPk(Yii::app()->user->id);
             //$users->password=md5($model->newPassword);
             //if($users->save()) // save the change to database
             if (Users::model()->updateByPk(Yii::app()->user->id, array("password" => md5($model->newPassword)))) {
                 echo CJSON::encode(array("result" => "1"));
             } else {
                 echo CJSON::encode(array("result" => "0"));
             }
             Yii::app()->end();
         }
         if (Yii::app()->request->isAjaxRequest) {
             $processOutput = false;
         }
     }
     Yii::app()->clientScript->scriptMap['jquery.js'] = false;
     Yii::app()->clientScript->scriptMap['jquery-ui.min.js'] = false;
     $this->renderPartial('changePassword', array('model' => $model), false, $processOutput);
 }
Ejemplo n.º 24
0
 /**
  * Save user's new password.
  */
 function savePassword($args, $request)
 {
     $this->setupTemplate($request, true);
     $user = $request->getUser();
     $site = $request->getSite();
     import('lib.pkp.classes.user.form.ChangePasswordForm');
     $passwordForm = new ChangePasswordForm($user, $site);
     $passwordForm->readInputData();
     $this->setupTemplate($request, true);
     if ($passwordForm->validate()) {
         $passwordForm->execute($request);
         $request->redirect(null, $request->getRequestedPage());
     } else {
         $passwordForm->display($args, $request);
     }
 }