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