From f127397743ad479c089412051a5b2756def4b0f5 Mon Sep 17 00:00:00 2001 From: liyukun <1099438829@qq.com> Date: Sun, 16 Jan 2022 01:35:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/User.php | 23 +++ app/index/controller/Login.php | 25 +++ public/install/index.php | 4 +- public/template/default/pc/login/login.html | 7 +- .../template/default/pc/login/register.html | 151 ++++++++++++++++++ 5 files changed, 206 insertions(+), 4 deletions(-) create mode 100644 public/template/default/pc/login/register.html diff --git a/app/common/model/User.php b/app/common/model/User.php index b34f816..9119095 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -40,6 +40,29 @@ class User extends BaseModel return true; } + /** + * 注册 + * @param string $name + * @param string $email + * @param string $pwd + * @return bool + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @author 李玉坤 + * @date 2022-01-16 1:33 + */ + public static function register(string $name, string $email,string $pwd): bool + { + $info = self::where("username|email|tel", "=", $name)->find(); + if (!$info) return self::setErrorInfo("登录账号不存在"); + if ($info['password'] != md5(md5($pwd))) return self::setErrorInfo("密码不正确!"); + if ($info['status'] == 2) return self::setErrorInfo("账号已被冻结!"); + self::setLoginInfo($info); + return true; + } + + /** * 设置登录信息 * @param $info diff --git a/app/index/controller/Login.php b/app/index/controller/Login.php index 482a56c..32976e7 100644 --- a/app/index/controller/Login.php +++ b/app/index/controller/Login.php @@ -57,9 +57,34 @@ class Login extends Base */ public function register() { + //清除可能存在的栏目分类树id + cache(Data::CURR_CATEGORY_PATENT_ID, false); + //模板兼容性标签 + $this->assign('id', false); + $this->assign('cid', false); return $this->fetch(); } + /** + * 验证登录 + * @return mixed + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function registerVerify() + { + list($username, $email, $password, $repassword,$captcha) = Util::postMore(['username','email', 'password', 'repassword','captcha'], null, true); + if (empty($username) || empty($email) || empty($password) || empty($repassword) || empty($captcha)) return app("json")->fail("账号、密码和验证码不能为空!"); + // 验证码验证 + if (!captcha_check($captcha)) return app("json")->fail("验证码不正确!"); + //密码 和 确认密码 + if ($password != $repassword) return app("json")->fail("两次密码不一致!"); + // 验证登录 + if (!userModel::login($username, $password)) return app("json")->fail(userModel::getErrorInfo()); + return app("json")->success("登录成功!"); + } + /** * 忘记密码 * @return string diff --git a/public/install/index.php b/public/install/index.php index d70aa29..8ffc835 100644 --- a/public/install/index.php +++ b/public/install/index.php @@ -335,8 +335,8 @@ switch ($step) { mysqli_query($conn, "truncate table {$dbPrefix}user"); $addAdminSql = "INSERT INTO `{$dbPrefix}admin` (`id`, `uid`,`username`,`realname`, `nickname`, `avatar`, `password`, `role_id`, `status`, `create_time`, `create_user`) VALUES" . "(1, 1,'" . $username . "', '超级管理员' ,'超级管理员','/static/admin/images/logo2.png','" . $password . "', 1, 1, $time, '1')"; - $addUserSql = "INSERT INTO `{$dbPrefix}user` (`id`, `username`, `nickname`, `password`, `status`, `is_admin`, `create_time`) VALUES " . - "(1,'" . $username . "', '超级管理员' ,'" . $password . "', 1, 1, $time);"; + $addUserSql = "INSERT INTO `{$dbPrefix}user` (`id`, `username`, `nickname`, `avatar`, `password`, `status`, `is_admin`, `create_time`) VALUES " . + "(1,'" . $username . "', '超级管理员' ,'/static/admin/images/logo2.png','" . $password . "', 1, 1, $time);"; //插入前台用户和管理员 mysqli_query($conn, $addUserSql); $res = mysqli_query($conn, $addAdminSql); diff --git a/public/template/default/pc/login/login.html b/public/template/default/pc/login/login.html index 95590f0..3a46821 100644 --- a/public/template/default/pc/login/login.html +++ b/public/template/default/pc/login/login.html @@ -1,7 +1,7 @@ - {:web_config('title')} + {:web_config('title')}-登录页 {include file="public/head" /} @@ -23,7 +23,10 @@
提示
- + diff --git a/public/template/default/pc/login/register.html b/public/template/default/pc/login/register.html new file mode 100644 index 0000000..cf76e01 --- /dev/null +++ b/public/template/default/pc/login/register.html @@ -0,0 +1,151 @@ + + + + {:web_config('title')}-注册页 + + + {include file="public/head" /} + + + + + + + +