Compare commits
No commits in common. "f0dc08c21c6bf94de7d408ab133d90f52c7404b6" and "91f7b524fec4355f62be86f9df27f677076b99ae" have entirely different histories.
f0dc08c21c
...
91f7b524fe
|
|
@ -17,7 +17,7 @@ class AdminUserController extends Controller
|
||||||
{
|
{
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$query = AdminUser::with(['roles'])->filter($request->all())->where('id', '>', 1);
|
$query = AdminUser::filter($request->all())->where('id', '>', 1);
|
||||||
$list = $query->paginate(Paginator::resolvePerPage('per_page', 20, 50));
|
$list = $query->paginate(Paginator::resolvePerPage('per_page', 20, 50));
|
||||||
|
|
||||||
return $this->json(AdminUserResource::collection($list));
|
return $this->json(AdminUserResource::collection($list));
|
||||||
|
|
@ -163,22 +163,4 @@ class AdminUserController extends Controller
|
||||||
|
|
||||||
return $this->success('修改成功!');
|
return $this->success('修改成功!');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function unban(AdminUser $adminUser, Request $request)
|
|
||||||
{
|
|
||||||
if (! $request->user()->isAdministrator()) {
|
|
||||||
return $this->error('无操作权限');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($adminUser->banned_at) {
|
|
||||||
$adminUser->update([
|
|
||||||
'banned_reason' => '',
|
|
||||||
'banned_at' => null,
|
|
||||||
]);
|
|
||||||
|
|
||||||
(new OperationLogService())->inLog(OperationType::Update, '解封-用户【'.$adminUser->name.'】');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->success('操作成功!');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,19 +2,13 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\AdminPermission;
|
|
||||||
use App\Models\AdminUser;
|
use App\Models\AdminUser;
|
||||||
use Illuminate\Contracts\Cache\Repository as Cache;
|
use App\Models\AdminPermission;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
|
||||||
class AuthController extends Controller
|
class AuthController extends Controller
|
||||||
{
|
{
|
||||||
public function __construct(
|
|
||||||
protected Cache $cache,
|
|
||||||
) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public function login(Request $request)
|
public function login(Request $request)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
|
|
@ -22,43 +16,13 @@ class AuthController extends Controller
|
||||||
'password' => 'required',
|
'password' => 'required',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$username = $request->input('username');
|
$user = AdminUser::where(['username' => $request->input('username')])->first();
|
||||||
|
if (! $user) {
|
||||||
$user = AdminUser::where(['username' => $username])->first();
|
return $this->error('用户名或密码错误');
|
||||||
|
}
|
||||||
if ($user?->banned_at) {
|
if (! Hash::check($request->input('password'), $user->password)) {
|
||||||
return $this->error('账号已封禁,请联系管理员');
|
|
||||||
}
|
|
||||||
|
|
||||||
$cacheKey = "admin_user_ban:{$username}";
|
|
||||||
|
|
||||||
if (! Hash::check($request->input('password'), (string) $user?->password)) {
|
|
||||||
$this->cache->add($cacheKey, 0, 86400);
|
|
||||||
|
|
||||||
$hits = $this->cache->increment($cacheKey, 1);
|
|
||||||
|
|
||||||
if ($hits >= 3) {
|
|
||||||
if ($user) {
|
|
||||||
// 锁定账号
|
|
||||||
$user->update([
|
|
||||||
'banned_reason' => '24小时内密码连续错误3次',
|
|
||||||
'banned_at' => now(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// 清空登录失败尝试次数
|
|
||||||
$this->cache->forget($cacheKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($hits > 3) {
|
|
||||||
return $this->error('账号已封禁,请联系管理员');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->error('用户名或密码错误');
|
return $this->error('用户名或密码错误');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清空登录失败尝试次数
|
|
||||||
$this->cache->forget($cacheKey);
|
|
||||||
|
|
||||||
if ($user->is_enable !== 1) {
|
if ($user->is_enable !== 1) {
|
||||||
return $this->error('用户状态异常请联系管理员');
|
return $this->error('用户状态异常请联系管理员');
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,6 @@ class AdminUserResource extends JsonResource
|
||||||
'status' => $this->status,
|
'status' => $this->status,
|
||||||
'is_enable' => $this->is_enable,
|
'is_enable' => $this->is_enable,
|
||||||
'view_all_bases' => (int) $this->view_all_bases,
|
'view_all_bases' => (int) $this->view_all_bases,
|
||||||
'banned_reason' => $this->banned_reason,
|
|
||||||
'banned_at' => $this->banned_at,
|
|
||||||
'bases' => AgriculturalBaseResource::collection($this->whenloaded('bases')),
|
'bases' => AgriculturalBaseResource::collection($this->whenloaded('bases')),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,6 @@ class AdminUser extends BaseAdminModel
|
||||||
{
|
{
|
||||||
use HasApiTokens, Filterable;
|
use HasApiTokens, Filterable;
|
||||||
|
|
||||||
protected $casts = [
|
|
||||||
'banned_at' => 'datetime',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name',
|
'name',
|
||||||
'username',
|
'username',
|
||||||
|
|
@ -24,8 +20,6 @@ class AdminUser extends BaseAdminModel
|
||||||
'status',
|
'status',
|
||||||
'is_enable',
|
'is_enable',
|
||||||
'view_all_bases',
|
'view_all_bases',
|
||||||
'banned_reason',
|
|
||||||
'banned_at',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,6 @@ use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration
|
||||||
{
|
{
|
||||||
public function getConnection()
|
|
||||||
{
|
|
||||||
return $this->config('database.connection') ?: config('database.default');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function config($key)
|
|
||||||
{
|
|
||||||
return config('admin.'.$key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
|
@ -23,7 +13,7 @@ return new class extends Migration
|
||||||
*/
|
*/
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
Schema::table($this->config('database.users_table'), function (Blueprint $table) {
|
Schema::table('admin_users', function (Blueprint $table) {
|
||||||
$table->boolean('view_all_bases')->default(false)->comment('是否可查看所有基地');
|
$table->boolean('view_all_bases')->default(false)->comment('是否可查看所有基地');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -35,7 +25,7 @@ return new class extends Migration
|
||||||
*/
|
*/
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
Schema::table($this->config('database.users_table'), function (Blueprint $table) {
|
Schema::table('admin_users', function (Blueprint $table) {
|
||||||
$table->dropColumn(['view_all_bases']);
|
$table->dropColumn(['view_all_bases']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
public function getConnection()
|
|
||||||
{
|
|
||||||
return $this->config('database.connection') ?: config('database.default');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function config($key)
|
|
||||||
{
|
|
||||||
return config('admin.'.$key);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function up()
|
|
||||||
{
|
|
||||||
Schema::table($this->config('database.users_table'), function (Blueprint $table) {
|
|
||||||
$table->string('banned_reason')->nullable()->comment('封禁原因');
|
|
||||||
$table->timestamp('banned_at')->nullable()->comment('封禁时间');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function down()
|
|
||||||
{
|
|
||||||
Schema::table($this->config('database.users_table'), function (Blueprint $table) {
|
|
||||||
$table->timestamp(['banned_reason', 'banned_at']);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -88,7 +88,6 @@ Route::group([
|
||||||
Route::apiResource('admin-users', AdminUserController::class)->names('admin_users');
|
Route::apiResource('admin-users', AdminUserController::class)->names('admin_users');
|
||||||
Route::put('admin-users/{admin_user}/enable', [AdminUserController::class, 'endable'])->name('admin_users.enable');
|
Route::put('admin-users/{admin_user}/enable', [AdminUserController::class, 'endable'])->name('admin_users.enable');
|
||||||
Route::put('admin-users/{admin_user}/edit-password', [AdminUserController::class, 'editPassword'])->name('admin_users.edit_password');
|
Route::put('admin-users/{admin_user}/edit-password', [AdminUserController::class, 'editPassword'])->name('admin_users.edit_password');
|
||||||
Route::put('admin-users/{admin_user}/unban', [AdminUserController::class, 'unban'])->name('admin_users.unban');
|
|
||||||
Route::apiResource('admin-roles', AdminRoleController::class)->names('admin_roles');
|
Route::apiResource('admin-roles', AdminRoleController::class)->names('admin_roles');
|
||||||
|
|
||||||
Route::get('weeks-per-year', WeeksPerYearController::class);
|
Route::get('weeks-per-year', WeeksPerYearController::class);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue