<?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(); }
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 register() { if ($_POST) { Swoole::$php->session->start(); if (!isset($_POST['authcode']) or strtoupper($_POST['authcode']) !== $_SESSION['authcode']) { Swoole\JS::js_back('验证码错误!'); exit; } if ($_POST['password'] !== $_POST['repassword']) { Swoole\JS::js_back('两次输入的密码不一致!'); exit; } if (empty($_POST['nickname'])) { Swoole\JS::js_back('昵称不能为空!'); exit; } if (empty($_POST['sex'])) { Swoole\JS::js_back('性别不能为空!'); exit; } $userInfo = createModel('UserInfo'); $login['email'] = trim($_POST['email']); if ($userInfo->exists($login['email'])) { Swoole\JS::js_back('已存在此用户,同一个Email不能注册2次!'); exit; } $login['password'] = Swoole\Auth::mkpasswd($login['email'], $_POST['password']); $login['username'] = $login['email']; // $login['reg_ip'] = Swoole\Http::getIP(); $login['nickname'] = $_POST['nickname']; $login['sex'] = (int) $_POST['sex']; //$login['skill'] = implode(',',$_POST['skill']); // $login['php_level'] = (int)$_POST['php_level']; $login['lastlogin'] = date('Y-m-d h:i:s'); $uid = $userInfo->put($login); $_SESSION['isLogin'] = true; $_SESSION['user_id'] = $uid; $_SESSION['user'] = $login; return Swoole\JS::js_goto('注册成功!', '/person/index/'); } else { require WEBPATH . '/dict/forms.php'; $_forms['sex'] = Swoole\Form::radio('sex', $forms['sex']); //$_forms['level'] = Form::radio('php_level',$forms['level'],''); $this->swoole->tpl->assign('forms', $_forms); $this->swoole->tpl->display(); } }