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 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(); }
<?php require '../config.php'; $php->tpl->template_dir = WEBPATH . '/admin/templates'; session(); //$php->db->debug = true; $table = 'st_admin'; Swoole\Auth::$session_prefix = 'admin_'; Swoole\Auth::$login_url = '/admin/login.php?'; $auth = new Swoole\Auth($php->db, $table); $refer = isset($_GET['refer']) ? $_GET['refer'] : WEBROOT . '/admin/index.php'; if ($auth->isLogin()) { header('location:' . $refer); } if (isset($_POST['username']) and $_POST['username'] != '') { $password = Swoole\Auth::mkpasswd($_POST['username'], $_POST['password']); if ($auth->login($_POST['username'], $password, isset($_POST['auto']) ? 1 : 0)) { $admin_id = $_SESSION['admin_user_id']; $_SESSION['admin_user'] = $php->db->query("select * from {$table} where id={$admin_id}")->fetch(); header('location:' . $refer); } else { Swoole\JS::js_back('用户名或密码错误!'); exit; } } else { $php->tpl->display('admin_login.html'); } if (isset($_GET['logout'])) { $auth->logout(); }
<?php $php->tpl->template_dir = WEBPATH . '/admin/templates'; $php->session->start(); Swoole\Auth::$session_prefix = 'admin_'; Swoole\Auth::$login_url = '/admin/login.php?'; Swoole\Auth::login_require(); $access = array(); require_once "../dict/acl.php";