function __construct($swoole) { parent::__construct($swoole); if (isset($_POST["PHPSESSID"])) { $_COOKIE['PHPSESSID'] = $_POST["PHPSESSID"]; session_id($_COOKIE['PHPSESSID']); } Swoole::$php->session->start(); Swoole\Auth::$login_url = '/page/login/?'; if (Swoole\Auth::login_require() === false) { return $this->swoole->http->finish(); } $this->uid = $_SESSION['user_id']; }
/** * 登陆页面 */ function login() { if (isPost()) { $username = getRequest('username'); $password = getRequest('password'); $authCode = getRequest('authCode'); if (!$this->verifyPicCaptcha($authCode)) { $this->tpl->assign('error', '图片验证码不正确'); } else { $config = Swoole::$php->config['user']; $auth = new Swoole\Auth($config); $flag = $auth->login($username, $password); if ($flag) { $user = $auth->getUid(); $_SESSION["role"] = $user["role"]; $this->http->redirect(WEBROOT . "/home/index"); } else { $this->tpl->assign('error', '账户名或者密码错误'); } } } $this->tpl->display("page/login.html"); }
/** * 加入认证 * @param Swoole $swoole */ function __construct(Swoole $swoole) { parent::__construct($swoole); Swoole::$php->session->start(); Swoole\Auth::login_require(); }
function home() { $this->session->start(); Swoole\Auth::loginRequire(); $this->display('user/home.php'); }
function home() { $this->session->start(); var_dump($_SESSION); Swoole\Auth::login_require(); }
function passwd() { if ($_POST) { if (empty($_POST['repass']) or empty($_POST['oldpass']) or empty($_POST['newpass'])) { return Swoole\JS::js_back('参数不能为空!'); } if ($_POST['repass'] != $_POST['newpass']) { return Swoole\JS::js_back('两次输入的密码不一致!'); } if (strlen($_POST['repass']) < 6) { return Swoole\JS::js_back('密码长度不得少于6位!'); } $u = model('UserInfo')->get($this->uid); if ($u['password'] != Swoole\Auth::mkpasswd($u['username'], $_POST['oldpass'])) { return Swoole\JS::js_back('旧密码错误!'); } $u->password = Swoole\Auth::mkpasswd($u['username'], $_POST['newpass']); $u->save(); return Swoole\JS::js_back('修改成功!'); } else { $this->swoole->tpl->display(); } }
function home() { $this->session->start(); Swoole\Auth::login_require(); }
function chatroom() { session(); Swoole\Auth::$login_url = '/page/login/?'; Swoole\Auth::login_require(); $userInfo = createModel('UserInfo'); $this->swoole->tpl->assign('user', $userInfo->get($_SESSION['user_id'])->get()); $this->swoole->tpl->display(); }
function reset_passwd() { //不是超级用户不能查看修改用户 if ($this->userinfo['usertype'] != 0) { return "access deny"; } if (empty($_GET['id'])) { return \Swoole\JS::js_back("操作不合法"); } $uid = intval($_GET['id']); $user = table('user')->get($uid); if (!$user->exist()) { return \Swoole\JS::js_back("用户不存在"); } $user->password = Swoole\Auth::mkpasswd($user->username, '123456'); if ($user->save()) { return \Swoole\JS::js_back("重置密码成功"); } else { return \Swoole\JS::js_back("重置密码失败,请稍后重试"); } }