setOutput('IS_ADMIN', $IS_ADMIN); $this->setOutput('backuser', $this->getUser()); } public function doLogin() { if (Request::isPost()) { $username = Request::p('username'); if (!$username) { self::ajax_fail_exit('请填写用户姓名'); } $password = Request::p('password'); if (!$password) { self::ajax_fail_exit('请填写登陆密码'); } $app_id = Config::getInstance()->get('App_Id'); $project = Math::md5_16($app_id); $objBackPassport = new BackPassport(); $tmpResult = $objBackPassport->login($username, $password, $project); if (!$tmpResult->isSuccess()) { self::ajax_fail_exit($tmpResult->getData()); } self::ajax_success_exit(); } $this->tpl = 'admin/backUser/login'; $title = '登录 - 后台管理工作平台'; $this->setOutput('title', $title); $this->setOutput('op', Request::g('op')); } public function doLogout() { $objBackPassport = new BackPassport(); $objBackPassport->logout(); self::redirect(Request::schemeDomain() . '/?c=admin_backUser&a=login&op=logout'); } /** * 创建新帐号 */ public function doCreateUser() { \KIF\Core\PermissionController::requireCompetence(); $objDBackUser = new DBackUser(); if (Request::isPost()) { $errMsg = array('ok' => true); do { $name = Request::p('name'); if (!$name) { $errMsg['msg'] = '请填写姓名'; break; } if ($objDBackUser->getIdByName($name)) { $errMsg['msg'] = "用户名\"{$name}\"已经存在"; break; } $platfrom = $_POST['platfrom']; if (!$platfrom) { $errMsg['msg'] = "请选择平台列表"; break; } $auto_generate = Request::p('auto_generate'); $password = Request::p('password'); if (!$auto_generate && !$password) { $auto_generate = true; } if ($auto_generate) { $password = crypt(Math::md5_16(time()), 'k'); $_POST['password'] = $password; } $email = Request::p('email'); $division = Request::p('division'); $app_id = Config::getInstance()->get('App_Id'); $project = Math::md5_16($app_id); $info = array( 'name' => $name, 'password' => $password, 'email' => $email, 'division' => $division, 'project' => $project, 'app_id' => $app_id, 'permission'=> 'ordinary', 'platfrom' => $platfrom, ); $tmpResult = $objDBackUser->add($info); if (!$tmpResult->isSuccess()) { $errMsg['msg'] = $tmpResult->getData(); } else { $user = $tmpResult->getData(); $user['password'] = $password; $uid = $user['uid']; # 建立权限组 // $objDKifUsergroup = new \Cas\Dao\KifUsergroup(); // $groupid = $objDKifUsergroup->add(array('description' => $name)); // $objDKifUsergroupRelation = new \Cas\Dao\KifUsergroupRelation(); // $objDKifUsergroupRelation->add(array('uid' => $uid, 'groupid' => $groupid)); // $objDBackUser->modify(array('groupid' => $groupid), array('uid' => $uid)); } } while (false); if ($errMsg['msg']) { $errMsg['ok'] = false; } $this->setOutput('submitData', $_POST); $this->setOutput('errMsg', $errMsg); $this->setOutput('new_user', $user); } $app_id = Config::getInstance()->get('App_Id'); $project = Math::md5_16($app_id); $uids = $objDBackUser->findIdsBy(array('project' => $project)); $users = $objDBackUser->gets($uids); krsort($users); $objDPlatfrom = new Platform (); $platfrom = $objDPlatfrom->getsAll('id desc'); $this->tpl = 'admin/backUser/user_list'; $title = '帐号管理'; $this->setOutput('title', $title); $this->setOutput('menu_active', array('name' => 'userslist', 'item' => '')); //激活菜单 $this->addNavMenu('平台设置'); $this->addNavMenu($title); $this->setOutput('users', $users); $this->setOutput('platfrom', $platfrom); } public function doDeleteUser() { \KIF\Core\PermissionController::requireCompetence(); $uid = Request::p('uid'); if (!Verify::unsignedInt($uid)) { $this->ajax_fail_exit('无效用户id'); } $objDBackUser = new DBackUser(); $tmpResult = $objDBackUser->delete(array('uid'=>$uid)); $this->ajax_success_exit(); } /** * 后台用户列表 */ public function doUserList() { \KIF\Core\PermissionController::requireCompetence(); $objDBackUser = new DBackUser(); $app_id = Config::getInstance()->get('App_Id'); $project = Math::md5_16($app_id); $condition = "project = '{$project}' || permission = 'admin'"; $uids = $objDBackUser->findIdsBy($condition); $users = $objDBackUser->gets($uids); krsort($users); $objDPlatfrom = new Platform (); $platfrom = $objDPlatfrom->getsAll('id desc'); $this->tpl = 'admin/backUser/user_list'; $title = '帐号管理'; $this->setOutput('title', $title); $this->setOutput('menu_active', array('name' => 'userslist', 'item' => '')); //激活菜单 $this->addNavMenu('平台设置'); $this->addNavMenu($title); $this->setOutput('users', $users); $this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据 $this->setOutput('platfrom', $platfrom); } /** * 修改密码 - 自助 */ public function doModifyPassword() { \KIF\Core\PermissionController::requireCompetence(); $uid = Request::g('uid'); if (!Verify::unsignedInt($uid)) { self::fail_exit_bs('无效uid'); } $objDBackUser = new DBackUser(); $user = $objDBackUser->get($uid); if (!$user) { self::fail_exit_bs('用户不存在'); } if (Request::isPost()) { do { $oldPassword = Request::p('oldPassword'); if (!$oldPassword) { $errMsg = '原始密码为空'; break; } $newPassword = Request::p('newPassword'); if (!$newPassword) { $errMsg = '新密码为空'; break; } $tmpResult = $objDBackUser->modifyPassword($uid, $oldPassword, $newPassword); if (!$tmpResult->isSuccess()) { $errMsg = $tmpResult->getData(); break; } $successMsg = '密码修改成功'; } while (false); } $this->tpl = 'admin/backUser/modify_password'; $title = '密码修改'; $this->setOutput('title', $title); $this->setOutput('menu_active', array('name' => 'modifypassword', 'item' => '')); //激活菜单 $this->addNavMenu('帐号管理'); $this->addNavMenu($title); $this->setOutput('errMsg', $errMsg); $this->setOutput('successMsg', $successMsg); $this->setOutput('user', $user); $this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据 } /** * 密码修改 - 超级管理员使用 */ public function doMP() { \KIF\Core\PermissionController::requireCompetence(); $uid = Request::g('uid'); if (!Verify::unsignedInt($uid)) { self::fail_exit_bs('无效uid'); } $objDBackUser = new DBackUser(); $user = $objDBackUser->get($uid); if (!$user) { self::fail_exit_bs('用户不存在'); } if (Request::isPost()) { do { $password = Request::p('password'); $auto_generate = Request::p('auto_generate'); if (!$password && $auto_generate) { $password = crypt(Math::md5_16(time()), '@w'); } else { if (strlen($password) < 6) { $errMsg['ok'] = 1; $errMsg['msg'] = '密码不能小于8位'; break; } } $tableInfo = array( 'password' => Math::md5_16($password), ); $condition = array( 'uid' => $uid, ); $tmpResult = $objDBackUser->update($tableInfo, $condition); if (!$tmpResult) { $errMsg['ok'] = 1; $errMsg['msg'] = '密码修改失败'; } $errMsg['ok'] = 2; $errMsg['msg'] = "密码修改成功。新密码: {$password}"; } while (false); } $this->tpl = 'admin/backUser/mp'; $title = '密码修改'; $this->setOutput('title', $title); $this->setOutput('menu_active', array('name' => 'userslist', 'item' => '')); //激活菜单 $this->addNavMenu('用户管理'); $this->addNavMenu($title); $this->setOutput('user', $user); $this->setOutput('password', $password); $this->setOutput('errMsg', $errMsg); $this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据 } /** * 权限设置 * 选择角色:管理员、普通账号 */ public function doSetPermission() { \KIF\Core\PermissionController::requireCompetence(); $uid = Request::g('uid'); if (!Verify::unsignedInt($uid)) { self::fail_exit_bs('无效uid'); } $objDBackUser = new DBackUser(); $user = $objDBackUser->get($uid); if (!$user) { self::fail_exit_bs('用户不存在'); } if (Request::isPost()) { $permission = Request::p('permission'); if (!in_array($permission, array('admin', 'ordinary'))) { $this->ajax_fail_exit('不存在的角色'); } $info = array('permission' => $permission); $condition = array('uid' => $uid); $objDBackUser->modify($info, $condition); $user['permission'] = $permission; $errMsg['ok'] = true; } $this->tpl = 'admin/backUser/permission'; $title = '权限设置'; $this->setOutput('title', $title); $this->setOutput('menu_active', array('name' => 'userslist', 'item' => '')); //激活菜单 $this->addNavMenu('用户管理'); $this->addNavMenu($title); $this->setOutput('user', $user); $this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据 $this->setOutput('errMsg', $errMsg); } public function doSetPlatfrom() { \KIF\Core\PermissionController::requireCompetence(); $uid = Request::g('uid'); if (!Verify::unsignedInt($uid)) { self::fail_exit_bs('无效uid'); } $objDBackUser = new DBackUser(); $user = $objDBackUser->get($uid); if (!$user) { self::fail_exit_bs('用户不存在'); } if (Request::isPost()) { $platfrom = $_POST['platfrom']; if (!$platfrom) { $this->ajax_fail_exit('不存在的角色'); } $info = array('platfrom' => $platfrom); $condition = array('uid' => $uid); $objDBackUser->modify($info, $condition); $user['platfrom'] = $platfrom; $errMsg['ok'] = true; } $objDPlatfrom = new Platform (); $platfrom = $objDPlatfrom->getsAll('id desc'); $this->tpl = 'admin/backUser/platfrom'; $title = '权限设置'; $this->setOutput('title', $title); $this->setOutput('menu_active', array('name' => 'userslist', 'item' => '')); //激活菜单 $this->addNavMenu('用户管理'); $this->addNavMenu($title); $this->setOutput('user', $user); $this->setOutput('pagePublicData', $this->getPagePublicData()); // 后台管理相关数据 $this->setOutput('errMsg', $errMsg); $this->setOutput('platfrom', $platfrom); } public function getPagePublicData() { $adminPublicArray = array (); $adminPublicArray ['rapidEntranceUrl'] = $this->getRapidEntrance (); // 头部导航"新建"数据 return $adminPublicArray; } /** * 头部导航"新建"数据 */ public function getRapidEntrance() { $url = Request::schemeDomain () . '/?c=Admin_Activity_SetBasics&a=PageCreate&type='; $fastCreateActivityUrlData = array ( '大转盘' => $url . LotteryEvents::TYPE_EVENTS_TURNTABLE . '&bigType=Event', '刮刮卡' => $url . LotteryEvents::TYPE_EVENTS_SCRATCH . '&bigType=Event', '邀请函' => $url . LotteryEvents::TYPE_EVENTS_INVITATION . '&bigType=Event', '优惠券' => $url . LotteryEvents::TYPE_EVENTS_CODE . '&bigType=Event', '试用' => $url . LotteryEvents::TYPE_EVENTS_TRY . '&bigType=Event', '问卷调查' => $url . LotteryEvents::TYPE_EVENTS_SURVEY . '&bigType=Event', '投票' => $url . LotteryEvents::TYPE_EVENTS_VOTE . '&bigType=Event', '切屏专题' => $url . LotteryEvents::TYPE_EVENTS_CUT_SCREEN . '&bigType=H5', '文章' => $url . LotteryEvents::TYPE_EVENTS_ARTICLE . '&bigType=Article', '其他' => $url . LotteryEvents::TYPE_EVENTS_OTHER . '&bigType=Event', ); return $fastCreateActivityUrlData; } public function display() { return $this->render(); } }