<?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(); }
/** * 个人用户登录 * @return unknown_type */ function login() { session(); $auth = new Swoole\Auth($this->swoole->db, 'user_login'); $refer = isset($_GET['refer']) ? $_GET['refer'] : WEBROOT . '/person/index/'; if ($auth->isLogin()) { $this->swoole->http->redirect($refer); } if (isset($_POST['username']) and $_POST['username'] != '') { if (!isset($_POST['authcode']) or strtoupper($_POST['authcode']) !== $_SESSION['authcode']) { return Swoole\JS::js_back('验证码错误!'); } $_POST['username'] = strtolower(trim($_POST['username'])); $_POST['password'] = trim($_POST['password']); $password = Swoole\Auth::mkpasswd($_POST['username'], $_POST['password']); if ($auth->login($_POST['username'], $password, isset($_POST['auto']) ? 1 : 0)) { $userinfo = $this->swoole->model->UserInfo->get($_SESSION['user_id'])->get(); $_SESSION['user'] = $userinfo; $this->setLoginStat(); $this->swoole->http->redirect($refer); } else { return Swoole\JS::js_goto('用户名或密码错误!', '/page/login/'); } } else { $this->swoole->tpl->display(); } }