Ejemplo n.º 1
0
 public function validateCurrentPassword($attribute)
 {
     if (!empty($this->user_id)) {
         $user = User::findOne($this->user_id);
         if (!$user->validatePassword($this->current_password)) {
             $this->addError($attribute, Yii::t('podium/view', 'Current password is incorrect.'));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Listing the details of user of given ID.
  * @param integer $id
  * @return string|\yii\web\Response
  */
 public function actionView($id = null)
 {
     $model = User::findOne((int) $id);
     if (empty($model)) {
         $this->error(Yii::t('podium/flash', 'Sorry! We can not find Member with this ID.'));
         return $this->redirect(['admin/members']);
     }
     return $this->render('view', ['model' => $model]);
 }
Ejemplo n.º 3
0
 /**
  * Updating the forum details.
  * @return string|\yii\web\Response
  */
 public function actionForum()
 {
     $model = Meta::findOne(['user_id' => Yii::$app->user->id]);
     if (empty($model)) {
         $model = new Meta();
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->user_id = Yii::$app->user->id;
         $uploadAvatar = false;
         $path = Yii::getAlias('@webroot/avatars');
         $avatar = UploadedFile::getInstance($model, 'image');
         if ($avatar) {
             $folderExists = true;
             if (!file_exists($path)) {
                 if (!FileHelper::createDirectory($path)) {
                     $folderExists = false;
                     Log::error('Error while creating avatars folder', null, __METHOD__);
                     $this->error('Sorry! There was an error while creating the avatars folder. Contact administrator about this problem.');
                 }
             }
             if ($folderExists) {
                 if (!empty($model->avatar)) {
                     if (!unlink($path . DIRECTORY_SEPARATOR . $model->avatar)) {
                         Log::error('Error while deleting old avatar image', null, __METHOD__);
                     }
                 }
                 $model->avatar = Yii::$app->security->generateRandomString() . '.' . $avatar->getExtension();
                 $uploadAvatar = true;
             }
         }
         if ($model->save()) {
             if ($uploadAvatar) {
                 if (!$avatar->saveAs($path . DIRECTORY_SEPARATOR . $model->avatar)) {
                     Log::error('Error while saving avatar image', null, __METHOD__);
                     $this->error('Sorry! There was an error while uploading the avatar image. Contact administrator about this problem.');
                 }
             }
             Log::info('Profile updated', !empty($model->id) ? $model->id : '', __METHOD__);
             $this->success('Your profile details have been updated.');
             return $this->refresh();
         } else {
             $model->current_password = null;
         }
     }
     return $this->render('forum', ['model' => $model, 'user' => User::findOne(Yii::$app->user->id)]);
 }