From 3a1095dcb3abe3b89bc810b1ac2df74e741a38f1 Mon Sep 17 00:00:00 2001 From: Wisp X Date: Fri, 14 Jan 2022 14:28:58 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E9=82=AE=E4=BB=B6=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 2 +- app/Enums/ConfigKey.php | 3 +++ app/Http/Controllers/Controller.php | 1 - app/Models/User.php | 3 ++- app/Service/ImageService.php | 4 ++++ app/Utils.php | 1 + database/seeders/DatabaseSeeder.php | 1 + public/css/app.css | 10 ++++++++++ resources/views/dashboard.blade.php | 29 +++++++++++++++++++++++++++-- routes/auth.php | 2 +- 10 files changed, 50 insertions(+), 6 deletions(-) diff --git a/.env.example b/.env.example index 9b72ce8e..2181b928 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ -APP_NAME=Laravel +APP_NAME="Lsky Pro" APP_ENV=local APP_KEY= APP_DEBUG=true diff --git a/app/Enums/ConfigKey.php b/app/Enums/ConfigKey.php index b3a4f58a..37655376 100644 --- a/app/Enums/ConfigKey.php +++ b/app/Enums/ConfigKey.php @@ -28,6 +28,9 @@ final class ConfigKey /** @var string 用户初始容量(kb) */ const UserInitialCapacity = 'user_initial_capacity'; + /** @var string 账户是否需要验证 */ + const IsUserNeedVerify = 'is_user_need_verify'; + /** @var string 邮件配置 */ const MailConfigs = 'mail_configs'; diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index 6f09fc2c..8cf22c41 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -14,7 +14,6 @@ use Illuminate\Http\Response; use Illuminate\Routing\Controller as BaseController; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; -use Illuminate\Support\Facades\Storage; class Controller extends BaseController { diff --git a/app/Models/User.php b/app/Models/User.php index 55a21685..4fe014e9 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,6 +4,7 @@ namespace App\Models; use App\Enums\UserConfigKey; use Carbon\Carbon; +use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -33,7 +34,7 @@ use Laravel\Sanctum\HasApiTokens; * @property-read \Illuminate\Database\Eloquent\Collection $albums * @property-read \Illuminate\Database\Eloquent\Collection $images */ -class User extends Authenticatable +class User extends Authenticatable implements MustVerifyEmail { use HasApiTokens, HasFactory, Notifiable; diff --git a/app/Service/ImageService.php b/app/Service/ImageService.php index 5b15a48f..b0542b76 100644 --- a/app/Service/ImageService.php +++ b/app/Service/ImageService.php @@ -58,6 +58,10 @@ class ImageService ]); if (! is_null($user)) { + if (Utils::config(ConfigKey::IsUserNeedVerify) && ! $user->email_verified_at) { + throw new UploadException('账户未验证'); + } + if ($user->status !== UserStatus::Normal) { throw new UploadException('账号状态异常'); } diff --git a/app/Utils.php b/app/Utils.php index 80b0a03d..18a0a16d 100644 --- a/app/Utils.php +++ b/app/Utils.php @@ -26,6 +26,7 @@ class Utils case ConfigKey::IsAllowGuestUpload: case ConfigKey::IsEnableGallery: case ConfigKey::IsEnableRegistration: + case ConfigKey::IsUserNeedVerify: $value = (bool) $value; break; case ConfigKey::MailConfigs: diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 2cf0fbb5..64006655 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -28,6 +28,7 @@ class DatabaseSeeder extends Seeder ConfigKey::IsEnableGallery => 1, ConfigKey::IsAllowGuestUpload => 1, ConfigKey::UserInitialCapacity => 512000, + ConfigKey::IsUserNeedVerify => 1, ConfigKey::MailConfigs => json_encode([ 'default' => 'smtp', 'mailers' => [ diff --git a/public/css/app.css b/public/css/app.css index 13e21c3a..38a4e562 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -817,6 +817,9 @@ select { .inline-flex { display: inline-flex; } +.table { + display: table; +} .grid { display: grid; } @@ -1144,6 +1147,9 @@ select { .break-words { overflow-wrap: break-word; } +.break-all { + word-break: break-all; +} .rounded-md { border-radius: 0.375rem; } @@ -1282,6 +1288,10 @@ select { --tw-bg-opacity: 1; background-color: rgb(220 38 38 / var(--tw-bg-opacity)); } +.bg-red-400 { + --tw-bg-opacity: 1; + background-color: rgb(248 113 113 / var(--tw-bg-opacity)); +} .bg-opacity-75 { --tw-bg-opacity: 0.75; } diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index a5a23cd8..719ad344 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -74,8 +74,12 @@

注册 IP

{{ $user->registered_ip }}

- @if(! $user->email_verified_at) -

你的账号尚未激活,功能受限,请根据激活邮件指引激活账号,如果你没有收到邮件,请点击 这里 重新发送。

+ @if(\App\Utils::config(\App\Enums\ConfigKey::IsUserNeedVerify) && !$user->email_verified_at) +

+ 你的账号尚未激活,功能受限,请根据激活邮件指引激活账号,如果你没有收到邮件,请点击 + 这里 + 重新发送。 +

@endif @@ -122,4 +126,25 @@ + + @if(\App\Utils::config(\App\Enums\ConfigKey::IsUserNeedVerify) && !$user->email_verified_at) + @push('scripts') + + @endpush + @endif diff --git a/routes/auth.php b/routes/auth.php index 0fb1129a..fcc7d0a9 100644 --- a/routes/auth.php +++ b/routes/auth.php @@ -49,7 +49,7 @@ Route::get('/verify-email/{id}/{hash}', [VerifyEmailController::class, '__invoke ->name('verification.verify'); Route::post('/email/verification-notification', [EmailVerificationNotificationController::class, 'store']) - ->middleware(['auth', 'throttle:6,1']) + ->middleware(['auth', 'throttle:3,1']) ->name('verification.send'); Route::get('/confirm-password', [ConfirmablePasswordController::class, 'show'])