/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->first_name = $this->first_name; $user->last_name = $this->last_name; $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); $user->save(); //添加权限 $permissionList = $_POST['SignupForm']['permissions']; foreach ($permissionList as $value) { $newPermission = new AuthAssignment(); $newPermission->user_id = $user->id; $newPermission->item_name = $value; $newPermission->save(); print_r($newPermission->getErrors()); } //die; if ($user->save()) { return $user; } } return null; }
public function activateAccount() { $user = $this->_user; $user->status = User::STATUS_ACTIVE; $user->removeActivateKey(); $result = $user->save(); $assignment = new AuthAssignment(); $assignment->item_name = 'user'; $assignment->user_id = $user->id; $assignment->created_at = time(); $result2 = $assignment->save(false, ['item_name', 'user_id', 'created_at']); return $result; }
/** * Deletes an existing Role model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param string $id * @return mixed */ public function actionDelete($id) { $item_name = $this->findModel($id); $f = \backend\models\AuthAssignment::findOne($id); if ($f != null) { $f->delete(); } $item_name->delete(); return $this->redirect(['user/index']); }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); $user->save(); $permissionList = $_POST['SignupForm']['permission']; foreach ($permissionList as $value) { $newPermisssion = new AuthAssignment(); $newPermisssion->user_id = $user->id; $newPermisssion->item_name = $value; $newPermisssion->save(); } return $user; } return null; }
/** * Updates an existing User model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $assignments = AuthAssignment::findAll(['user_id' => $id]); $roles = []; if ($model->load(Yii::$app->request->post()) && $model->save()) { // $this->applyAssignments($roles, $id); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'roles' => $assignments]); } }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->firstname = $this->firstname; $user->lastname = $this->lastname; $user->notelp = $this->notelp; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { //add to auth_assignment table $permission = new AuthAssignment(); $permission->user_id = $user->id; $permission->item_name = 'user'; $permission->save(); return $user; } } return null; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = AuthAssignment::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['created_at' => $this->created_at]); $query->andFilterWhere(['like', 'item_name', $this->item_name])->andFilterWhere(['like', 'user_id', $this->user_id]); return $dataProvider; }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { // Save Permission $permissionList = $_POST['SignupForm']['permissions']; foreach ($permissionList as $key => $val) { $authAssignment = new AuthAssignment(); $authAssignment->user_id = $user->id; $authAssignment->item_name = $val; $authAssignment->created_at = date('Y-m-d'); $authAssignment->save(); } return $user; } } return null; }
private function save_assignment($user_id) { $assignment = new \backend\models\AuthAssignment(); $assignment->user_id = $user_id; $assignment->item_name = $this->auth_item; if ($assignment->save()) { // echo $this->auth_item; $this->id = $user_id; } else { echo $this->auth_item; print_r($assignment->getErrors()); exit; } }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->firstname = $this->firstname; $user->lastname = $this->lastname; $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); if ($user->save()) { $post = Yii::$app->request->post(); $permissionList = $post['SignupForm']['permissions']; foreach ($permissionList as $item) { $authAssignment = new AuthAssignment(); $authAssignment->user_id = $user->id; $authAssignment->item_name = $item; $authAssignment->save(); } return $user; } } return null; }
/** * @return \yii\db\ActiveQuery */ public function getAuthAssignment() { return $this->hasOne(AuthAssignment::className(), ['item_name' => 'name']); }
/** * Finds the AuthAssignment model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $item_name * @param string $user_id * @return AuthAssignment the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($item_name, $user_id) { if (($model = AuthAssignment::findOne(['item_name' => $item_name, 'user_id' => $user_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getAuthAssignments() { return $this->hasMany(AuthAssignment::className(), ['user_id' => 'id']); }
<?php echo $this->render('_form', ['model' => $model]); ?> <!-- <table> <tr> <td style="margin: 5px;"> <?php echo Html::tag('p', 'Назначенные роли'); $assignment = []; foreach ($roles as $item) { $assignment[] = $item->item_name; } echo Html::listBox('roles', null, $assignment); ?> </td> <td style="margin: 5px;"> <?php echo Html::tag('p', 'Доступные роли'); $auth = AuthAssignment::find()->all(); $assignment = []; foreach ($auth as $item) { $assignment[] = $item->item_name; } echo Html::listBox('roles', null, $assignment); ?> </td> </tr> </table>--> </div>
/** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = User::findOne($id)) !== null) { /* * Asign auth_assignment for current user */ $array = ArrayHelper::map(\backend\models\AuthAssignment::find()->where(['user_id' => $id])->all(), 'user_id', 'item_name'); if ($array) { $model->auth_assignment = $array[$id]; } return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Find the AuthAssighment model based on its user_id value * @param type $user_id * @return type * @throws NotFoundHttpException */ protected function findAuth($user_id) { if (($auth = AuthAssignment::findOne(['user_id' => $user_id])) !== null) { return $auth; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
?> </h1> <p> <?php echo Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a('Delete', ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => 'Are you sure you want to delete this item?', 'method' => 'post']]); ?> <?php if (Yii::$app->user->can('admin')) { echo Html::a('Изменить пароль', ['password-change', 'id' => $model->id], ['class' => 'btn btn-primary']); } ?> </p> <?php $status = User::getStatusName($model->status); echo DetailView::widget(['model' => $model, 'attributes' => ['id', 'username', 'name', 'email:email', ['attribute' => 'status', 'format' => 'raw', 'value' => $model->status == 10 ? '<span class="label label-success">' . $status . '</span>' : '<span class="label label-danger">' . $status . '</span>'], ['attribute' => 'created_at', 'value' => date('d-M-Y H:i:s', $model->created_at)], ['attribute' => 'updated_at', 'value' => date('d-M-Y H:i:s', $model->updated_at)]]]); echo Html::tag('p', 'Назначенные роли'); $auth = AuthAssignment::findAll(['user_id' => $model->id]); $assignment = []; foreach ($auth as $item) { $assignment[] = $item->item_name; } echo Html::listBox('roles', null, $assignment); ?> </div>
public function getAuthAssignment() { return $this->hasOne(\backend\models\AuthAssignment::className(), ['user_id' => 'id']); }
public function update($runValidation = true, $attributeNames = NULL) { if (!empty($this->password)) { $this->password_hash = Yii::$app->security->generatePasswordHash($this->password); } $assignment = \backend\models\AuthAssignment::findOne(['user_id' => $this->id]); if ($assignment != null) { $assignment->item_name = $this->auth_item; if (!$assignment->update()) { print_r($assignment->getErrors()); exit; } } else { $this->save_assignment($this->id); } $this->status = $this->status == 1 ? 10 : 0; parent::update(); return true; }