mirror of https://github.com/1099438829/apeblog
完善部分代码
This commit is contained in:
parent
61967bb957
commit
4f23f09295
|
|
@ -90,7 +90,7 @@ class File extends AuthController
|
|||
break;
|
||||
case 'document':
|
||||
$fileSize = 5 * 1024 * 1024;
|
||||
$fileExt = 'pdf,doc,docx';
|
||||
$fileExt = 'doc,docx,pdf,xls,xlsx,ppt,pptx,txt,wps';
|
||||
break;
|
||||
case 'image':
|
||||
$fileSize = 5 * 1024 * 1024;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use think\db\exception\DbException;
|
|||
use think\db\exception\ModelNotFoundException;
|
||||
use think\facade\Session;
|
||||
use mailer\Mailer;
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 用户管理
|
||||
|
|
@ -82,7 +83,6 @@ class User extends BaseModel
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置登录信息
|
||||
* @param $info
|
||||
|
|
@ -183,4 +183,54 @@ class User extends BaseModel
|
|||
$data = $data ? $data->toArray() : [];
|
||||
return compact("data", "count");
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码重置
|
||||
* @param string $userid
|
||||
* @param $password
|
||||
* @return bool|void
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public static function resetPassword(string $userid, $password)
|
||||
{
|
||||
$info = self::where('id', '=', $userid)->find();
|
||||
if (!$info) return self::setErrorInfo("用户不存在");
|
||||
$info['password'] = md5(md5($password));
|
||||
$info['status'] = 2;
|
||||
$info['remark'] = '重置密码成功!';
|
||||
$info['update_time'] = time();
|
||||
$info['create_time'] = time();
|
||||
$info['is_admin'] = Data::USER_IS_ADMIN_NO;
|
||||
$info['update_time'] = time();
|
||||
$info['is_admin'] = Data::USER_IS_ADMIN_NO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 丢失密码
|
||||
* @param $username
|
||||
* @return bool
|
||||
* @author 木子的忧伤
|
||||
* @date 2022-01-03 3:48
|
||||
*/
|
||||
public static function lostPassword($username)
|
||||
{
|
||||
$model = new self;
|
||||
$info = self::where('username|email', '=', $username)->find();
|
||||
if ($info) return self::setErrorInfo("账号或邮箱不存在,请检查后重试");
|
||||
//生成密码重置key 设置有效时间 过期无效
|
||||
$key = md5($info->email . rand(1000,99999));
|
||||
cache($key,"----",24*60*60); //缓存1天过后则失效
|
||||
//发送邮箱
|
||||
$content = "您好,您在本网站进行重置密码操作,请点击如下链接进入重置密码页面。【本链接24小时内容有效,如果不是您的操作,请忽略】
|
||||
/forget?action=rested&key={$key}&id=20";
|
||||
$mailer = new Mailer();
|
||||
$mailer->from(system_config('title'))
|
||||
->to($info->email)
|
||||
->subject(system_config('title').'重置密码验证')
|
||||
->text($content)
|
||||
->send();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,8 +7,10 @@
|
|||
namespace app\index\controller;
|
||||
|
||||
use app\admin\extend\Util;
|
||||
use app\common\model\Document;
|
||||
use app\common\model\User as userModel;
|
||||
use Exception;
|
||||
use think\App;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\DbException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
|
|
@ -16,6 +18,18 @@ use think\Response;
|
|||
|
||||
class User extends Base
|
||||
{
|
||||
|
||||
/**
|
||||
* 构造方法 初始化一些参数
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
if (!web_config('is_register')) {
|
||||
$this->error('登录未启用,请联系管理员!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录
|
||||
* @return string
|
||||
|
|
@ -23,9 +37,6 @@ class User extends Base
|
|||
*/
|
||||
public function login()
|
||||
{
|
||||
if (!web_config('is_register')){
|
||||
$this->error('登录未启用,请联系管理员!');
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
|
@ -38,9 +49,6 @@ class User extends Base
|
|||
*/
|
||||
public function verify()
|
||||
{
|
||||
if (!web_config('is_register')){
|
||||
return app("json")->fail('非法操作!');
|
||||
}
|
||||
list($username, $password, $captcha) = Util::postMore(['username', 'password', 'captcha'], null, true);
|
||||
if (empty($username) || empty($password)) return app("json")->fail("账号、密码和验证码不能为空!");
|
||||
// 验证码验证
|
||||
|
|
@ -57,9 +65,6 @@ class User extends Base
|
|||
*/
|
||||
public function register()
|
||||
{
|
||||
if (!web_config('is_register')){
|
||||
$this->error('注册未启用,请联系管理员!');
|
||||
}
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
|
@ -70,21 +75,18 @@ class User extends Base
|
|||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function registerVerify()
|
||||
public function register_verify()
|
||||
{
|
||||
if (!web_config('is_register')){
|
||||
return app("json")->fail('非法操作!');
|
||||
}
|
||||
list($username, $email, $password,$captcha) = Util::postMore(['username','email', 'password', 'captcha'], null, true);
|
||||
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 (!empty(web_config('register_black_list')) && in_array($username,explode(',',web_config('register_black_list')))){
|
||||
if (!empty(web_config('register_black_list')) && in_array($username, explode(',', web_config('register_black_list')))) {
|
||||
return app("json")->fail("账号不合法,请更换后重试");
|
||||
}
|
||||
// 验证登录
|
||||
if (!userModel::register($username,$email, $password)) return app("json")->fail(userModel::getErrorInfo());
|
||||
if (!userModel::register($username, $email, $password)) return app("json")->fail(userModel::getErrorInfo());
|
||||
return app("json")->success("注册成功!我们给您邮箱发送了一封激活邮件,请按照邮件提示激活用户");
|
||||
}
|
||||
|
||||
|
|
@ -98,6 +100,30 @@ class User extends Base
|
|||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ModelNotFoundException
|
||||
* @throws DbException
|
||||
* @throws DataNotFoundException
|
||||
*/
|
||||
public function forget_verify()
|
||||
{
|
||||
list($action, $username, $key, $password) = Util::postMore(['action', 'username', 'key', 'pwd'], null, true);
|
||||
//做验证
|
||||
switch ($action) {
|
||||
case'rested':
|
||||
//重置密码
|
||||
if (!userModel::resetPassword($username, $password)) return app("json")->fail(userModel::getErrorInfo());
|
||||
return app("json")->success("密码重置成功!");
|
||||
case 'LastPass':
|
||||
// 验证码验证
|
||||
if (!captcha_check($key)) return app("json")->fail("验证码不正确!");
|
||||
//丢失密码 发送邮件
|
||||
if (!userModel::lostPassword($username)) return app("json")->fail(userModel::getErrorInfo());
|
||||
return app("json")->success("发送成功!我们给您邮箱发送了一封激活邮件,请按照邮件提示激活用户");
|
||||
}
|
||||
return app("json")->fail("非法访问!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登陆
|
||||
* @return mixed
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
function getQueryVariable(variable) {
|
||||
var query = window.location.search.substring(1);
|
||||
var vars = query.split("&");
|
||||
for (var i = 0; i < vars.length; i++) {
|
||||
var pair = vars[i].split("=");
|
||||
if (pair[0] == variable) {
|
||||
let query = window.location.search.substring(1);
|
||||
let vars = query.split("&");
|
||||
for (let i = 0; i < vars.length; i++) {
|
||||
let pair = vars[i].split("=");
|
||||
if (pair[0] === variable) {
|
||||
return pair[1];
|
||||
}
|
||||
}
|
||||
|
|
@ -35,13 +35,12 @@ function replaceTag(str) {
|
|||
}
|
||||
|
||||
function addarelt(msg, type) {
|
||||
var icon = '<i class="fas fa-info-circle" style="color: #515a6e"></i>';
|
||||
let icon = '<i class="fas fa-info-circle" style="color: #515a6e"></i>';
|
||||
if (type == 'succ') {
|
||||
icon = '<i class="fas fa-check-circle" style="color:#19be6b;"></i>'
|
||||
} else if (type == 'erro') {
|
||||
icon = '<i class="fas fa-times-circle" style="color:#ed4014;"></i>'
|
||||
}
|
||||
var msg_id = '';
|
||||
$('body').append('<div class="corepress-alert"><div class="corepress-alert-main">' + icon + msg + '</div></div>');
|
||||
setTimeout(function () {
|
||||
$('.corepress-alert-main').addClass('corepress-alert-main-show');
|
||||
|
|
|
|||
|
|
@ -0,0 +1,116 @@
|
|||
<!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" style="width: 100%;">
|
||||
<div id="login-note">
|
||||
提示
|
||||
</div>
|
||||
<div class="login-form">
|
||||
<div class="login-title">
|
||||
<h3>找回密码</h3>
|
||||
</div>
|
||||
<i class="fa fa-user ico-login" aria-hidden="true"></i>
|
||||
<input class="input-login input-pass" name="user" type="text" placeholder="请输入用户名或者邮箱">
|
||||
<div class="code-plane">
|
||||
<img class="img-code" src="/index/user/captcha">
|
||||
<input class="input-login input-code" name="code" type="text" placeholder="验证码">
|
||||
</div>
|
||||
<div>
|
||||
<button class="login-button" id="btn-getlostpass">找回密码</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<script>
|
||||
$('#btn-getlostpass').click(() =>{
|
||||
getlostpass();
|
||||
})
|
||||
|
||||
$('#btn-resetpwd').click(() =>{
|
||||
let pwd = $('input[name="pwd"]').val();
|
||||
let repwd = $('input[name="repwd"]').val();
|
||||
if (pwd === '' || repwd === '') {
|
||||
addarelt('请输入完整内容', 'erro');
|
||||
return;
|
||||
}
|
||||
if (pwd !== repwd) {
|
||||
addarelt('两次密码不一致', 'erro');
|
||||
|
||||
} else {
|
||||
$('#login-note').css('visibility', 'visible');
|
||||
$('#login-note').text('验证中,请稍后');
|
||||
$.post('/index/user/forget_verify', {
|
||||
action: "rested",
|
||||
userid: "",
|
||||
key: "",
|
||||
pwd: pwd
|
||||
}, (data) =>{
|
||||
var obj = JSON.parse(data);
|
||||
if (obj.code === 1) {
|
||||
$('#login-note').text(obj.msg);
|
||||
} else {
|
||||
$('#login-note').text(obj.msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function getlostpass() {
|
||||
var user = $('input[name="user"]').val();
|
||||
var key = $('input[name="code"]').val();
|
||||
$('#login-note').text('检测中,请稍后');
|
||||
$('#login-note').css('visibility', 'visible');
|
||||
|
||||
$.post('/index/user/forget_verify', {
|
||||
action: 'LastPass',
|
||||
user: user,
|
||||
key: key
|
||||
},
|
||||
(data) =>{
|
||||
let obj = JSON.parse(data);
|
||||
if (obj) {
|
||||
if (obj.code === 1) {
|
||||
$('#login-note').css('visibility', 'visible');
|
||||
$('#login-note').text(obj.msg);
|
||||
} else {
|
||||
$('#login-note').css('visibility', 'visible');
|
||||
$('#login-note').text(obj.msg);
|
||||
recodeimg();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
$('.img-code').click(() =>{
|
||||
recodeimg();
|
||||
});
|
||||
|
||||
function recodeimg() {
|
||||
$('.img-code').attr('src',"/index/user/captcha?d=" + Math.random());
|
||||
}
|
||||
</script>
|
||||
{include file="public/footer"/}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
<label>
|
||||
<input type="checkbox" id="remember" name="remember" value="true"/>
|
||||
记住我的登录状态</label>
|
||||
<a href="wp-login-lostpassword.html">忘记密码?</a>
|
||||
<a href="/index/user/forget">忘记密码?</a>
|
||||
</div>
|
||||
<!-- <div class="thirdparty-plane">-->
|
||||
<!-- <span class="login-thirdparty-btn">-->
|
||||
|
|
@ -100,17 +100,13 @@
|
|||
$("#login-note").text(data.msg);
|
||||
recodeimg();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function recodeimg() {
|
||||
$(".img-code").attr(
|
||||
"src",
|
||||
"/index/user/captcha?d=" + Math.random()
|
||||
);
|
||||
$('.img-code').attr('src',"/index/user/captcha?d=" + Math.random());
|
||||
}
|
||||
</script>
|
||||
{include file="public/footer"/}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@
|
|||
<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="password" placeholder="密码">
|
||||
<i class="fas fa-key ico-login" aria-hidden="true"></i>
|
||||
|
|
@ -64,7 +63,7 @@
|
|||
});
|
||||
|
||||
function recodeimg() {
|
||||
$('.img-code').attr('src', "/index/user/captcha?d=" + Math.random());
|
||||
$('.img-code').attr('src',"/index/user/captcha?d=" + Math.random());
|
||||
}
|
||||
|
||||
$('input[name="repassword"],input[name="username"],input[name="email"]').click(function () {
|
||||
|
|
@ -111,10 +110,9 @@
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
$('#login-note').text('正在注册,请稍后');
|
||||
$('#login-note').css('visibility', 'visible');
|
||||
$.post('/index/user/registerVerify', {
|
||||
$.post('/index/user/register_verify', {
|
||||
username: username,
|
||||
email: email,
|
||||
password: password,
|
||||
|
|
|
|||
Loading…
Reference in New Issue