laravel-admin添加验证码 设置中文以及禁用用户

设置中文

在config目录下面的app.php

将默认语言项改为:

‘locale’ => ‘zh-CN’

执行代码:

composer require "overtrue/laravel-lang:~3.0"

自定义中文:

在resources\lang目录下面建立zh-CN.json

{
    "ID": "ID",
    "Created at":"创建时间",
    "Updated at":"更新时间",
    "name":"名字",
    "Email":"邮箱",
    "Phone":"手机号",
    "Username":"用户名",
    "Status":"状态",
    "Address":"地址"
}
//可直接替换成中文 
$grid->column('phone', __('Phone'));
$grid->column('address', __('Address'));
$grid->column('status', __('Status'));
$grid->column('created_at', __('Created at'));
$grid->column('updated_at', __('Updated at'));

添加验证码

composer require james.xue/login-captcha

配置config/admin.php

'extensions' => [
     'login-captcha' => [
         // set to false if you want to disable this extension
         'enable' => true,
     ]
 ]

禁用用户

laravel7执行上边的添加验证码composer很难找到配套的禁用用户的composer所以我自己更改一下框架内容

在数据表admin_users中添加字段status默认为1

1为使用0为禁用

修改Encore\Admin\Controllers\UserController.php

gird()表格方法中添加:

$states = [
	'on'  => ['value' => 1, 'text' => '使用', 'color' => 'success'],
	 'off' => ['value' => 0, 'text' => '禁用', 'color' => 'default'],
	];
$grid->column('status', __('状态'))->switch($states);

form()表单方法中添加:

$states = [
	'on'  => ['value' => 1, 'text' => '使用', 'color' => 'success'],
	'off' => ['value' => 0, 'text' => '禁用', 'color' => 'default'],
	];
        $form->switch('status', __('状态'))->states($states)->default('1');

修改Encore\Admin\Controllers\AuthController.php(不使用验证码时用这个判断)

postLogin()判断登录方法中:

$status=\DB::table('admin_users')->where('username',$credentials['username'])->value('status');
        if($status==0){
            return back()->withInput()->withErrors([
                $this->username() => "用户被禁用",
            ]);
          
        }

修改james.xue/login-captcha/src文件中的Encore\James\JamesController.php(使用验证码时用这个判断)

postLogin()判断登录方法中:

$status=\DB::table('admin_users')->where('username',$credentials['username'])->value('status');
        if($status==0){
            return back()->withInput()->withErrors([
                $this->username() => "用户被禁用",
            ]);
          
        }

结果:

0 评论
内联反馈
查看所有评论