2019-12-02 23:04:43 +08:00
|
|
|
<?php
|
|
|
|
namespace catchAdmin\login\controller;
|
|
|
|
|
2019-12-12 18:52:56 +08:00
|
|
|
use catchAdmin\user\Auth;
|
2019-12-02 23:04:43 +08:00
|
|
|
use catchAdmin\login\request\LoginRequest;
|
2019-12-12 09:13:44 +08:00
|
|
|
use catcher\base\CatchController;
|
|
|
|
use catcher\CatchResponse;
|
2019-12-12 18:52:56 +08:00
|
|
|
use think\captcha\Captcha;
|
2019-12-02 23:04:43 +08:00
|
|
|
|
2019-12-12 09:13:44 +08:00
|
|
|
class Index extends CatchController
|
2019-12-02 23:04:43 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 登录
|
|
|
|
*
|
|
|
|
* @time 2019年11月30日
|
|
|
|
* @throws \Exception
|
|
|
|
* @return string
|
|
|
|
*/
|
2019-12-06 08:24:07 +08:00
|
|
|
public function index(): string
|
2019-12-02 23:04:43 +08:00
|
|
|
{
|
2019-12-06 08:24:07 +08:00
|
|
|
return $this->fetch();
|
2019-12-02 23:04:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 登陆
|
|
|
|
*
|
|
|
|
* @time 2019年11月28日
|
|
|
|
* @param LoginRequest $request
|
|
|
|
* @return bool|string
|
2019-12-12 09:13:44 +08:00
|
|
|
* @throws \cather\exceptions\LoginFailedException
|
2019-12-02 23:04:43 +08:00
|
|
|
* @throws \app\exceptions\LoginFailedException
|
|
|
|
*/
|
|
|
|
public function login(LoginRequest $request)
|
|
|
|
{
|
2019-12-12 18:52:56 +08:00
|
|
|
return Auth::login($request->param()) ?
|
2019-12-12 09:13:44 +08:00
|
|
|
CatchResponse::success('', '登录成功') : CatchResponse::success('', '登录失败');
|
2019-12-02 23:04:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 登出
|
|
|
|
*
|
|
|
|
* @time 2019年11月28日
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function logout(): bool
|
|
|
|
{
|
2019-12-12 18:52:56 +08:00
|
|
|
if (Auth::logout()) {
|
2019-12-02 23:04:43 +08:00
|
|
|
return redirect(url('login'));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-12 18:52:56 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @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);
|
|
|
|
}
|
2019-12-02 23:04:43 +08:00
|
|
|
}
|