1
0
mirror of https://github.com/cjango/dcat-vue.git synced 2025-12-06 22:40:03 +08:00

合并验证码

This commit is contained in:
weiwait
2023-02-08 11:04:57 +08:00
parent cc5b77b993
commit ec52abe746
11 changed files with 427 additions and 5 deletions

View File

@@ -74,10 +74,9 @@ class DcatVueServiceProvider extends ServiceProvider
$configs = collect(admin_setting_array('weiwait_filesystem'));
// dd($configs);
app()->booted(function () use ($configs) {
Helper::injectFilesystemConfig($configs);
Helper::injectAuthConfigs();
});
Event::listen('admin:booted', function () use ($configs) {

51
src/Forms/AuthSetting.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
namespace Weiwait\DcatVue\Forms;
use Dcat\Admin\Extend\Setting as Form;
use Dcat\Admin\Form\NestedForm;
use Illuminate\Support\Facades\Artisan;
use Weiwait\DcatVue\DcatVueServiceProvider;
class AuthSetting extends Form
{
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
admin_setting(['weiwait_auth' => $input]);
is_file(app()->getCachedConfigPath()) && Artisan::call('config:cache');
return $this
->response()
->success('保存成功')
->refresh();
}
public function form()
{
$this->switch('enable_captcha', DcatVueServiceProvider::trans('auth.enable_captcha'))
->default(true);
$this->vImage('background', DcatVueServiceProvider::trans('auth.background'));
$this->array('footer', DcatVueServiceProvider::trans('auth.footer'), function (NestedForm $form) {
$form->text('name', DcatVueServiceProvider::trans('auth.footers.name'));
$form->text('path', DcatVueServiceProvider::trans('auth.footers.path'));
});
}
/**
* The data of the form.
*
* @return array
*/
public function default()
{
return admin_setting_array('weiwait_auth');
}
}

View File

@@ -103,4 +103,12 @@ class Helper
// 获取临时密钥,计算签名
return (new Sts())->getTempKeys($config);
}
public static function injectAuthConfigs()
{
config()->set('captcha.default.length', 4);
config()->set('captcha.default.height', 34);
config()->set('captcha.default.width', 100);
config()->set('captcha.default.quality', 100);
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace Weiwait\DcatVue\Http\Controllers;
use Dcat\Admin\Http\Controllers\AuthController;
use Dcat\Admin\Layout\Content;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Validator;
class DcatAuthController extends AuthController
{
protected Collection $config;
public function __construct()
{
$this->config = collect(admin_setting()->getArray('weiwait_auth'));
}
public function getLogin(Content $content)
{
if ($this->guard()->check()) {
return redirect($this->getRedirectPath());
}
return $content->full()->body(view('weiwait.dcat-vue::login', ['config' => $this->config]));
}
public function postLogin(Request $request)
{
$credentials = $request->only([$this->username(), 'password']);
$remember = (bool) $request->input('remember', false);
$rules = [
$this->username() => 'required',
'password' => 'required',
];
if ($this->config->get('enable_captcha')) {
$rules['captcha'] = 'required|captcha';
}
/** @var \Illuminate\Validation\Validator $validator */
$validator = Validator::make($request->all(), $rules, ['captcha.captcha' => '验证码错误']);
if ($validator->fails()) {
return $this->validationErrorsResponse($validator);
}
if ($this->guard()->attempt($credentials, $remember)) {
return $this->sendLoginResponse($request);
}
return $this->validationErrorsResponse([
$this->username() => $this->getFailedLoginMessage(),
]);
}
}

View File

@@ -23,3 +23,7 @@ Route::get('weiwait/distpicker/address2ll', [Controllers\DcatVueController::clas
// 坐标位置信息
Route::get('weiwait/distpicker/ll2address', [Controllers\DcatVueController::class, 'll2address'])
->name('weiwait.distpicker.ll2address');
// 替换原生登录
Route::get('auth/login', [Controllers\DcatAuthController::class, 'getLogin']);
Route::post('auth/login', [Controllers\DcatAuthController::class, 'postLogin']);

View File

@@ -3,16 +3,35 @@
namespace Weiwait\DcatVue;
use Dcat\Admin\Extend\Setting as Form;
use Dcat\Admin\Form\NestedForm;
use Dcat\Admin\Http\JsonResponse;
class Setting extends Form
{
public function form()
{
// Todo
$this->tab('站点', function (\Dcat\Admin\Widgets\Form $form) {
$form->switch('weiwait_auth.enable_captcha', DcatVueServiceProvider::trans('auth.enable_captcha'))
->default(true);
$form->vImage('weiwait_auth.background', DcatVueServiceProvider::trans('auth.background'));
$form->array('weiwait_auth.footer', DcatVueServiceProvider::trans('auth.footer'), function (NestedForm $form) {
$form->text('name', DcatVueServiceProvider::trans('auth.footers.name'));
$form->text('path', DcatVueServiceProvider::trans('auth.footers.path'));
});
});
}
public function handle(array $input)
public function handle(array $input): JsonResponse
{
// Todo
admin_setting(['weiwait_auth' => $input['weiwait_auth']]);
return $this->response()->success('保存成功')->refresh();
}
public function default(): array
{
return [
'weiwait_auth' => admin_setting_array('weiwait_auth'),
];
}
}