adds roles
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
namespace App\Http\Controllers\Auth;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Services\ActivityLogger;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
@@ -29,17 +30,25 @@ public function callback(): RedirectResponse
|
||||
{
|
||||
$azureUser = Socialite::driver('azure')->user();
|
||||
|
||||
$user = User::query()->firstOrCreate(
|
||||
$user = User::query()->updateOrCreate(
|
||||
['email' => $azureUser->getEmail()],
|
||||
[
|
||||
'name' => $azureUser->getName(),
|
||||
'password' => null,
|
||||
'azure_id' => $azureUser->getId(),
|
||||
'photo' => $azureUser->getAvatar(),
|
||||
'job_title' => Arr::get($azureUser->user, 'jobTitle'),
|
||||
'department' => Arr::get($azureUser->user, 'department'),
|
||||
'phone' => Arr::get($azureUser->user, 'mobilePhone', Arr::get($azureUser->user, 'businessPhones.0')),
|
||||
]
|
||||
);
|
||||
|
||||
if ($user->role_id === null) {
|
||||
$user->update(['role_id' => Role::where('name', 'user')->first()->id]);
|
||||
}
|
||||
|
||||
auth()->login($user);
|
||||
|
||||
ActivityLogger::log('login', $user->id, metadata: ['email' => $user->email, 'firm_name' => Arr::get($azureUser, 'companyName')]);
|
||||
ActivityLogger::log('login', $user->id, metadata: ['email' => $user->email, 'firm_name' => Arr::get($azureUser->user, 'companyName')]);
|
||||
|
||||
return redirect('/');
|
||||
}
|
||||
|
||||
@@ -68,10 +68,6 @@ public function update(UpdateSessionRequest $request, Session $session): Redirec
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
if (Arr::has($validated, 'basic_info')) {
|
||||
$session->update(['basic_info' => Arr::get($validated, 'basic_info')]);
|
||||
}
|
||||
|
||||
if (Arr::has($validated, 'answers')) {
|
||||
$this->saveAnswers($session, Arr::get($validated, 'answers'));
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Inertia\Middleware;
|
||||
use Laravel\Nova\Nova;
|
||||
|
||||
final class HandleInertiaRequests extends Middleware
|
||||
{
|
||||
@@ -32,6 +34,7 @@ public function share(Request $request): array
|
||||
...parent::share($request),
|
||||
'auth' => [
|
||||
'user' => $this->getAuthenticatedUser(),
|
||||
'logo_href' => $this->getLogoHref(),
|
||||
],
|
||||
'flash' => [
|
||||
'success' => fn () => Arr::get($request->session()->all(), 'success'),
|
||||
@@ -57,4 +60,18 @@ private function getAuthenticatedUser(): ?array
|
||||
'email' => $user->email,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine logo href based on user Nova access.
|
||||
*/
|
||||
private function getLogoHref(): string
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user !== null && Gate::allows('viewNova', $user)) {
|
||||
return Nova::path();
|
||||
}
|
||||
|
||||
return '/';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,6 @@ public function authorize(): bool
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'basic_info' => ['sometimes', 'required', 'array'],
|
||||
'basic_info.client_name' => ['required_with:basic_info', 'string', 'max:255'],
|
||||
'basic_info.client_contact' => ['required_with:basic_info', 'string', 'max:255'],
|
||||
'basic_info.lead_firm_name' => ['required_with:basic_info', 'string', 'max:255'],
|
||||
'basic_info.lead_firm_contact' => ['required_with:basic_info', 'string', 'max:255'],
|
||||
'answers' => ['sometimes', 'array'],
|
||||
'answers.*.value' => ['nullable', 'string', 'in:yes,no,not_applicable'],
|
||||
'answers.*.text_value' => ['nullable', 'string', 'max:10000'],
|
||||
@@ -41,20 +36,6 @@ public function rules(): array
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'basic_info.required' => 'Basic information is required.',
|
||||
'basic_info.array' => 'Basic information must be a valid data structure.',
|
||||
'basic_info.client_name.required_with' => 'The client name is required.',
|
||||
'basic_info.client_name.string' => 'The client name must be text.',
|
||||
'basic_info.client_name.max' => 'The client name cannot exceed 255 characters.',
|
||||
'basic_info.client_contact.required_with' => 'The client contact is required.',
|
||||
'basic_info.client_contact.string' => 'The client contact must be text.',
|
||||
'basic_info.client_contact.max' => 'The client contact cannot exceed 255 characters.',
|
||||
'basic_info.lead_firm_name.required_with' => 'The lead firm name is required.',
|
||||
'basic_info.lead_firm_name.string' => 'The lead firm name must be text.',
|
||||
'basic_info.lead_firm_name.max' => 'The lead firm name cannot exceed 255 characters.',
|
||||
'basic_info.lead_firm_contact.required_with' => 'The lead firm contact is required.',
|
||||
'basic_info.lead_firm_contact.string' => 'The lead firm contact must be text.',
|
||||
'basic_info.lead_firm_contact.max' => 'The lead firm contact cannot exceed 255 characters.',
|
||||
'answers.array' => 'Answers must be a valid data structure.',
|
||||
'answers.*.value.in' => 'Answer value must be yes, no, or not_applicable.',
|
||||
'answers.*.text_value.string' => 'Answer text must be text.',
|
||||
|
||||
Reference in New Issue
Block a user