public function run() { $model = new UserForm(); if (($post = $this->request->getPost('UserForm', false)) !== false) { $model->attributes = $post; if ($model->save()) { $this->response(200, '更新用户成功'); } else { $this->response(500, '更新用户失败'); } $this->app->end(); } else { if (($id = $this->request->getQuery('id', 0)) != false) { if (($user = User::model()->findByPk($id)) != false) { $model->attributes = ['id' => $user->id, 'username' => $user->username, 'realname' => $user->realname, 'nickname' => $user->nickname, 'email' => $user->email, 'state' => $user->state]; $auth = $this->app->getAuthManager(); $roles = $auth->getRoleByUserId($id); $role = []; foreach ($roles as $item) { $role[] = $item->getId(); } $groups = $auth->getGroupByUserId($id); $group = []; foreach ($groups as $item) { $group[] = $item->getId(); } $this->render('edit', ['model' => $model, 'role' => $role, 'group' => $group, 'roleList' => Role::model()->findAll(), 'groupList' => Group::model()->findAll()]); $this->app->end(); } } } $this->response(404, '参数错误'); }
public function actionAccount() { $model = new UserForm(); if (($post = $this->request->getPost('UserForm', false)) != false) { $model->attributes = $post; if ($model->save()) { $this->user->logout(); $this->redirect($this->createUrl('index')); } } $this->render('account', ['model' => $model, 'service' => Service::model()->findByPk($this->user->getId())]); }
public function actionEdit() { $model = new UserForm(); if (($post = $this->request->getPost('UserForm', false)) !== false) { $post['state'] = -1; $model->attributes = $post; if ($model->save()) { $this->response(200, '更新用户成功'); } else { $this->response(500, '更新用户失败'); } } else { if (($id = $this->request->getQuery('id', 0)) != false) { if (($user = User::model()->findByPk($id)) != false) { $model->attributes = ['id' => $user->id, 'username' => $user->username, 'realname' => $user->realname, 'nickname' => $user->nickname, 'email' => $user->email, 'state' => -1]; $this->render('edit', ['model' => $model]); } } else { $this->response(404, '参数错误'); } } }
public function actionUpdate() { $companyId = Helper::getCompanyId(Yii::app()->request->getParam('companyId')); $id = Yii::app()->request->getParam('id'); Until::isUpdateValid(array($id), $companyId, $this); //0,表示企业任何时候都在云端更新。 if (Yii::app()->user->role > User::ADMIN && Yii::app()->user->userId != $id) { Yii::app()->user->setFlash('error', yii::t('app', '你没有权限修改')); $this->redirect(array('user/index', 'companyId' => $companyId)); } $model = new UserForm(); $model->find('lid=:id and dpid=:dpid and status=1', array(':id' => $id, ':dpid' => $companyId)); if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('UserForm'); //$model->update_at=date('Y-m-d H:i:s',time()); //var_dump($model->attributes);exit; if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '修改成功')); $this->redirect(array('user/index', 'companyId' => $companyId)); } } $this->render('update', array('model' => $model)); }
$methods = array('widgetChoiceTableMethod1', 'widgetChoiceTableMethod2', 'widgetChoiceTableMethod3'); foreach ($methods as $method) { $widget = new sfWidgetFormDoctrineChoice(array('model' => 'User', 'table_method' => $method)); $t->is($widget->getChoices(), array(1 => 1)); } $widget = new sfWidgetFormDoctrineChoice(array('model' => 'User', 'table_method' => 'widgetChoiceTableMethod4')); $t->is($widget->getChoices(), array()); $user = new User(); $user->Groups[]->name = 'User Group 1'; $user->Groups[]->name = 'User Group 2'; class UserGroupForm extends GroupForm { public function configure() { parent::configure(); $this->useFields(array('name')); } } $userForm = new UserForm($user); $userForm->embedRelation('Groups', 'UserGroupForm'); $data = array('username' => 'jonwage', 'password' => 'changeme', 'Groups' => array(0 => array('name' => 'New User Group 1 Name'), 1 => array('name' => 'New User Group 2 Name'))); $userForm->bind($data); $t->is($userForm->isValid(), true); if ($userForm->isValid()) { $userForm->save(); } $t->is($user->Groups[0]->name, 'New User Group 1 Name'); $t->is($user->Groups[1]->name, 'New User Group 2 Name'); $form = new DefaultValueTestForm(); $validatorSchema = $form->getValidatorSchema(); $t->is($validatorSchema['name']->getOption('required'), false);
/** * This action enables us to create an admin user for CiiMS */ public function actionCreateAdmin() { $this->stage = Yii::app()->session['stage'] = 6; $model = new UserForm(); if (Cii::get($_POST, 'UserForm') != NULL) { $model->attributes = Cii::get($_POST, 'UserForm', array()); if ($model->save()) { $this->redirect($this->createUrl('/admin')); } $errors = $model->getErrors(); $firstError = array_values($errors); Yii::app()->user->setFlash('error', Yii::t('Install.main', '{{warning}} {{error}}', array('{{warning}}' => CHtml::tag('strong', array(), Yii::t('Install.main', 'Warning!')), '{{error}}' => $firstError[0][0]))); } $this->render('createadmin', array('model' => $model)); }