Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login form optional password #863

Merged
merged 2 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ public function loginAsUser(Request $request, User $user)
return redirect()->route('login');
}

/**
* @return \Illuminate\Http\RedirectResponse
*/
public function loginAs(Request $request)
{
if (config('auth.user_list')) {
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved
$user = User::where('id', $request->get('user'))->first();
Auth::login($user, true);
return $this->sendLoginResponse($request);
}
return redirect()->route('login');
}

protected function authenticated(Request $request, $user)
{
$response = $this->userAuthService->authenticated($user);
Expand Down
81 changes: 44 additions & 37 deletions resources/views/auth/login.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,51 +21,58 @@
</li>
@endforeach
</ul>
@endif


<form method="POST" action="{{ route('login') }}" class="w-full">
{{ csrf_field() }}
<div class="mb-3 {{ $errors->has('email') ? ' has-error' : '' }}">
@if(config('auth.user_list'))
<select id="email" name="email" class="rounded border p-2 w-full dark:bg-slate-800 dark:border-slate-500">
@foreach (\App\User::limit(30)->get() as $user)
<option value="{{ $user->email}}">{!! $user->name !!} @if ($user->pledge) ({!! $user->pledge !!}) @endif</option>
@endforeach
</select>
@else
<input id="email" type="email" class="rounded border p-2 w-full dark:bg-slate-800 dark:border-slate-500" name="email" value="{{ old('email') }}" placeholder="{{ __('auth.login.fields.email') }}" required autofocus>
@endif
<form method="GET" action="{{ route('login-as') }}" class="w-full">
{{ csrf_field() }}
@if(config('auth.user_list'))
spitfire305 marked this conversation as resolved.
Show resolved Hide resolved
<select id="user" name="user" class="rounded border p-2 w-full dark:bg-slate-800 dark:border-slate-500">
@foreach (\App\User::limit(30)->get() as $user)
<option value="{{ $user->id }}">{!! $user->name !!} @if ($user->pledge) ({!! $user->pledge !!}) @endif</option>
@endforeach
</select>
@endif

@if ($errors->has('email'))
<span class="text-red-500">
{{ $errors->first('email') }}
</span>
@endif
</div>
<button type="submit" class="w-full rounded border border-blue-500 text-blue-500 uppercase px-6 py-2 transition-all bg-white hover:shadow-xs hover:bg-blue-500 hover:text-white dark:bg-slate-800">
{{ __('auth.login.submit') }}
</button>
</form>
@else
<form method="POST" action="{{ route('login') }}" class="w-full">
{{ csrf_field() }}
<div class="mb-3 {{ $errors->has('email') ? ' has-error' : '' }}">
<input id="email" type="email" class="rounded border p-2 w-full dark:bg-slate-800 dark:border-slate-500" name="email" value="{{ old('email') }}" placeholder="{{ __('auth.login.fields.email') }}" required autofocus>

<div class="mb-3 {{ $errors->has('password') ? ' has-error' : '' }}">
<div class="flex items-stretch w-full">
<input id="password" type="password" class="border rounded w-full p-2 dark:bg-slate-800 dark:border-slate-500" name="password" required placeholder="{{ __('auth.login.fields.password') }}">
<a href="#" id="toggle-password" class="input-group-addon p-2" title="{{ __('auth.helpers.password') }}">
<i id="toggle-password-icon" class="fa-solid fa-eye" aria-hidden="true"></i>
<span class="sr-only">{{ __('auth.helpers.password') }}</span>
</a>
@if ($errors->has('email'))
<span class="text-red-500">
{{ $errors->first('email') }}
</span>
@endif
</div>

@if ($errors->has('password'))
<span class="text-red-500">
{{ $errors->first('password') }}
</span>
@endif
</div>
<div class="mb-3 {{ $errors->has('password') ? ' has-error' : '' }}">
<div class="flex items-stretch w-full">
<input id="password" type="password" class="border rounded w-full p-2 dark:bg-slate-800 dark:border-slate-500" name="password" required placeholder="{{ __('auth.login.fields.password') }}">
<a href="#" id="toggle-password" class="input-group-addon p-2" title="{{ __('auth.helpers.password') }}">
<i id="toggle-password-icon" class="fa-solid fa-eye" aria-hidden="true"></i>
<span class="sr-only">{{ __('auth.helpers.password') }}</span>
</a>
</div>

<input type="hidden" name="remember" value="1" />
@if ($errors->has('password'))
<span class="text-red-500">
{{ $errors->first('password') }}
</span>
@endif
</div>

<input type="hidden" name="remember" value="1" />

<button type="submit" class="w-full rounded border border-blue-500 text-blue-500 uppercase px-6 py-2 transition-all bg-white hover:shadow-xs hover:bg-blue-500 hover:text-white dark:bg-slate-800">
{{ __('auth.login.submit') }}
</button>
</form>
<button type="submit" class="w-full rounded border border-blue-500 text-blue-500 uppercase px-6 py-2 transition-all bg-white hover:shadow-xs hover:bg-blue-500 hover:text-white dark:bg-slate-800">
{{ __('auth.login.submit') }}
</button>
</form>
@endif

@if(config('auth.register_enabled'))
<div class="social-auth-links text-center mb-3">
Expand Down
1 change: 1 addition & 0 deletions routes/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
Route::get('/login-as-user/{user}', [LoginController::class, 'loginAsUser'])->name('login-as-user');
Route::get('/login-as', [LoginController::class, 'loginAs'])->name('login-as');

// OAuth Routes
Route::get('auth/{provider}', [AuthController::class, 'redirectToProvider'])->name('auth.provider');
Expand Down
Loading