diff --git a/site/app/Http/Requests/Auth/LoginRequest.php b/site/app/Http/Requests/Auth/LoginRequest.php index 7a19bc0..a2b9d0f 100644 --- a/site/app/Http/Requests/Auth/LoginRequest.php +++ b/site/app/Http/Requests/Auth/LoginRequest.php @@ -2,12 +2,14 @@ namespace App\Http\Requests\Auth; +use App\Models\User; use Illuminate\Auth\Events\Lockout; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\RateLimiter; use Illuminate\Support\Str; use Illuminate\Validation\ValidationException; +use Illuminate\Support\Facades\Hash; class LoginRequest extends FormRequest { @@ -27,7 +29,7 @@ public function authorize(): bool public function rules(): array { return [ - 'email' => ['required', 'string', 'email'], + 'login' => ['required', 'string'], 'password' => ['required', 'string'], ]; } @@ -41,6 +43,8 @@ public function authenticate(): void { $this->ensureIsNotRateLimited(); + + /* if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) { RateLimiter::hit($this->throttleKey()); @@ -48,7 +52,20 @@ public function authenticate(): void 'email' => trans('auth.failed'), ]); } + */ + $user = User::where('email', $this->login) + ->orWhere('name', $this->login) + ->first(); + + if (!$user || !Hash::check($this->password, $user->password)) { + RateLimiter::hit($this->throttleKey()); + throw ValidationException::withMessages([ + 'login' => __('auth.failed'), + ]); + } + + Auth::login($user, $this->boolean('remember')); RateLimiter::clear($this->throttleKey()); } diff --git a/site/database/migrations/2023_12_21_024651_add_unique_index_to_usernames.php b/site/database/migrations/2023_12_21_024651_add_unique_index_to_usernames.php new file mode 100644 index 0000000..9f2f65b --- /dev/null +++ b/site/database/migrations/2023_12_21_024651_add_unique_index_to_usernames.php @@ -0,0 +1,28 @@ +unique('name'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropUnique('name'); + }); + } +}; diff --git a/site/resources/views/auth/login.blade.php b/site/resources/views/auth/login.blade.php index 2aa5269..cdc0048 100644 --- a/site/resources/views/auth/login.blade.php +++ b/site/resources/views/auth/login.blade.php @@ -5,6 +5,7 @@

Sign in with your existing account

Welcome back! Please enter your credentials to sign in.

+

If you haven't logged in with your existing account since the upgrade, you need to reset your password using the forgot password link below.

@@ -15,9 +16,9 @@ @csrf {{-- Email Address --}}
- - - + + +
{{-- Password --}}