mirror of
https://github.com/lsky-org/lsky-pro.git
synced 2025-01-08 11:57:52 +08:00
✨ 邮件验证功能
This commit is contained in:
parent
f12beb3fd2
commit
3a1095dcb3
@ -1,4 +1,4 @@
|
||||
APP_NAME=Laravel
|
||||
APP_NAME="Lsky Pro"
|
||||
APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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('账号状态异常');
|
||||
}
|
||||
|
@ -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:
|
||||
|
@ -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' => [
|
||||
|
10
public/css/app.css
vendored
10
public/css/app.css
vendored
@ -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;
|
||||
}
|
||||
|
@ -74,8 +74,12 @@
|
||||
<p class="basis-1/3">注册 IP</p>
|
||||
<p class="basis-2/3 truncate text-gray-800">{{ $user->registered_ip }}</p>
|
||||
</div>
|
||||
@if(! $user->email_verified_at)
|
||||
<p class="p-2 text-sm rounded bg-red-500 text-white">你的账号尚未激活,功能受限,请根据激活邮件指引激活账号,如果你没有收到邮件,请点击 <a href="" class="text-green-400">这里</a> 重新发送。</p>
|
||||
@if(\App\Utils::config(\App\Enums\ConfigKey::IsUserNeedVerify) && !$user->email_verified_at)
|
||||
<p class="p-2 text-sm rounded bg-red-400 text-white">
|
||||
你的账号尚未激活,功能受限,请根据激活邮件指引激活账号,如果你没有收到邮件,请点击
|
||||
<a id="send-verify-email" href="javascript:void(0)" class="text-green-400">这里</a>
|
||||
重新发送。
|
||||
</p>
|
||||
@endif
|
||||
</div>
|
||||
</x-slot>
|
||||
@ -122,4 +126,25 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if(\App\Utils::config(\App\Enums\ConfigKey::IsUserNeedVerify) && !$user->email_verified_at)
|
||||
@push('scripts')
|
||||
<script>
|
||||
$('#send-verify-email').click(function () {
|
||||
if (! $(this).attr('disabled')) {
|
||||
$(this).text('发送中...').attr('disabled');
|
||||
axios.post('{{ route('verification.send') }}').then(response => {
|
||||
toastr.success('发送成功,请注意查收。');
|
||||
}).catch(error => {
|
||||
if (error.response.status === 429) {
|
||||
toastr.error('操作频繁,请稍后再试');
|
||||
}
|
||||
}).finally(_ => {
|
||||
$(this).text('这里').attr('disabled');
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
@endif
|
||||
</x-app-layout>
|
||||
|
@ -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'])
|
||||
|
Loading…
Reference in New Issue
Block a user