当前位置:网站首页>Laravel-admin 登录添加图形验证码
Laravel-admin 登录添加图形验证码
2022-06-26 10:04:00 【siner.li】
引入
composer require mews/captcha
修改
config/app.php
'providers' => [
// ...
Mews\Captcha\CaptchaServiceProvider::class,
]
'aliases' => [
// ...
'Captcha' => Mews\Captcha\Facades\Captcha::class,
]
php artisan vendor:publish
修改
config/captcha.php 中的 default
return [
'default' => [
'length' => 5,
'width' => 120,
'height' => 36,
'quality' => 90,
],
// ...
];
修改登录方法
修改 app/Admin/Controllers/AuthController.php , 如没有则复制 vendor/encore/laravel-admin/src/Controllers/AuthController.php 到 app/Admin/Controllers/AuthController.php
实例:
<?php
namespace App\Admin\Controllers;
use Encore\Admin\Controllers\AuthController as BaseAuthController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Validator;
class AuthController extends BaseAuthController
{
public function getLogin()
{
if (!Auth::guard('admin')->guest()) {
return redirect(config('admin.route.prefix'));
}
return view('admin.login');
}
public function postLogin(Request $request)
{
$credentials = $request->only(['username', 'password','captcha']);
$validator = Validator::make($credentials, [
'username' => 'required',
'password' => 'required',
'captcha' => 'required|captcha'
]);
if ($validator->fails()) {
return Redirect::back()->withInput()->withErrors($validator);
}
unset($credentials['captcha']);
if (Auth::guard('admin')->attempt($credentials)) {
admin_toastr(trans('admin.login_successful'));
return redirect()->intended(config('admin.route.prefix'));
}
return Redirect::back()->withInput()->withErrors(['username' => $this->getFailedLoginMessage()]);
}
protected function getFailedLoginMessage()
{
return Lang::has('auth.failed')
? trans('auth.failed')
: 'These credentials do not match our records.';
}
}
修改页面
复制 vendor/encore/laravel-admin/resources/views/login.blade.php 到 resources/views/admin/login.blade.php 在密码与记住我代码块中间添加代码
实例:
<div class="form-group has-feedback {!! !$errors->has('password') ?: 'has-error' !!}">
@if($errors->has('password'))
@foreach($errors->get('password') as $message)
<label class="control-label" for="inputError"><i class="fa fa-times-circle-o"></i>{
{
$message}}</label><br>
@endforeach
@endif
<input type="password" class="form-control" placeholder="{
{ trans('admin.password') }}" name="password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<!-- 在这里添加代码 start-->
<div class="row">
<div class="form-group has-feedback {!! !$errors->has('captcha') ?: 'has-error' !!}">
@if($errors->has('captcha'))
@foreach($errors->get('captcha') as $message)
<label class="control-label" for="inputError" style="margin-left: 15px"><i class="fa fa-times-circle-o">{
{
$message}}</i></label></br>
@endforeach
@endif
<input type="text" class="form-control" style="display: inline;width: 55%; margin-left: 15px" placeholder="{
{ trans('admin.captcha') }}" name="captcha">
<span class="glyphicon glyphicon-refresh form-control-feedback captcha" style="right:39%;z-index: 100"></span>
<img class="captcha" src="{
{ captcha_src('admin') }}">
</div>
</div>
<!-- 在这里添加代码 end-->
<div class="row">
<div class="col-xs-8">
@if(config('admin.auth.remember'))
边栏推荐
- 工作汇报(2)
- Qixia housing and Urban Rural Development Bureau and fire rescue brigade carried out fire safety training
- Moore vote, leetcode169, leetcode229
- See how I store integer data in the map < string, string > set
- MySQL Performance Monitoring and SQL statements
- Opencv image processing - grayscale processing
- Matrix fast power notes
- Recent work report
- 8- creating leecode algorithm with pictures and texts - algorithm solution of minimum stack and LRU caching mechanism
- 二叉树常见面试题
猜你喜欢
随机推荐
Oracle sqlplus 查询结果显示优化
QT连接MySql数据查询失败
你好!正向代理!
Using reflection to export entity data to excel
MySQL Performance Monitoring and SQL statements
VS或Qt编译链接过程中出现“无法解析的外部符号”的原因:
工程数学概率论统计简明教程第二版复习大纲
Mysql 30条军规
ISO 26262之——2功能安全概念
小笔记-简单但够用系列_KVM快速入门
滑动窗口
24 个必须掌握的数据库面试问题!
MySQL performance monitoring and SQL statements
JS reverse | four libraries and one platform response data encryption
Oracle11g reports an error when starting the database ora-27154: post/wait create failed
Pit record_ TreeSet custom sorting results in less data loss
Cereals Mall - Distributed Advanced
[work details] March 18, 2020
【在线仿真】Arduino UNO PWM 控制直流电机转速
See how I store integer data in the map < string, string > set

![[echart] i. how to learn echart and its characteristic document reading notes](/img/21/5405ae302df77d2ba07d9f5e5537f3.jpg)
![Installer MySQL sous Linux [détails]](/img/38/77be56c3ef3923ce4c4e5df4a96f41.png)




