作者 王晓刚
1 个管道 的构建 通过 耗费 23 秒

合并分支 'wxg' 到 'master'

Wxg



查看合并请求 !79
@@ -5,6 +5,7 @@ namespace app\admin\controller; @@ -5,6 +5,7 @@ namespace app\admin\controller;
5 use app\admin\model\AdminLog; 5 use app\admin\model\AdminLog;
6 use app\common\controller\Backend; 6 use app\common\controller\Backend;
7 use think\Config; 7 use think\Config;
  8 +use think\Db;
8 use think\Hook; 9 use think\Hook;
9 use think\Validate; 10 use think\Validate;
10 11
@@ -15,7 +16,7 @@ use think\Validate; @@ -15,7 +16,7 @@ use think\Validate;
15 class Index extends Backend 16 class Index extends Backend
16 { 17 {
17 18
18 - protected $noNeedLogin = ['login']; 19 + protected $noNeedLogin = ['login','forget','send_ems','verify_code','reset_password'];
19 protected $noNeedRight = ['index', 'logout']; 20 protected $noNeedRight = ['index', 'logout'];
20 protected $layout = ''; 21 protected $layout = '';
21 22
@@ -119,4 +120,208 @@ class Index extends Backend @@ -119,4 +120,208 @@ class Index extends Backend
119 $this->success(__('Logout successful'), 'index/login'); 120 $this->success(__('Logout successful'), 'index/login');
120 } 121 }
121 122
  123 + /**
  124 + * 忘记密码
  125 + */
  126 + public function forget(){
  127 + $url = $this->request->get('url', 'index/index');
  128 + if ($this->auth->isLogin()) {
  129 + $this->success(__("You've logged in, do not login again"), $url);
  130 + }
  131 + if ($this->request->isPost()) {
  132 + $url = $this->request->get('url', 'index/forget');
  133 + $email = $this->request->post('email');
  134 + $rule = [
  135 + 'email' => 'require|email',
  136 +// '__token__' => 'require|token',
  137 + ];
  138 + $data = [
  139 + 'email' => $email,
  140 +// '__token__' => $token,
  141 + ];
  142 + $validate = new Validate($rule, [], ['email' => __('email')]);
  143 + $result = $validate->check($data);
  144 + if (!$result) {
  145 + $this->error($validate->getError(), $url, ['token' => $this->request->token()]);
  146 + }
  147 + //根据email获取商户信息
  148 + $admin = Db::name('admin')->where(['email'=>$email])->find();
  149 + if(empty($admin)){
  150 + $this->error('当前email尚未绑定');
  151 + }
  152 + if(empty($admin['user_id'])){
  153 + $this->error('平台管理员忘记密码请联系总管理员');
  154 + }
  155 + if($admin['status'] != 'normal'){
  156 + $this->error('您已被拉黑,请联系客服');
  157 + }
  158 + //生成验证码
  159 + $code = generateCode(6);
  160 + //储存验证码
  161 + $admin_code = Db::name('admin_code')->where(['email'=>$email])->find();
  162 + $arr['code'] = $code;
  163 + $arr['pasttime'] = time()+600;
  164 + $arr['is_use'] = 0;
  165 + if(empty($admin_code)){
  166 + $arr['email'] = $email;
  167 + $arr['createtime'] = time();
  168 + $result1 = Db::name('admin_code')->insert($arr);
  169 + }else{
  170 + $arr['updatetime'] = time();
  171 + $result1 = Db::name('admin_code')->where(['id'=>$admin_code['id']])->update($arr);
  172 + }
  173 + if(empty($result1)){
  174 + $this->error('sql执行失败');
  175 + }
  176 + //发送验证码
  177 + $this->send_ems($admin['email'],$code);
  178 + if ($result) {
  179 + $this->success('发送成功');
  180 + } else {
  181 + $this->error('发送失败');
  182 + }
  183 + /*AdminLog::setTitle(__('Login'));
  184 + $result = $this->auth->login($username, $password, $keeplogin ? 86400 : 0);
  185 + if ($result === true) {
  186 + Hook::listen("admin_login_after", $this->request);
  187 + $this->success(__('Login successful'), $url, ['url' => $url, 'id' => $this->auth->id, 'username' => $username, 'avatar' => $this->auth->avatar]);
  188 + } else {
  189 + $msg = $this->auth->getError();
  190 + $msg = $msg ? $msg : __('Username or password is incorrect');
  191 + $this->error($msg, $url, ['token' => $this->request->token()]);
  192 + }*/
  193 + }
  194 + $background = Config::get('fastadmin.login_background');
  195 + $background = stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background;
  196 + $this->view->assign('background', $background);
  197 + $this->view->assign('title', __('忘记密码'));
  198 + Hook::listen("admin_login_init", $this->request);
  199 + return $this->view->fetch();
  200 + }
  201 +
  202 + public function send_ems($receiver,$code){
  203 + \think\Config::set('site', \think\Config::get('site'));
  204 + $email = new Email();
  205 + $str = "验证码:$code,10分钟内有效。";
  206 + $result = $email
  207 + ->to($receiver)
  208 + ->subject("金点网-找回密码")
  209 + ->message($str)
  210 + ->send();
  211 + return $result;
  212 + }
  213 +
  214 + /**
  215 + * 验证验证码是否正确
  216 + */
  217 + public function verify_code(){
  218 + if ($this->request->isPost()) {
  219 + $url = $this->request->get('url', 'index/forget');
  220 + $email = $this->request->post('email');
  221 + $code = $this->request->post('code');
  222 + $rule = [
  223 + 'email' => 'require|email',
  224 + 'code' => 'require',
  225 +// '__token__' => 'require|token',
  226 + ];
  227 + $data = [
  228 + 'email' => $email,
  229 + 'code' => $code,
  230 +// '__token__' => $token,
  231 + ];
  232 + $validate = new Validate($rule, [], ['email' => __('email'), 'code' => '请输入验证码']);
  233 + $result = $validate->check($data);
  234 + if (!$result) {
  235 + $this->error($validate->getError(), $url, ['token' => $this->request->token()]);
  236 + }
  237 + $admin_code = Db::name('admin_code')->where(['email'=>$email])->find();
  238 + if(empty($admin_code)){
  239 + $this->error('404');
  240 + }
  241 + if(!empty($admin_code['is_use'])){
  242 + $this->error('验证码已被使用');
  243 + }
  244 + if($admin_code['pasttime'] < time()){
  245 + $this->error('验证码已过期');
  246 + }
  247 + if($admin_code['code'] != $code){
  248 + $this->error('验证码错误');
  249 + }
  250 + $result = Db::name('admin_code')->where(['id'=>$admin_code['id']])->update(['is_use'=>1]);
  251 + if(empty($result)){
  252 + $this->error('sql执行失败');
  253 + }
  254 + //生成令牌(为了安全)
  255 + $str = "Bronet";
  256 + $auth_code = config('auth_code');
  257 + $token = rawurlencode(sha1(md5($str.$auth_code).md5($email)));
  258 + $this->success('验证通过',url('reset_password',['token'=>$token,'email'=>$email],false,true));
  259 + }
  260 + }
  261 +
  262 + /**
  263 + * 重置密码页面
  264 + */
  265 + public function reset_password(){
  266 + $url = $this->request->get('url', 'index/index');
  267 + if ($this->auth->isLogin()) {
  268 + $this->success(__("You've logged in, do not login again"), $url);
  269 + }
  270 + if($this->request->isPost()){
  271 + $password = $this->request->param('password');
  272 + $affirm_password = $this->request->param('affirm_password');
  273 + $email = $this->request->param('email');
  274 + $token = $this->request->param('token');
  275 + $rule = [
  276 + 'password' => 'require|length:3,30',
  277 + 'affirm_password' => 'require|length:3,30',
  278 + 'email' => 'require|email',
  279 + 'token' => 'require',
  280 + ];
  281 + $data = [
  282 + 'password' => $password,
  283 + 'affirm_password' => $affirm_password,
  284 + 'email' => $email,
  285 + 'token' => $token,
  286 + ];
  287 + $validate = new Validate($rule, [], ['password' => __('password'), 'affirm_password' => __('Password'), 'email' => __('email')]);
  288 + $result = $validate->check($data);
  289 + if (!$result) {
  290 + $this->error($validate->getError(), $url, ['token' => $this->request->token()]);
  291 + }
  292 + if($password != $affirm_password){
  293 + $this->error('两次密码不一致');
  294 + }
  295 + $str = "Bronet";
  296 + $auth_code = config('auth_code');
  297 + $token2 = rawurlencode(sha1(md5($str.$auth_code).md5($email)));
  298 + if($token != $token2){
  299 + $this->error('令牌错误','','','');
  300 + }
  301 + $admin = Db::name('admin')->where(['email'=>$email])->find();
  302 + $password = md5(md5($password) . $admin['salt']);
  303 + $result = Db::name('admin')->where(['id'=>$admin['id']])->update(['password'=>$password]);
  304 + if(empty($result)){
  305 + $this->error('sql执行失败');
  306 + }
  307 +
  308 + $this->success('重置成功',$url);
  309 + }else{
  310 + $token = $this->request->param('token');
  311 + $email = $this->request->param('email');
  312 + $str = "Bronet";
  313 + $auth_code = config('auth_code');
  314 + $token2 = rawurlencode(sha1(md5($str.$auth_code).md5($email)));
  315 + if($token != $token2){
  316 + $this->error('令牌错误','','','');
  317 + }
  318 + $background = Config::get('fastadmin.login_background');
  319 + $background = stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background;
  320 + $this->view->assign('background', $background);
  321 + $this->view->assign('title', __('重置密码'));
  322 + Hook::listen("admin_login_init", $this->request);
  323 + return $this->view->fetch();
  324 + }
  325 + }
  326 +
122 } 327 }
@@ -90,6 +90,9 @@ @@ -90,6 +90,9 @@
90 <input type="checkbox" name="keeplogin" id="keeplogin" value="1" /> 90 <input type="checkbox" name="keeplogin" id="keeplogin" value="1" />
91 {:__('Keep login')} 91 {:__('Keep login')}
92 </label> 92 </label>
  93 + <!--<label class="inline pull-right" style="cursor:pointer" onclick="window.location.href='{:url('forget')}'">
  94 + 忘记密码?
  95 + </label>-->
93 </div> 96 </div>
94 <div class="form-group"> 97 <div class="form-group">
95 <button type="submit" class="btn btn-success btn-lg btn-block">{:__('Sign in')}</button> 98 <button type="submit" class="btn btn-success btn-lg btn-block">{:__('Sign in')}</button>
@@ -19,7 +19,7 @@ use app\index\model\Store; @@ -19,7 +19,7 @@ use app\index\model\Store;
19 19
20 class Goods extends Frontend 20 class Goods extends Frontend
21 { 21 {
22 - protected $noNeedLogin = ['*']; 22 + protected $noNeedLogin = [''];
23 protected $noNeedRight = ['*']; 23 protected $noNeedRight = ['*'];
24 24
25 public function _initialize() 25 public function _initialize()
@@ -802,7 +802,7 @@ @@ -802,7 +802,7 @@
802 error: function (res) { 802 error: function (res) {
803 toast('与服务器断开连接'); 803 toast('与服务器断开连接');
804 } 804 }
805 - }) 805 + });
806 } 806 }
807 807
808 //入驻协议radio点击 808 //入驻协议radio点击
@@ -818,11 +818,11 @@ @@ -818,11 +818,11 @@
818 818
819 //查询数据 819 //查询数据
820 function searchData(val) { 820 function searchData(val) {
821 - var searchKey = $('#searchVal').val(); 821 + /*var searchKey = $('#searchVal').val();
822 if(searchKey == ''){ 822 if(searchKey == ''){
823 toast('请输入要搜索的内容'); 823 toast('请输入要搜索的内容');
824 return; 824 return;
825 - } 825 + }*/
826 initGoodsList(); 826 initGoodsList();
827 //noResultsTips(); 827 //noResultsTips();
828 } 828 }