Пример #1
0
 function actionChangePassword($params = '')
 {
     $this->objAuthentication->requiresAccount();
     $errorMsg = false;
     $changedpassword = false;
     if (!empty($params['changepassword'])) {
         $objUser = new UserModel();
         if (!empty($params['orignal_pw']) && !empty($params['password']) && !empty($params['password2'])) {
             // verify old password
             $passwordMatch = $objUser->testPassword($this->objAuthentication->user_id, $params['orignal_pw']);
             if ($passwordMatch) {
                 $objValidation = new Validator();
                 $objValidation->validatePassword($params['password']);
                 $objValidation->passwordsMatch($params['password'], $params['password2']);
                 if ($objValidation->hasError) {
                     $errorMsg = $objValidation->getError();
                     if (is_array($errorMsg)) {
                         $errorMsg = implode(', ', $errorMsg);
                     }
                 } else {
                     $saveData = array();
                     $saveData['id'] = $this->objAuthentication->user_id;
                     $saveData['password'] = $this->objAuthentication->encryptPassword($params['password']);
                     $changedpassword = $objUser->save($saveData, 'users');
                     if ($changedpassword) {
                         $objEmailer = new EmailSender();
                         $objEmailer->sendUserChangePassword($this->objAuthentication->user_id);
                     } else {
                         $errorMsg = 'Unable to change password.';
                     }
                 }
             } else {
                 $errorMsg = 'Current password incorrect.';
             }
         } else {
             $errorMsg = 'Current password and new password are required.';
         }
     }
     $objLayout = new LayoutModel();
     $objTemplate = new TemplatesModel();
     $layoutInfo = $objLayout->loadLayout();
     $template = $objTemplate->loadTemplateFromKeyname('user-changepassword');
     $this->view->assign('errorMsg', $errorMsg);
     $this->view->assign('changedpassword', $changedpassword);
     $this->view->assign('content', $this->view->fetch('fromstring:' . $template['content']));
     $this->view->assign('sidebar_left', $this->view->fetch('fromstring:' . $template['left_sidebar']));
     $this->view->assign('sidebar_right', $this->view->fetch('fromstring:' . $template['right_sidebar']));
     $this->view->assign('layout', $this->view->fetch('fromstring:' . $layoutInfo['code']));
     $this->finish();
 }