修改登录
This commit is contained in:
parent
a0a62b5640
commit
109cb7279a
@ -1,10 +1,11 @@
|
||||
<?php
|
||||
namespace catchAdmin\login\controller;
|
||||
|
||||
use catchAdmin\login\Auth;
|
||||
use catchAdmin\user\Auth;
|
||||
use catchAdmin\login\request\LoginRequest;
|
||||
use catcher\base\CatchController;
|
||||
use catcher\CatchResponse;
|
||||
use think\captcha\Captcha;
|
||||
|
||||
class Index extends CatchController
|
||||
{
|
||||
@ -31,7 +32,7 @@ class Index extends CatchController
|
||||
*/
|
||||
public function login(LoginRequest $request)
|
||||
{
|
||||
return (new Auth())->login($request->param()) ?
|
||||
return Auth::login($request->param()) ?
|
||||
CatchResponse::success('', '登录成功') : CatchResponse::success('', '登录失败');
|
||||
}
|
||||
|
||||
@ -43,10 +44,22 @@ class Index extends CatchController
|
||||
*/
|
||||
public function logout(): bool
|
||||
{
|
||||
if ((new Auth())->logout()) {
|
||||
if (Auth::logout()) {
|
||||
return redirect(url('login'));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月12日
|
||||
* @param Captcha $captcha
|
||||
* @param null $config
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function captcha(Captcha $captcha, $config = null): \think\Response
|
||||
{
|
||||
return $captcha->create($config);
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ class LoginRequest extends CatchRequest
|
||||
{
|
||||
// TODO: Implement rules() method.
|
||||
return [
|
||||
'name|用户名' => 'require|max:25',
|
||||
'email|用户名' => 'email',
|
||||
'password|密码' => 'require',
|
||||
// 'captcha|验证码' => 'require|captcha'
|
||||
];
|
||||
|
@ -1,8 +1,11 @@
|
||||
<?php
|
||||
|
||||
# 登陆页面
|
||||
$router->get('login', '\catchAdmin\login\controller\Index/index');
|
||||
$router->get('login', '\catchAdmin\login\controller\Index@index');
|
||||
# 登入
|
||||
$router->post('login', '\catchAdmin\login\controller\Index/login');
|
||||
$router->post('login', '\catchAdmin\login\controller\Index@login');
|
||||
# 登出
|
||||
$router->post('logout', '\catchAdmin\login\controller\Index/logout');
|
||||
$router->post('logout', '\catchAdmin\login\controller\Index@logout');
|
||||
# 验证码
|
||||
$router->get('catch/captcha/[:config]','\catchAdmin\login\controller\Index@captcha');
|
||||
|
||||
|
@ -38,8 +38,8 @@
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
|
||||
<div class="layui-input-block">
|
||||
<input name="name" type="text" placeholder="账号" class="layui-input"
|
||||
lay-verType="tips" lay-verify="required" required/>
|
||||
<input name="email" type="text" placeholder="邮箱" class="layui-input"
|
||||
lay-verType="tips" lay-verify="required|email" required/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
@ -58,7 +58,7 @@
|
||||
autocomplete="off" lay-verType="tips" lay-verify="required" required/>
|
||||
</div>
|
||||
<div class="layui-col-xs5" style="padding-left: 6px;">
|
||||
<img src="{:captcha_src()}" alt="captcha" class="captcha" onclick="this.src = this.src + '?t=' + (new Date).getTime();"/>
|
||||
<img src="{:url('catch/captcha')}" alt="captcha" class="captcha" onclick="this.src = this.src + '?t=' + (new Date).getTime();"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -106,13 +106,20 @@
|
||||
type: 'post',
|
||||
data: obj.field,
|
||||
success: function(response) {
|
||||
layer.msg(response.msg, {
|
||||
icon: 1,
|
||||
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
||||
}, function(){
|
||||
//do something
|
||||
window.location.href = '/';
|
||||
})
|
||||
if (response.code === 10000) {
|
||||
layer.msg(response.msg, {
|
||||
icon: 1,
|
||||
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
||||
}, function () {
|
||||
//do something
|
||||
window.location.href = '/';
|
||||
})
|
||||
} else {
|
||||
layer.msg(response.msg, {
|
||||
icon: 2,
|
||||
time: 2000 //2秒关闭(如果不配置,默认是3秒)
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user