/**
  * 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;
 }
 /**
  * Creates a new AuthAssignment model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new AuthAssignment();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'item_name' => $model->item_name, 'user_id' => $model->user_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#3
0
 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;
 }
 /**
  * Creates a new AuthAssignment model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('createAuthAssignment')) {
         $model = new AuthAssignment();
         if ($model->load(Yii::$app->request->post())) {
             $model->created_at = time();
             $model->save();
             return $this->redirect(['view', 'item_name' => $model->item_name, 'user_id' => $model->user_id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         throw new ForbiddenHttpException();
     }
 }
示例#5
0
 /**
  * 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;
 }
示例#6
0
 /**
  * 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;
 }
示例#7
0
 /**
  * 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;
 }
示例#8
0
 /**
  * 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;
 }
示例#9
0
 public function actionUpdate()
 {
     $id = Yii::$app->request->get('id', 0);
     $error = '';
     $user = new User();
     $model = $this->findModel($id);
     $data['_csrf'] = Yii::$app->request->post('_csrf', '');
     $data['User'] = Yii::$app->request->post();
     if (isset($data['User']['submit'])) {
         $data['User']['update_date'] = time();
         $data['User']['user_update'] = \Yii::$app->user->id;
         if ($model->load($data) && $model->save()) {
             $this->findAuth($id)->delete();
             $auth = new AuthAssignment();
             $dataAuth['_csrf'] = $data['_csrf'];
             $dataAuth['AuthAssignment']['item_name'] = $data['User']['group'];
             $dataAuth['AuthAssignment']['user_id'] = $id;
             $dataAuth['AuthAssignment']['created_at'] = time();
             $auth->load($dataAuth);
             $auth->save();
             return $this->redirect(['index']);
         }
     } else {
         $group = $user->getGroup();
         return $this->render('update', ['model' => $model, 'error' => $error, 'group' => $group]);
     }
 }
示例#10
0
 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;
     }
 }