Skip to content

Commit

Permalink
WIP add sso details to admin user management, add missing admin role …
Browse files Browse the repository at this point in the history
…assignment to setup (#174 #194)
  • Loading branch information
Kovah committed Sep 19, 2024
1 parent a9d92e8 commit 0ab7779
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
2 changes: 2 additions & 0 deletions app/Http/Controllers/Setup/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Setup;

use App\Actions\Fortify\CreateNewUser;
use App\Enums\Role;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
Expand All @@ -27,6 +28,7 @@ public function index(): View
protected function register(Request $request): RedirectResponse
{
$user = (new CreateNewUser())->create($request->input());
$user->assignRole(Role::ADMIN);

Auth::login($user, true);

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/SocialiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function callback(string $provider)
if ($user = User::where('email', $authUser->getEmail())->first()) {
if ($user->sso_provider !== null && $user->sso_provider !== $provider) {
abort(403, trans('auth.sso_wrong_provider', [
'currentProvider' => trans('auth.sso.' . $provider),
'userProvider' => trans('auth.sso.' . $user->sso_provider),
'currentProvider' => trans('auth.sso_provider.' . $provider),
'userProvider' => trans('auth.sso_provider.' . $user->sso_provider),
]));
}

Expand Down
5 changes: 5 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,9 @@ public function isSystemUser(): bool
{
return $this->id === 0;
}

public function isSsoUser(): bool
{
return $this->sso_id !== null;
}
}
5 changes: 4 additions & 1 deletion lang/en_US/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@
'api_tokens.revoke_confirm' => 'Do you really want to revoke this token? This step cannot be undone and the token cannot be recovered.',
'api_tokens.revoke_successful' => 'The token was revoked successfully.',

'sso' => 'SSO',
'sso_account_provider' => 'SSO Provider',
'sso_account_id' => 'SSO ID',
'sso_provider_disabled' => 'The selected SSO provider is not available. Please choose another one.',
'sso_wrong_provider' => 'Unable to login with :currentProvider. Please use :userProvider to login, or contact your administrator for help.',

'sso' => [
'sso_provider' => [
'auth0' => 'Auth0',
'authentik' => 'Authentik',
'azure' => 'Azure',
Expand Down
3 changes: 3 additions & 0 deletions resources/views/admin/users/partials/user-list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<div class="list-group-item d-md-flex justify-content-between">
<div>
{{ $user->name }} <span class="ms-2 text-muted">{{ $user->email }}</span>
@if($user->isSsoUser())
<span class="badge bg-secondary">@lang('auth.sso')</span>
@endif
@if($user->isBlocked())
<span class="badge bg-warning">@lang('linkace.blocked')</span>
@endif
Expand Down
22 changes: 14 additions & 8 deletions resources/views/admin/users/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
<div>{{ $user->email }}</div>
<div class="mt-3 small text-muted">@lang('linkace.created_at') {{ $user->created_at }}</div>
</div>
@if($user->isSsoUser())
<div class="card-body">
<div>@lang('auth.sso_account_provider'): @lang('auth.sso_provider.' . $user->sso_provider)</div>
<div>@lang('auth.sso_account_id'): {{ $user->sso_id }}</div>
</div>
@endif
<div class="card-footer">

@if($user->isBlocked())
Expand All @@ -41,26 +47,26 @@ class="btn btn-sm btn-outline-danger">
</button>
@endif
<form action="{{ route('system.users.block', ['user' => $user]) }}"
id="block-user-{{ $user->id }}"
method="post" class="d-none" data-confirmation="@lang('user.block_confirmation')">
id="block-user-{{ $user->id }}"
method="post" class="d-none" data-confirmation="@lang('user.block_confirmation')">
@csrf
@method('PATCH')
</form>
<form action="{{ route('system.users.unblock', ['user' => $user]) }}"
id="unblock-user-{{ $user->id }}"
method="post" class="d-none" data-confirmation="@lang('user.unblock_confirmation')">
id="unblock-user-{{ $user->id }}"
method="post" class="d-none" data-confirmation="@lang('user.unblock_confirmation')">
@csrf
@method('PATCH')
</form>
<form action="{{ route('system.users.delete', ['user' => $user]) }}"
id="delete-user-{{ $user->id }}"
method="post" class="d-none" data-confirmation="@lang('user.delete_confirmation')">
id="delete-user-{{ $user->id }}"
method="post" class="d-none" data-confirmation="@lang('user.delete_confirmation')">
@csrf
@method('DELETE')
</form>
<form action="{{ route('system.users.restore', ['user' => $user]) }}"
id="restore-user-{{ $user->id }}"
method="post" class="d-none" data-confirmation="@lang('user.restore_confirmation')">
id="restore-user-{{ $user->id }}"
method="post" class="d-none" data-confirmation="@lang('user.restore_confirmation')">
@csrf
@method('PATCH')
</form>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/oauth.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@foreach(config('auth.sso.providers') as $provider)
@if(config('services.'.$provider.'.enabled') === true)
<a href="{{ route('auth.sso.redirect', ['provider' => $provider]) }}" class="btn btn-outline-primary">
<x-dynamic-component :component="'icon.brand.'.$provider" class="me-1"/> @lang('auth.sso.'.$provider)
<x-dynamic-component :component="'icon.brand.'.$provider" class="me-1"/> @lang('auth.sso_provider.'.$provider)
</a>
@endif
@endforeach
Expand Down

0 comments on commit 0ab7779

Please sign in to comment.