Esempio n. 1
0
 /**
  * 修改个人信息
  */
 function actionChangeInfo()
 {
     $this->_pathway->addStep('个人信息');
     $currentUser = $this->_app->currentUser();
     $user = Users::find()->getById($currentUser['id']);
     $form = new Form_User(url('admin::usercenter/changeInfo'));
     $form->element('username')->set('readonly', 'true');
     $form->remove('password');
     $form->element('group_id')->items = Groups::find('id=?', $user->group_id)->order('weight desc')->getAll()->toHashMap('id', 'name');
     $form->element('level_id')->items = Levels::find('weight=?', $user->level_id)->order('weight desc')->getAll()->toHashMap('weight', 'name');
     $form->remove('enabled');
     $form->add(QForm::ELEMENT, 'id', array('_ui' => 'hidden', 'value' => $currentUser['id']));
     if ($this->_context->isPOST() && $form->validate($_POST)) {
         try {
             $user->changeProps($form->values());
             $user->save();
             return "{msg:'编辑成功'}";
         } catch (QDB_ActiveRecord_ValidateFailedException $ex) {
             $form->invalidate($ex);
         }
     } else {
         $form->import($user);
     }
     $form->add(QForm::ELEMENT, 'reg_at', array('_ui' => 'textbox', '_label' => '注册时间', 'value' => date('Y-m-d', $user->register_at), 'class' => 'txt w200', 'readonly' => 'true'));
     $form->add(QForm::ELEMENT, 'reg_ip', array('_ui' => 'textbox', '_label' => '注册IP', 'value' => $user->register_ip, 'class' => 'txt w200', 'readonly' => 'true'));
     $form->add(QForm::ELEMENT, 'log_at', array('_ui' => 'textbox', '_label' => '最后登录时间', 'value' => $user->login_at == 0 ? '0000-00-00' : date('Y-m-d', $user->login_at), 'class' => 'txt w200', 'readonly' => 'true'));
     $form->add(QForm::ELEMENT, 'log_ip', array('_ui' => 'textbox', '_label' => '最后登录IP', 'value' => $user->login_ip, 'class' => 'txt w200', 'readonly' => 'true'));
     $form->add(QForm::ELEMENT, 'log_count', array('_ui' => 'textbox', '_label' => '登录次数', 'value' => $user->login_count, 'class' => 'txt w200', 'readonly' => 'true'));
     $this->_view['form'] = $form;
 }
Esempio n. 2
0
 /**
  * 添加用户
  */
 function actionUserEdit()
 {
     $this->_pathway->addStep('编辑用户');
     $id = $this->_context->id;
     $user = Users::find()->getById($id);
     $form = new Form_User(url('admin::aclmanager/userEdit'));
     $form->element('username')->set('readonly', 'true');
     $form->element('password')->set('_tips', '密码长度只能在3-32位之间,如果不更改密码此处请留空');
     $form->element('group_id')->items = Groups::find('enabled=1')->order('weight desc')->getAll()->toHashMap('id', 'name');
     $form->element('level_id')->items = Levels::find('enabled=1')->order('weight desc')->getAll()->toHashMap('weight', 'name');
     $form->add(QForm::ELEMENT, 'id', array('_ui' => 'hidden', 'value' => $id));
     if ($this->_context->isPOST()) {
         if ($_POST['password'] == '') {
             $form->remove('password');
         }
         if ($form->validate($_POST)) {
             try {
                 $user->changePropForce('group_id', $form->element('group_id')->value());
                 $user->changePropForce('level_id', $form->element('level_id')->value());
                 $user->changeProps($form->values());
                 $user->save();
                 return "{id:{$id},msg:'编辑成功'}";
             } catch (QDB_ActiveRecord_ValidateFailedException $ex) {
                 $form->invalidate($ex);
             }
         } else {
             $form->import($user);
         }
     } else {
         $form->import($user);
     }
     $form->element('password')->set('value', '');
     $form->add(QForm::ELEMENT, 'reg_at', array('_ui' => 'textbox', '_label' => '注册时间', 'value' => date('Y-m-d', $user->register_at), 'class' => 'txt w200', 'readonly' => 'true'));
     $form->add(QForm::ELEMENT, 'reg_ip', array('_ui' => 'textbox', '_label' => '注册IP', 'value' => $user->register_ip, 'class' => 'txt w200', 'readonly' => 'true'));
     $form->add(QForm::ELEMENT, 'log_at', array('_ui' => 'textbox', '_label' => '最后登录时间', 'value' => $user->login_at == 0 ? '0000-00-00' : date('Y-m-d', $user->login_at), 'class' => 'txt w200', 'readonly' => 'true'));
     $form->add(QForm::ELEMENT, 'log_ip', array('_ui' => 'textbox', '_label' => '最后登录IP', 'value' => $user->login_ip, 'class' => 'txt w200', 'readonly' => 'true'));
     $form->add(QForm::ELEMENT, 'log_count', array('_ui' => 'textbox', '_label' => '登录次数', 'value' => $user->login_count, 'class' => 'txt w200', 'readonly' => 'true'));
     $this->_view['form'] = $form;
 }