mirror of https://github.com/1099438829/apeblog
修正前台注册问题
This commit is contained in:
parent
b660823772
commit
0c450018f0
|
|
@ -32,4 +32,9 @@ class Data
|
|||
//前台用户session
|
||||
const SESSION_KEY_USER_ID = 'user_id';
|
||||
const SESSION_KEY_USER_INFO = 'user_info';
|
||||
|
||||
//用户是否是管理员
|
||||
const USER_IS_ADMIN_YES = 1;
|
||||
const USER_IS_ADMIN_NO = 0;
|
||||
|
||||
}
|
||||
|
|
@ -23,18 +23,18 @@ class User extends BaseModel
|
|||
|
||||
/**
|
||||
* 登录
|
||||
* @param $name
|
||||
* @param $pwd
|
||||
* @param $username
|
||||
* @param $password
|
||||
* @return bool
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public static function login(string $name, string $pwd): bool
|
||||
public static function login(string $username, string $password): bool
|
||||
{
|
||||
$info = self::where("username|email|tel", "=", $name)->find();
|
||||
$info = self::where("username|email|tel", "=", $username)->find();
|
||||
if (!$info) return self::setErrorInfo("登录账号不存在");
|
||||
if ($info['password'] != md5(md5($pwd))) return self::setErrorInfo("密码不正确!");
|
||||
if ($info['password'] != md5(md5($password))) return self::setErrorInfo("密码不正确!");
|
||||
if ($info['status'] == 2) return self::setErrorInfo("账号已被冻结!");
|
||||
self::setLoginInfo($info);
|
||||
return true;
|
||||
|
|
@ -42,9 +42,9 @@ class User extends BaseModel
|
|||
|
||||
/**
|
||||
* 注册
|
||||
* @param string $name
|
||||
* @param string $username
|
||||
* @param string $email
|
||||
* @param string $pwd
|
||||
* @param string $password
|
||||
* @return bool
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
|
|
@ -52,14 +52,25 @@ class User extends BaseModel
|
|||
* @author 李玉坤
|
||||
* @date 2022-01-16 1:33
|
||||
*/
|
||||
public static function register(string $name, string $email,string $pwd): bool
|
||||
public static function register(string $username, string $email, string $password): 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;
|
||||
$info = self::where('username', '=', $username)->whereOr('email', '=', $email)->find();
|
||||
if ($info) return self::setErrorInfo("账号已存在,请更换用户名重试");
|
||||
$data = [
|
||||
'username' => $username,
|
||||
'email' => $email,
|
||||
'password' => md5(md5($password)),
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
'is_admin' => Data::USER_IS_ADMIN_NO
|
||||
];
|
||||
$res = self::insert($data, true);
|
||||
if (!$res) {
|
||||
return self::setErrorInfo("账号注册失败,请稍后再试");
|
||||
} else {
|
||||
$info = self::where('id', "=", $res)->find();
|
||||
return self::setLoginInfo($info);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -74,14 +74,12 @@ class Login extends Base
|
|||
*/
|
||||
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("账号、密码和验证码不能为空!");
|
||||
list($username, $email, $password,$captcha) = Util::postMore(['username','email', 'password', 'captcha'], null, true);
|
||||
if (empty($username) || empty($email) || empty($password) || 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());
|
||||
if (!userModel::register($username,$email, $password)) return app("json")->fail(userModel::getErrorInfo());
|
||||
return app("json")->success("登录成功!");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
#login-plane,.msgbox{display:flex;justify-content:center}.container-main{margin-top:70px}.reg-plane-main{max-width:440px;margin:auto;background:#fff;padding:10px}.login-main{position:relative;max-width:440px;background:#fff;box-shadow:0 4px 16px rgba(0,0,0,.15);margin:30px;border-radius:4px;overflow:hidden}.login-form{padding:10px 20px 20px 20px}.input-login{display:inline-block;width:100%;height:37px;padding:10px 10px 10px 34px;line-height:16px;font-size:14px;color:#333;font-weight:400;border:none;border-bottom:1px solid #ddd;background:none;outline:0;box-sizing:border-box;margin-bottom:10px}.input-warning{border-bottom-color:red}#login-note{background:#fffbe5;color:#5c3c00;padding:8px;visibility:hidden}.code-plane{display:flex}.ico-login{position:relative;top:30px;font-size:20px;left:8px;color:#999}.login-button{margin-top:20px;font-weight:400;text-align:center;vertical-align:middle;touch-action:manipulation;user-select:none;width:100%;font-size:16px;color:#fff;background:#3ca5f6;border:0;margin-bottom:5px;border-radius:3px;text-indent:0;outline:0;padding:10px 16px;display:block;cursor:pointer}.login-button:active{box-shadow:inset 0 3px 5px rgba(0,0,0,.125)}.msgbox-content{position:absolute;display:inline-block;background:#f0f9eb;color:#6bc440;padding:10px 50px;border-radius:4px;vertical-align:middle;border:2px solid #e1f3d8;font-size:14px;top:0;z-index:999;transition:0.5s;opacity:0}.msgbox-content-show{top:10%;visibility:visible;opacity:1}.login-title{display:flex;justify-content:space-between;align-items:center}@media screen and (max-width:400px){body .login-main{box-shadow:none;margin:0}}.login-background{background-repeat:no-repeat!important;background-size:cover!important}.usercenter-plane{display:flex;justify-content:space-between;margin:10px}.usercenter-left{flex-basis:30%}.usercenter-right{flex-basis:70%;background-color:#fff;padding:10px;margin-left:10px}.usercenter-userinfo{margin-bottom:10px;background-color:#fff;padding:30px 10px;text-align:center}.usercenter-menu{padding:10px;background-color:#fff}.usercenter-info-item{margin-top:10px;display:flex;align-content:flex-start}.usercenter-form-input{padding:6px;border:1px solid #dcdfe6;outline:none;border-radius:4px;transition:border-color .2s cubic-bezier(.645,.045,.355,1)}.usercenter-info-title{flex-basis:20%;max-width:200px;margin-bottom:30px;font-size:14px;color:#999;user-select:none}.usercenter-info-text{font-size:14px;color:#999;user-select:none}.usercenter-info-text p{margin:6px 0}.usercenter-info-h3{margin:10px 0 30px 0;font-weight:300}.usercenter-form-input:focus{border-color:var(--Maincolor)}.usercenter-info-login{color:#999}.usercenter-info-body{flex-basis:70%}.usercenter-form-description{width:100%}.usercenter-info-description{margin-top:0!important;font-size:14px;color:#999}.usercenter-menu-item{padding:6px 0;position:relative;cursor:pointer}.usercenter-menu-item-active{color:var(--Maincolor)}.usercenter-a{color:var(--Maincolor);cursor:pointer;margin-left:10px}.send-mail-btn{width:80px!important}.layui-layer-content #avatar-plane{margin:auto}.layui-layer-content{padding:10px}.thirdparty-plane{padding:20px 0 10px 0}.thirdparty-plane img{width:20px;margin-bottom:4px}.login-thirdparty-btn{padding:2px;border:1px solid #d7dae2;border-radius:3px}.login-thirdparty-btn a{color:unset;font-size:14px}.userinfo-infoplnae{background-color:#fff;text-align:center;width:100%;border-radius:3px;padding:10px}.userinfo-metas-plane{background-color:#fff;width:100%;border-radius:3px;text-align:center;margin-top:10px;padding:10px}.userinfo-tabs{display:flex;justify-content:center;font-size:16px}.userinfo-tabs-item{padding:0 20px;position:relative;transition:.3s;cursor:pointer}.userinfo-tabs-item:after{position:absolute;height:4px;content:"";display:block;background-color:var(--Maincolor);width:0;left:50%;bottom:-10px;visibility:hidden;opacity:0;transition:all .3s}.userinfo-tabs-item:hover.userinfo-tabs-item:after{visibility:visible;opacity:1;width:50%;left:25%}.userinfo-tabs-item-active:after{visibility:visible;opacity:1;width:50%;left:25%}
|
||||
#login-plane,.msgbox{display:flex;justify-content:center}.container-main{margin-top:70px}.reg-plane-main{max-width:440px;margin:auto;background:#fff;padding:10px}.login-main{position:relative;max-width:440px;background:#fff;box-shadow:0 4px 16px rgba(0,0,0,.15);margin:30px;border-radius:2px;overflow:hidden}.login-form{padding:10px 20px 20px 20px}.input-login{display:inline-block;width:100%;height:37px;padding:10px 10px 10px 34px;line-height:16px;font-size:14px;color:#333;font-weight:400;border:0;border-bottom:1px solid #ddd;background:0;outline:0;box-sizing:border-box;margin-bottom:10px}.input-warning{border-bottom-color:red}#login-note{background:#fffbe5;color:#5c3c00;padding:8px;visibility:hidden}.code-plane{display:flex}.ico-login{position:relative;top:28px;font-size:16px;left:8px;color:#999}.login-button{margin-top:20px;font-weight:400;text-align:center;vertical-align:middle;touch-action:manipulation;user-select:none;width:100%;font-size:16px;color:#fff;background:#3ca5f6;border:0;margin-bottom:5px;border-radius:3px;text-indent:0;outline:0;padding:10px 16px;display:block;cursor:pointer}.login-button:active{box-shadow:inset 0 3px 5px rgba(0,0,0,.125)}.msgbox-content{position:absolute;display:inline-block;background:#f0f9eb;color:#6bc440;padding:10px 50px;border-radius:4px;vertical-align:middle;border:2px solid #e1f3d8;font-size:14px;top:0;z-index:999;transition:.5s;opacity:0}.msgbox-content-show{top:10%;visibility:visible;opacity:1}.login-title{display:flex;justify-content:space-between;align-items:center;font-size:14px}@media screen and (max-width:400px){body .login-main{box-shadow:none;margin:0}}.usercenter-plane{display:flex;justify-content:space-between;margin:10px}.usercenter-left{flex-basis:30%}.usercenter-right{flex-basis:70%;background-color:#fff;padding:10px;margin-left:10px}.usercenter-userinfo{margin-bottom:10px;background-color:#fff;padding:30px 10px;text-align:center}.usercenter-menu{padding:10px;background-color:#fff}.usercenter-info-item{margin-top:10px;display:flex;align-content:flex-start}.usercenter-form-input{padding:6px;border:1px solid #dcdfe6;outline:0;border-radius:4px;transition:border-color .2s cubic-bezier(.645,.045,.355,1)}.usercenter-info-title{flex-basis:20%;max-width:200px;margin-bottom:30px;font-size:14px;color:#999;user-select:none}.usercenter-info-text{font-size:14px;color:#999;user-select:none}.usercenter-info-text p{margin:6px 0}.usercenter-info-h3{margin:10px 0 30px 0;font-weight:300}.usercenter-form-input:focus{border-color:var(--Maincolor)}.usercenter-info-login{color:#999}.usercenter-info-body{flex-basis:70%}.usercenter-form-description{width:100%}.usercenter-info-description{margin-top:0!important;font-size:14px;color:#999}.usercenter-menu-item{padding:6px 0;position:relative;cursor:pointer}.img-code{padding-bottom:10px}.usercenter-menu-item-active{color:var(--Maincolor)}.usercenter-a{color:var(--Maincolor);cursor:pointer;margin-left:10px}.send-mail-btn{width:80px!important}.layui-layer-content #avatar-plane{margin:auto;padding:10px}.thirdparty-plane{padding:20px 0 10px 0}.thirdparty-plane img{width:20px;margin-bottom:4px}.login-thirdparty-btn{padding:2px;border:1px solid #d7dae2;border-radius:3px}.login-thirdparty-btn a{color:unset;font-size:14px}.userinfo-infoplnae{background-color:#fff;text-align:center;width:100%;border-radius:3px;padding:10px}.userinfo-metas-plane{background-color:#fff;width:100%;border-radius:3px;text-align:center;margin-top:10px;padding:10px}.userinfo-tabs{display:flex;justify-content:center;font-size:16px}.userinfo-tabs-item{padding:0 20px;position:relative;transition:.3s;cursor:pointer}.userinfo-tabs-item:after{position:absolute;height:4px;content:"";display:block;background-color:var(--Maincolor);width:0;left:50%;bottom:-10px;visibility:hidden;opacity:0;transition:all .3s}.userinfo-tabs-item:hover.userinfo-tabs-item:after{visibility:visible;opacity:1;width:50%;left:25%}.userinfo-tabs-item-active:after{visibility:visible;opacity:1;width:50%;left:25%}
|
||||
|
|
@ -34,9 +34,9 @@
|
|||
<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="密码">
|
||||
<input class="input-login input-pass" name="password" type="password" placeholder="密码">
|
||||
<i class="fas fa-key ico-login" aria-hidden="true"></i>
|
||||
<input class="input-login input-pass" name="repassword" type="text" placeholder="重复密码">
|
||||
<input class="input-login input-pass" name="repassword" type="password" 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="验证码">
|
||||
|
|
@ -88,7 +88,7 @@
|
|||
if (username == '' || password == '' || repassword == '' || email == '') {
|
||||
return;
|
||||
}
|
||||
if (!checkEemail(email)) {
|
||||
if (!checkEmail(email)) {
|
||||
$('#login-note').text('邮箱格式不正确');
|
||||
$('#login-note').css('visibility', 'visible');
|
||||
$('input[name="email"]').addClass('input-warning')
|
||||
|
|
@ -114,22 +114,18 @@
|
|||
|
||||
$('#login-note').text('正在注册,请稍后');
|
||||
$('#login-note').css('visibility', 'visible');
|
||||
$.post('/index/login/login', {
|
||||
action: 'corepress_reguser',
|
||||
user: user,
|
||||
$.post('/index/login/registerVerify', {
|
||||
username: username,
|
||||
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);
|
||||
if (data) {
|
||||
if (data.status === 200) {
|
||||
$('#login-note').text('注册成功,跳转首页');
|
||||
window.location.href = '/';
|
||||
} else {
|
||||
$('#login-note').text(data.msg);
|
||||
recodeimg();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue