/** * Iterates over all password groups and their passwords and saves them * to the database. */ public function get($file_path) { /* @var $xml \app\modules\yiipass\services\SimpleKeePassXmlService */ $xml = \Yii::$app->getModule('yiipass')->get('SimpleKeePassXmlService'); $arr_password_groups = $xml->formXmlFileToArray($file_path); foreach ($arr_password_groups as $group) { foreach ($group as $password_from_group) { /* @var $password_from_group \app\models\Password */ /* @var $password \app\models\Password */ $password = new Password(); $password->title = $password_from_group->title->__toString(); $password->username = $password_from_group->username->__toString(); $password->password = $password_from_group->password->__toString(); $password->url = $password_from_group->url->__toString(); $password->comment = $password_from_group->comment->__toString(); $password->creation = $password_from_group->creation->__toString(); $password->lastaccess = $password_from_group->lastaccess->__toString(); $password->lastmod = $password_from_group->lastmod->__toString(); $password->group = $password_from_group->group->__toString(); $password->lastaccess = $password_from_group->lastaccess->__toString(); $password->save(); $password->save(); UserController::addPermissionToUser(Yii::$app->user->id, 'password-id-' . $password->id); } } }
/** * 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); } }