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(); } }
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 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("重置密码失败,请稍后重试"); } }