Example #1
0
 /**
  * Profile edit action
  * @param int $id
  * @return string
  * @throws \Ffcms\Core\Exception\SyntaxException
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws NotFoundException
  */
 public function actionUpdate($id)
 {
     if (!Obj::isLikeInt($id) || $id < 1) {
         throw new NotFoundException();
     }
     // get user profile via id
     $profile = ProfileRecords::find($id);
     if (false === $profile || null === $profile) {
         throw new NotFoundException();
     }
     // check if user id for this profile_id is exist
     if (!App::$User->isExist($profile->user_id)) {
         throw new NotFoundException();
     }
     // get user object from profile
     $user = $profile->User();
     $model = new FrontFormSettings($user);
     if ($model->send() && $model->validate()) {
         $model->save();
         App::$Session->getFlashBag()->add('success', __('Profile is updated'));
     }
     return $this->view->render('update', ['model' => $model, 'user' => $user, 'profile' => $profile]);
 }
Example #2
0
 /**
  * User profile settings
  * @return string
  * @throws \Ffcms\Core\Exception\SyntaxException
  * @throws \Ffcms\Core\Exception\NativeException
  * @throws ForbiddenException
  */
 public function actionSettings()
 {
     // check if auth
     if (!App::$User->isAuth()) {
         throw new ForbiddenException();
     }
     // get user object
     $user = App::$User->identity();
     // create model and pass user object
     $model = new FormSettings($user);
     // check if form is submited
     if ($model->send() && $model->validate()) {
         $model->save();
         App::$Session->getFlashBag()->add('success', __('Profile data are successful updated'));
     }
     // render view
     return $this->view->render('settings', ['model' => $model]);
 }