From 2ed0ee272e3b515f6bdd44d36af929cd197eec23 Mon Sep 17 00:00:00 2001 From: sky121113 Date: Mon, 12 Jan 2026 11:23:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=85=A5=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Requests/Auth/LoginRequest.php | 21 ++++++++++--- app/Models/User.php | 1 + compose.yaml | 12 +++---- ...026_01_12_031514_create_sessions_table.php | 31 +++++++++++++++++++ ..._12_031836_add_username_to_users_table.php | 28 +++++++++++++++++ resources/views/auth/login.blade.php | 8 ++--- 6 files changed, 86 insertions(+), 15 deletions(-) create mode 100644 database/migrations/2026_01_12_031514_create_sessions_table.php create mode 100644 database/migrations/2026_01_12_031836_add_username_to_users_table.php diff --git a/app/Http/Requests/Auth/LoginRequest.php b/app/Http/Requests/Auth/LoginRequest.php index 2b92f65..81d468a 100644 --- a/app/Http/Requests/Auth/LoginRequest.php +++ b/app/Http/Requests/Auth/LoginRequest.php @@ -27,11 +27,22 @@ class LoginRequest extends FormRequest public function rules(): array { return [ - 'email' => ['required', 'string', 'email'], + 'username' => ['required', 'string'], 'password' => ['required', 'string'], ]; } + /** + * 取得驗證規則的自訂錯誤訊息 + */ + public function messages(): array + { + return [ + 'username.required' => '請輸入帳號', + 'password.required' => '請輸入密碼', + ]; + } + /** * Attempt to authenticate the request's credentials. * @@ -41,11 +52,11 @@ class LoginRequest extends FormRequest { $this->ensureIsNotRateLimited(); - if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) { + if (! Auth::attempt($this->only('username', 'password'), $this->boolean('remember'))) { RateLimiter::hit($this->throttleKey()); throw ValidationException::withMessages([ - 'email' => trans('auth.failed'), + 'username' => trans('auth.failed'), ]); } @@ -68,7 +79,7 @@ class LoginRequest extends FormRequest $seconds = RateLimiter::availableIn($this->throttleKey()); throw ValidationException::withMessages([ - 'email' => trans('auth.throttle', [ + 'username' => trans('auth.throttle', [ 'seconds' => $seconds, 'minutes' => ceil($seconds / 60), ]), @@ -80,6 +91,6 @@ class LoginRequest extends FormRequest */ public function throttleKey(): string { - return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip()); + return Str::transliterate(Str::lower($this->string('username')).'|'.$this->ip()); } } diff --git a/app/Models/User.php b/app/Models/User.php index 5ea0bc7..bb1044d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -18,6 +18,7 @@ class User extends Authenticatable * @var array */ protected $fillable = [ + 'username', 'name', 'email', 'password', diff --git a/compose.yaml b/compose.yaml index d8c30ce..5d814ec 100644 --- a/compose.yaml +++ b/compose.yaml @@ -6,8 +6,8 @@ services: args: WWWGROUP: '${WWWGROUP}' image: 'sail-8.5/app' - container_name: start-cloud-laravel - hostname: start-cloud-laravel + container_name: star-cloud-laravel + hostname: star-cloud-laravel extra_hosts: - 'host.docker.internal:host-gateway' ports: @@ -29,8 +29,8 @@ services: mysql: image: 'mysql/mysql-server:8.0' - container_name: start-cloud-mysql - hostname: start-cloud-mysql + container_name: star-cloud-mysql + hostname: star-cloud-mysql ports: - '${FORWARD_DB_PORT:-3306}:3306' environment: @@ -56,8 +56,8 @@ services: timeout: 5s redis: image: 'redis:alpine' - container_name: start-cloud-redis - hostname: start-cloud-redis + container_name: star-cloud-redis + hostname: star-cloud-redis ports: - '${FORWARD_REDIS_PORT:-6379}:6379' volumes: diff --git a/database/migrations/2026_01_12_031514_create_sessions_table.php b/database/migrations/2026_01_12_031514_create_sessions_table.php new file mode 100644 index 0000000..f60625b --- /dev/null +++ b/database/migrations/2026_01_12_031514_create_sessions_table.php @@ -0,0 +1,31 @@ +string('id')->primary(); + $table->foreignId('user_id')->nullable()->index(); + $table->string('ip_address', 45)->nullable(); + $table->text('user_agent')->nullable(); + $table->longText('payload'); + $table->integer('last_activity')->index(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('sessions'); + } +}; diff --git a/database/migrations/2026_01_12_031836_add_username_to_users_table.php b/database/migrations/2026_01_12_031836_add_username_to_users_table.php new file mode 100644 index 0000000..5773e07 --- /dev/null +++ b/database/migrations/2026_01_12_031836_add_username_to_users_table.php @@ -0,0 +1,28 @@ + @csrf - +
- - - + + +