Example #1
0
 /**
  * Updates the user profile from a form
  */
 public function actionProfile()
 {
     if (Pii::guest()) {
         $this->_redirectError('You must be logged in to change your profile.');
     }
     $_model = new ProfileForm();
     if (isset($_POST, $_POST['ProfileForm'])) {
         $_model->attributes = $_POST['ProfileForm'];
         if ($_model->validate()) {
             try {
                 $_userId = Session::getCurrentUserId();
                 $_result = Profile::changeProfile($_userId, $_model->attributes);
                 if (Option::getBool($_result, 'success')) {
                     Yii::app()->user->setFlash('profile-form', 'Your profile has been successfully updated.');
                 }
             } catch (\Exception $_ex) {
                 $_model->addError(null, $_ex->getMessage());
             }
         }
     } else {
         $_userId = Session::getCurrentUserId();
         $_model->attributes = Profile::getProfile($_userId);
     }
     $this->render('profile', array('model' => $_model, 'backUrl' => $this->_getRedirectUrl(), 'session' => Session::generateSessionDataFromUser(Session::getCurrentUserId())));
 }