diff --git a/app/admin/controller/File.php b/app/admin/controller/File.php index 95bc92c..3ffbc09 100644 --- a/app/admin/controller/File.php +++ b/app/admin/controller/File.php @@ -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; diff --git a/app/common/model/User.php b/app/common/model/User.php index 7955b49..d80482b 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -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; + } } \ No newline at end of file diff --git a/app/index/controller/User.php b/app/index/controller/User.php index c3a4ca5..8d4fc43 100644 --- a/app/index/controller/User.php +++ b/app/index/controller/User.php @@ -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 diff --git a/public/template/default/pc/js/tools.js b/public/template/default/pc/js/tools.js index dea24ff..bfbf95e 100644 --- a/public/template/default/pc/js/tools.js +++ b/public/template/default/pc/js/tools.js @@ -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 = ''; + let icon = ''; if (type == 'succ') { icon = '' } else if (type == 'erro') { icon = '' } - var msg_id = ''; $('body').append('
' + icon + msg + '
'); setTimeout(function () { $('.corepress-alert-main').addClass('corepress-alert-main-show'); diff --git a/public/template/default/pc/user/forget.html b/public/template/default/pc/user/forget.html new file mode 100644 index 0000000..984b168 --- /dev/null +++ b/public/template/default/pc/user/forget.html @@ -0,0 +1,116 @@ + + + + {:web_config('title')}-登录页 + + + {include file="public/head" /} + + + + + +
+ {include file="public/header" /} +
+ +
+
+ +
+
+ + {include file="public/footer"/} +
+ + diff --git a/public/template/default/pc/user/login.html b/public/template/default/pc/user/login.html index 4fdc43a..c3875ee 100644 --- a/public/template/default/pc/user/login.html +++ b/public/template/default/pc/user/login.html @@ -40,7 +40,7 @@ - 忘记密码? + 忘记密码? @@ -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()); } {include file="public/footer"/} diff --git a/public/template/default/pc/user/register.html b/public/template/default/pc/user/register.html index 6225d95..1ff9fab 100644 --- a/public/template/default/pc/user/register.html +++ b/public/template/default/pc/user/register.html @@ -32,7 +32,6 @@ - @@ -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,