/** * Creates a new Password model. If creation is successful, the browser * will be redirected to the 'view' page. * * @return mixed */ public function actionCreate() { if (Yii::$app->user->isGuest === true) { return $this->redirect(['/site/login']); } $model = new Password(); if ($model->load(Yii::$app->request->post()) && $model->save()) { // The user which has created the password can access it. UserController::addPermissionToUser(Yii::$app->user->id, 'password-id-' . $model->id); // Update permissions if they have been set for any user. $this->setNewPermissionsAndNotify($model->id); return $this->redirect(['view', 'id' => $model->id]); } else { $elements_to_render = array('model' => $model); if (Yii::$app->user->getIdentity()->is_admin == 1) { $all_users = User::find()->all(); $user_checkboxes = $this->getHtmlCheckboxesForUsers($all_users, false, $model); $elements_to_render['user_checkboxes'] = $user_checkboxes; } return $this->render('create', $elements_to_render); } }
/** * Creates a new Password model. If creation is successful, the browser * will be redirected to the 'view' page. * * @return mixed */ public function actionCreate() { if (Yii::$app->params['single_user_mode'] === FALSE) { if (Yii::$app->user->isGuest === TRUE) { return $this->redirect(['/site/login']); } } $model = new Password(); if ($model->load(Yii::$app->request->post())) { $sPassword = Yii::$app->request->post()['Password']['password']; /* @var $model \app\modules\yiipass\models\Password */ $model->password = $this->encrypt($sPassword); $model->save(); if (Yii::$app->params['single_user_mode'] === FALSE) { $iUserId = Yii::$app->user->id; } else { $iUserId = 1; } // The user which has created the password can access it. UserController::addPermissionToUser($iUserId, 'password-id-' . $model->id); // Update permissions if they have been set for any user. $this->setNewPermissionsAndNotify($model->id); return $this->redirect(['view', 'id' => $model->id]); } else { $elements_to_render = array('model' => $model); if (Yii::$app->params['single_user_mode'] === FALSE) { if (Yii::$app->user->getIdentity()->is_admin == 1) { $all_users = User::find()->all(); $user_checkboxes = $this->getHtmlCheckboxesForUsers($all_users, FALSE, $model); $elements_to_render['user_checkboxes'] = $user_checkboxes; } } return $this->render('create', $elements_to_render); } }