Example #1
0
 public function actionProfile()
 {
     $model = $this->findProfile();
     $ajax = Yii::$app->request->isAjax;
     if ($model->load(Yii::$app->request->post())) {
         if (!empty($model->new_password)) {
             if ($model->validatePassword($model->old_password)) {
                 $model->setPassword($model->new_password);
             } else {
                 Yii::$app->session->setFlash('warning', 'Password lama salah');
             }
         }
         if ($model->save()) {
             Yii::$app->session->setFlash('success', 'Profile berhasil diupdate');
         } else {
             Yii::$app->session->setFlash('error', 'Profile gagal diupdate');
         }
         //return $this->refresh();
     }
     $authAssignments = AuthAssignment::find()->where(['user_id' => Yii::$app->user->id])->column();
     if ($ajax) {
         return $this->renderAjax('profile', ['model' => $model, 'authAssignments' => $authAssignments]);
     } else {
         return $this->render('profile', ['model' => $model, 'authAssignments' => $authAssignments]);
     }
 }
Example #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRoles()
 {
     return $this->hasMany(AuthAssignment::className(), ['user_id' => 'id']);
 }
Example #3
0
 /**
  * Deletes an existing User model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     $authAssignments = AuthAssignment::find()->where(['user_id' => $model->id])->all();
     foreach ($authAssignments as $authAssignment) {
         $authAssignment->delete();
     }
     Yii::$app->session->setFlash('success', 'Delete success');
     $model->delete();
     return $this->redirect(['index']);
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAuthAssignments()
 {
     return $this->hasMany(AuthAssignment::className(), ['item_name' => 'name']);
 }