mirror of https://github.com/1099438829/apeblog
更新注册
This commit is contained in:
parent
2d3dececdf
commit
f127397743
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<title>{:web_config('title')}</title>
|
||||
<title>{:web_config('title')}-登录页</title>
|
||||
<meta name="keywords" content="{:web_config('keywords')}">
|
||||
<meta name="description" content="{:web_config('description')}">
|
||||
{include file="public/head" /}
|
||||
|
|
@ -23,7 +23,10 @@
|
|||
<div class="login-main">
|
||||
<div id="login-note">提示</div>
|
||||
<div class="login-form">
|
||||
<div class="login-title"><h3>登录账户</h3></div>
|
||||
<div class="login-title">
|
||||
<h3>登录账户</h3>
|
||||
<span><a href="/index/login/register">注册用户</a></span>
|
||||
</div>
|
||||
<i class="fa fa-user ico-login" aria-hidden="true"></i>
|
||||
<input class="input-login input-user" name="username" type="text" placeholder="请输入用户名/电子邮箱"/>
|
||||
<i class="fa fa-key ico-login" aria-hidden="true"></i>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,151 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="zh">
|
||||
<head>
|
||||
<title>{:web_config('title')}-注册页</title>
|
||||
<meta name="keywords" content="{:web_config('keywords')}">
|
||||
<meta name="description" content="{:web_config('description')}">
|
||||
{include file="public/head" /}
|
||||
<link rel="stylesheet" href="__LIB__/swiper/swiper.min.css"/>
|
||||
<script type="text/javascript" src="__LIB__/swiper/swiper.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<link rel="stylesheet" href="__CSS__/login-plane.css">
|
||||
<div id="app" class="login-background">
|
||||
{include file="public/header" /}
|
||||
<div class="header-zhanwei" style="min-height: 80px; width: 100%"></div>
|
||||
<style>
|
||||
#app {
|
||||
background-image: url(__IMG__/login_backgroud.jpg);
|
||||
}
|
||||
</style>
|
||||
<main class="container">
|
||||
<div id="login-plane">
|
||||
<div class="login-main">
|
||||
<div id="login-note">
|
||||
提示
|
||||
</div>
|
||||
<div class="login-form">
|
||||
<div class="login-title">
|
||||
<h3>注册用户</h3>
|
||||
</div>
|
||||
<i class="fas fa-user ico-login" aria-hidden="true"></i>
|
||||
<input class="input-login input-user" name="username" type="text" placeholder="用户名(只能英文)">
|
||||
<i class="far fa-envelope ico-login" aria-hidden="true"></i>
|
||||
<input class="input-login input-pass" name="email" type="text" placeholder="电子邮箱">
|
||||
|
||||
<i class="fas fa-key ico-login" aria-hidden="true"></i>
|
||||
<input class="input-login input-pass" name="password" type="text" placeholder="密码">
|
||||
<i class="fas fa-key ico-login" aria-hidden="true"></i>
|
||||
<input class="input-login input-pass" name="repassword" type="text" placeholder="重复密码">
|
||||
<div class="code-plane">
|
||||
<img class="img-code" src="/index/login/captcha" alt="">
|
||||
<input class="input-login input-code" name="captcha" type="text" placeholder="验证码">
|
||||
</div>
|
||||
<div class="login-title">
|
||||
<div>已有账户?</div>
|
||||
<a href="/index/login/login">立即登录</a>
|
||||
</div>
|
||||
<div>
|
||||
<button class="login-button" id="btn-login">注册账户</button>
|
||||
</div>
|
||||
<div class="usercenter-info-text">
|
||||
<p><b>注册须知:</b>
|
||||
</p>
|
||||
<p>用户名只支持英文用户名</p>
|
||||
<p>密码不能包含中文,长度8位以上,并且必须包含中英文和数字</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<script>
|
||||
$('.img-code').click(() => {
|
||||
recodeimg();
|
||||
});
|
||||
|
||||
function recodeimg() {
|
||||
$('.img-code').attr('src', "/index/login/captcha?d=" + Math.random());
|
||||
}
|
||||
|
||||
$('input[name="repassword"],input[name="username"],input[name="email"]').click(function () {
|
||||
$(this).removeClass('input-warning');
|
||||
});
|
||||
$('#btn-login').click(() => {
|
||||
var username = $('input[name="username"]').val();
|
||||
var email = $('input[name="email"]').val();
|
||||
var password = $('input[name="password"]').val();
|
||||
var repassword = $('input[name="repassword"]').val();
|
||||
var captcha = $('input[name="captcha"]').val();
|
||||
if (password != repassword) {
|
||||
$('input[name="repassword"]').addClass('input-warning')
|
||||
$('#login-note').text('两次密码输入不一致');
|
||||
$('#login-note').css('visibility', 'visible');
|
||||
setTimeout(function () {
|
||||
$('#login-note').css('visibility', 'hidden');
|
||||
}, 3000);
|
||||
return;
|
||||
}
|
||||
if (username == '' || password == '' || repassword == '' || email == '') {
|
||||
return;
|
||||
}
|
||||
if (!checkEemail(email)) {
|
||||
$('#login-note').text('邮箱格式不正确');
|
||||
$('#login-note').css('visibility', 'visible');
|
||||
$('input[name="email"]').addClass('input-warning')
|
||||
setTimeout(function () {
|
||||
$('#login-note').css('visibility', 'hidden');
|
||||
}, 3000);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isChinese(password) || isChinese(username)) {
|
||||
addarelt('密码和用户名不支持中文', 'erro');
|
||||
return;
|
||||
}
|
||||
if (!haveNumandLetter(password)) {
|
||||
addarelt('密码必须包含字母和数字', 'erro');
|
||||
return;
|
||||
}
|
||||
if (password.length < 8) {
|
||||
addarelt('密码必须大于8位', 'erro');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$('#login-note').text('正在注册,请稍后');
|
||||
$('#login-note').css('visibility', 'visible');
|
||||
$.post('/index/login/login', {
|
||||
action: 'corepress_reguser',
|
||||
user: user,
|
||||
email: email,
|
||||
password: password,
|
||||
captcha: captcha
|
||||
}, (data) => {
|
||||
var obj = JSON.parse(data);
|
||||
if (obj) {
|
||||
if (obj.code === 1) {
|
||||
$('#login-note').text('注册成功,跳转登陆页面');
|
||||
window.location.href = 'https://www.cnesa.cn/login';
|
||||
} else if (obj.code === 2) {
|
||||
$('#login-note').text(obj.msg);
|
||||
} else if (obj.code === 0) {
|
||||
$('#login-note').text(obj.msg);
|
||||
recodeimg();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function checkEmail(email) {
|
||||
var myreg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
|
||||
if (!myreg.test(email)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{include file="public/footer"/}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Reference in New Issue