Exemplo n.º 1
0
 public function indexAction()
 {
     if ($this->_request->get('dowhat') == 'logout') {
         $this->_view->assign('useTpl', 'logout');
         \Sooh\Base\Session\Data::getInstance()->set('managerId', '');
     } elseif ($this->manager) {
         //已经登入,进主页
         $this->manager->load();
         $this->_view->assign('leftmenus', $this->manager->acl->getMenuMine());
         $this->_view->assign('useTpl', 'homepage');
     } else {
         //尚未登入,去登入页
         $u = $this->_request->get('u');
         $p = $this->_request->get('p');
         if (!empty($u) && !empty($p)) {
             $this->ini->viewRenderType('json');
             $acc = \Lib\Services\Manager::getInstance(null);
             try {
                 $validImg = $this->_request->get('valid');
                 $sessionData = \Sooh\Base\Session\Data::getInstance();
                 if ($validImg !== $sessionData->get('validImg')) {
                     return $this->returnError('invalidCode');
                 }
                 $accountInfo = $acc->login($u, $p, 'local', array('rights'));
                 $log = \Sooh\Base\Log\Data::getInstance();
                 $log->ret = 'login ok';
                 $log->ext = $accountInfo['nickname'];
                 $sessionData->set('managerId', $accountInfo['accountId']);
                 $sessionData->set('nickname', $accountInfo['nickname']);
                 $this->returnOK();
             } catch (\Exception $e) {
                 \Sooh\Base\Log\Data::getInstance()->ret = $e->getMessage();
                 $this->returnError($e->getMessage());
             }
         } else {
             $acc = \Lib\Services\Manager::getInstance(null);
             $acc->addFirstAccount();
             $this->_view->assign('useTpl', 'login');
         }
     }
 }
Exemplo n.º 2
0
 /**
  * 负责添加,更新逻辑以及表单页面控制
  * @return type
  */
 public function formAction()
 {
     $where = \Lib\Misc\DWZ::decodePkey($this->_request->get('_pkey_val'));
     $frm = \Sooh\Base\Form\Broker::getCopy('default')->init(\Sooh\Base\Tools::uri(), 'post', empty($where) ? \Sooh\Base\Form\Broker::type_c : \Sooh\Base\Form\Broker::type_u);
     //$frm->addItem('camefrom', form_def::factory('', 'local', form_def::constval));
     if (empty($where)) {
         $frm->addItem('loginname', form_def::factory('帐号', '', form_def::text))->addItem('nickname', form_def::factory('昵称', '', form_def::text));
         $frm->addItem('passwd', form_def::factory('初始密码', '', form_def::text));
         $this->_view->assign('FormOp', $op = '添加');
     } else {
         $frm->addItem('loginname', form_def::factory('帐号', '', form_def::constval))->addItem('nickname', form_def::factory('昵称', '', form_def::text));
         $this->_view->assign('FormOp', $op = '更新');
     }
     $frm->addItem('_pkey_val', '')->addItem('rights', form_def::factory('权限', '', array($this, 'renderTreeCheckbox')));
     //->initMore(new \Sooh\Base\Form\Options($this->optionsOfRights()))
     $frm->fillValues($this->getInputs());
     if ($frm->flgIsThisForm) {
         //submit
         try {
             if ($frm->type() == \Sooh\Base\Form\Broker::type_c) {
                 //add new manager
                 $fields = $frm->getFields();
                 if (is_array($fields['rights'])) {
                     $fields['rights'] = implode(',', $fields['rights']);
                 }
                 $acc = \Lib\Services\Manager::getInstance(null);
                 $acc->register($fields['loginname'], $fields['passwd'], $fields['camefrom'] = 'local', array('rights' => $fields['rights'], 'nickname' => $fields['nickname']));
                 $randPwd = $fields['passwd'];
             } else {
                 //update manager
                 $fields = $frm->getFields();
                 if (is_array($fields['rights'])) {
                     $fields['rights'] = implode(',', $fields['rights']);
                 }
                 //var_log($fields,'upd:');
                 unset($fields['camefrom']);
                 unset($fields['loginname']);
                 $manager = \Prj\Data\Manager::getCopy($where['loginname'], $where['camefrom']);
                 $manager->load();
                 foreach ($fields as $k => $v) {
                     $manager->setField($k, $v);
                 }
                 $manager->update();
                 $randPwd = null;
             }
             $this->closeAndReloadPage($this->tabname('index'));
             $this->returnOK($op . '成功' . ($randPwd ? ',密码:' . $randPwd : ''));
         } catch (\ErrorException $e) {
             if (\Sooh\DB\Broker::errorIs($e, \Sooh\DB\Error::duplicateKey)) {
                 $this->returnError($op . '失败:冲突,相关记录已经存在?');
             } else {
                 $this->returnError($op . '失败:' . $e->getMessage());
             }
         }
     } else {
         //show form
         if (!empty($where)) {
             $manager = \Prj\Data\Manager::getCopy($where['loginname'], $where['camefrom']);
             $manager->load();
             $fields = $manager->dump();
             $this->tmpVal = \Sooh\Base\Acl\Ctrl::_fromString($manager->getField('rights'));
             $ks = array_keys($frm->items);
             foreach ($ks as $k) {
                 if (isset($fields[$k]) && is_object($frm->items[$k])) {
                     $frm->item($k)->value = $fields[$k];
                 }
             }
             $frm->items['_pkey_val'] = \Lib\Misc\DWZ::encodePkey(array('camefrom' => $fields['camefrom'], 'loginname' => $fields['loginname']));
         } else {
             $fields = array();
             $this->tmpVal = array();
             //$frm->item('camefrom')->value='local';
         }
     }
 }