diff --git a/app/controller/user/Base.php b/app/controller/user/Base.php index fd20bd79..59cd688e 100644 --- a/app/controller/user/Base.php +++ b/app/controller/user/Base.php @@ -16,9 +16,11 @@ use app\model\Form; class Base extends BaseC { + protected $outAuthUrl = ['user/index/login', 'user/index/logout', 'user/index/verify', 'user/index/register', 'user/index/forget', 'user/index/resetpasswd']; + protected function initialize() { $url = str_replace(".", "/", strtolower($this->request->controller())) . '/' . $this->request->action(); - if (!is_login() && !in_array($url, array('user/index/login', 'user/index/logout', 'user/index/verify', 'user/index/register'))) { + if (!is_login() && !in_array($url, $this->outAuthUrl)) { $this->redirect('/user/index/login'); } diff --git a/app/controller/user/Index.php b/app/controller/user/Index.php index ed74391b..e361dc81 100644 --- a/app/controller/user/Index.php +++ b/app/controller/user/Index.php @@ -8,6 +8,9 @@ // +---------------------------------------------------------------------- namespace app\controller\user; +use app\model\Member; +use think\facade\Session; + /** * @title 用户中心 */ @@ -26,7 +29,19 @@ class Index extends Base { * @return [type] [description] */ public function login() { - return $this->fetch(); + if ($this->request->isAjax()) { + try { + $userinfo = (new Member())->login($this->request); + if ($userinfo) { + Session::set('userInfo', $userinfo); + return $this->success('登录成功!', url('/user/index/index')); + } + } catch (Exception $e) { + return $this->error($e->getError(), ''); + } + }else{ + return $this->fetch(); + } } /** @@ -34,7 +49,8 @@ class Index extends Base { * @return [type] [description] */ public function logout() { - return $this->fetch(); + Session::delete('userInfo'); + $this->redirect('/user/index/login'); } /** @@ -42,7 +58,16 @@ class Index extends Base { * @return [type] [description] */ public function register() { - return $this->fetch(); + if ($this->request->isAjax()) { + $result = (new Member())->register($this->request); + if (false !== $result) { + return $this->success("注册成功!", url('/user/index/login')); + }else{ + return $this->error("注册失败!"); + } + }else{ + return $this->fetch(); + } } /** @@ -50,7 +75,30 @@ class Index extends Base { * @return [type] [description] */ public function forget() { - return $this->fetch(); + if ($this->request->isAjax()) { + $data = $this->request->post(); + $map = []; + if (!$data['username'] || !$data['email']) { + return $this->error("请完整填写信息!"); + } + $map[] = ['username', '=', $data['username']]; + $map[] = ['email', '=', $data['email']]; + + $user = Member::where($map)->findOrEmpty(); + if (!$user->isEmpty()) { + //发生重置密码连接电子邮件 + $result = Member::sendFindPaswd($user); + if (false !== $result) { + return $this->success("已发送找回密码邮件!", url('/user/index/login')); + }else{ + return $this->error("发送邮件失败!"); + } + }else{ + return $this->error('无此用户!'); + } + }else{ + return $this->fetch(); + } } /** @@ -58,6 +106,33 @@ class Index extends Base { * @return [type] [description] */ public function resetpasswd() { - return $this->fetch(); + if ($this->request->isAjax()) { + $token = $this->request->get('token'); + $data = $this->request->post(); + + list($username, $email) = explode("|", \xin\helper\Secure::decrypt($token, \think\facade\Env::get('jwt.secret'))); + if (!$username || !$email) { + return $this->error("找回密码地址错误或已过期!"); + } + $map[] = ['username', '=', $username]; + $map[] = ['email', '=', $email]; + + $user = Member::where($map)->findOrEmpty(); + + if (!$user->isEmpty()) { + $data['salt'] = \xin\helper\Str::random(6); + $result = Member::update($data, ['uid' => $user['uid']]); + if (false !== $result) { + return $this->success("已重置!", url('/user/index/login')); + }else{ + return $this->error("发送邮件失败!"); + } + }else{ + return $this->error('无此用户!'); + } + }else{ + $token = $this->request->param('token'); + return $this->fetch(); + } } } \ No newline at end of file diff --git a/app/controller/user/User.php b/app/controller/user/User.php index b8cb7609..95d82bd5 100644 --- a/app/controller/user/User.php +++ b/app/controller/user/User.php @@ -20,8 +20,8 @@ class User extends Base { */ public function profile() { if ($this->request->isPost()) { - $reuslt = (new Member())->editUser($this->request, session('userInfo.uid')); - if (false !== $reuslt) { + $result = (new Member())->editUser($this->request, session('userInfo.uid')); + if (false !== $result) { return $this->success('修改成功!'); } else { return $this->error('修改失败'); @@ -41,7 +41,29 @@ class User extends Base { * @return [type] [description] */ public function repasswd() { - return $this->fetch(); + if ($this->request->isAjax()) { + $data = $this->request->post(); + + $user = Member::where('uid', $data['uid'])->findOrEmpty(); + if (!$user->isEmpty()) { + if (md5($data['oldpassword'] . $user['salt']) !== $user['password']) { + return $this->error('旧密码不正确!'); + } + + $data['salt'] = \xin\helper\Str::random(6); + $result = $user->save($data); + + if (false !== $result) { + return $this->success('修改成功!'); + } else { + return $this->error('修改失败'); + } + }else{ + return $this->error('无此用户!'); + } + }else{ + return $this->fetch(); + } } /** diff --git a/app/http/form/template/select.html b/app/http/form/template/select.html index bf45a346..e1b0d4ab 100644 --- a/app/http/form/template/select.html +++ b/app/http/form/template/select.html @@ -1,4 +1,4 @@ - {volist name="option" id="item"} {/volist} diff --git a/app/model/Member.php b/app/model/Member.php index e0326901..4f4f2b24 100644 --- a/app/model/Member.php +++ b/app/model/Member.php @@ -242,6 +242,12 @@ class Member extends Model { self::where(['uid' => $user['uid']])->update($data); } + public static function sendFindPaswd($user){ + $token = \xin\helper\Secure::encrypt($user['username'] . "|" . $user['email'], \think\facade\Env::get('jwt.secret')); + $url = url('/user/index/resetpasswd', ['token'=>$token], true, true); + return true; + } + public function depart() { return $this->hasOne('Department', 'id', 'department'); } diff --git a/public/static/common/js/require-form.js b/public/static/common/js/require-form.js index 33224d05..98d36f60 100644 --- a/public/static/common/js/require-form.js +++ b/public/static/common/js/require-form.js @@ -57,7 +57,7 @@ define(['jquery', 'bootstrap', 'validator'], function ($, undefined, Validator) //验证通过提交表单 var submitResult = Form.api.submit($(ret), function (data, ret) { that.holdSubmit(false); - // submitBtn.removeClass("disabled"); + submitBtn.removeClass("disabled").removeAttr('disabled'); if (false === $(this).triggerHandler("success.form", [data, ret])) { return false; } @@ -81,7 +81,7 @@ define(['jquery', 'bootstrap', 'validator'], function ($, undefined, Validator) if (false === $(this).triggerHandler("error.form", [data, ret])) { return false; } - submitBtn.removeClass("disabled"); + submitBtn.removeClass("disabled").removeAttr('disabled'); if (typeof error === 'function') { if (false === error.call($(this), data, ret)) { return false; @@ -98,7 +98,7 @@ define(['jquery', 'bootstrap', 'validator'], function ($, undefined, Validator) }, form.data("validator-options") || {})); //移除提交按钮的disabled类 - $("button.btn[type=submit]", form).removeClass("disabled"); + $("button.btn[type=submit]", form).removeClass("disabled").removeAttr('disabled'); }, editor: function (form) { //绑定编辑器元素事件 diff --git a/public/template/default/front/index_index.html b/public/template/default/front/index_index.html index 2aaf473c..75e0c491 100644 --- a/public/template/default/front/index_index.html +++ b/public/template/default/front/index_index.html @@ -10,7 +10,9 @@ +
+ 注册 + 登录 +
diff --git a/public/template/default/static/css/style.css b/public/template/default/static/css/style.css new file mode 100644 index 00000000..1b2cb2a0 --- /dev/null +++ b/public/template/default/static/css/style.css @@ -0,0 +1,3 @@ +.reg-box, .log-box,.foret-box{margin-top: 30px; padding: 10px; height: 460px; background: #ffffff; border-radius: 4px;} +.reg-box .title, .log-box .title{font-size: 16px; margin: 15px auto; font-weight: bold; border-bottom: 1px solid #dedede; line-height: 35px; padding: 0 10px;} +.foret-box .body-content{width: 480px; margin: 40px auto;} \ No newline at end of file diff --git a/public/template/default/user/base.html b/public/template/default/user/base.html index 0e12e6e6..68bcfbcd 100644 --- a/public/template/default/user/base.html +++ b/public/template/default/user/base.html @@ -6,6 +6,7 @@ 用户中心 + + +用户中心 + + + + + + + +
+
+ +
+ +
+
+ +
+
+
+ +
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+ + Copyright © 2013-2020 SentCMS. All rights + reserved. +
+
+ + + + \ No newline at end of file diff --git a/public/template/default/user/index_login.html b/public/template/default/user/index_login.html index c4d43b20..552c4101 100644 --- a/public/template/default/user/index_login.html +++ b/public/template/default/user/index_login.html @@ -6,6 +6,7 @@ 用户中心 +
+
+
+
+

用户登录

+ +
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
diff --git a/public/template/default/user/index_register.html b/public/template/default/user/index_register.html index 289dbd7f..4f3e5298 100644 --- a/public/template/default/user/index_register.html +++ b/public/template/default/user/index_register.html @@ -6,6 +6,7 @@ 用户中心 +
+
+
+
+

用户注册

+ +
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+
+ +
+
+
+
+
diff --git a/public/template/default/user/index_resetpasswd.html b/public/template/default/user/index_resetpasswd.html new file mode 100644 index 00000000..e3953a12 --- /dev/null +++ b/public/template/default/user/index_resetpasswd.html @@ -0,0 +1,83 @@ + + + + + + +用户中心 + + + + + + + +
+
+ +
+ +
+
+ +
+
+
+ +
+
+ +
+ +
+
+
+
+ +
+ +
+
+
+
+
+ +
+
+
+
+
+
+
+
+ + +
+ + + + \ No newline at end of file diff --git a/public/template/default/user/user_repasswd.html b/public/template/default/user/user_repasswd.html index 0c1ebec7..cde0daf3 100644 --- a/public/template/default/user/user_repasswd.html +++ b/public/template/default/user/user_repasswd.html @@ -17,14 +17,14 @@
- +
- +