Auditionadmin 64 #71
|
|
@ -4,14 +4,20 @@ namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Actions\Schools\SetHeadDirector;
|
use App\Actions\Schools\SetHeadDirector;
|
||||||
use App\Exceptions\AuditionAdminException;
|
use App\Exceptions\AuditionAdminException;
|
||||||
|
use App\Mail\NewUserPassword;
|
||||||
use App\Models\AuditLogEntry;
|
use App\Models\AuditLogEntry;
|
||||||
use App\Models\School;
|
use App\Models\School;
|
||||||
use App\Models\SchoolEmailDomain;
|
use App\Models\SchoolEmailDomain;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
use function abort;
|
use function abort;
|
||||||
|
use function auditionLog;
|
||||||
use function redirect;
|
use function redirect;
|
||||||
use function request;
|
use function request;
|
||||||
|
|
||||||
|
|
@ -150,4 +156,39 @@ class SchoolController extends Controller
|
||||||
|
|
||||||
return redirect('/schools/create');
|
return redirect('/schools/create');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addDirector(School $school)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (auth()->user()->school_id !== $school->id) {
|
||||||
|
return redirect()->back()->with('error', 'No adding directors to another school');
|
||||||
|
}
|
||||||
|
if (! auth()->user()->hasFlag('head_director')) {
|
||||||
|
return redirect()->back()->with('error', 'Only the head director can add directors to a school');
|
||||||
|
}
|
||||||
|
$validData = request()->validate([
|
||||||
|
'first_name' => ['required'],
|
||||||
|
'last_name' => ['required'],
|
||||||
|
'email' => ['required', 'email', 'unique:users'],
|
||||||
|
'cell_phone' => ['required'],
|
||||||
|
'judging_preference' => ['required'],
|
||||||
|
]);
|
||||||
|
// Generate a random password
|
||||||
|
$randomPassword = Str::random(12);
|
||||||
|
$newUser = User::create([
|
||||||
|
'first_name' => $validData['first_name'],
|
||||||
|
'last_name' => $validData['last_name'],
|
||||||
|
'email' => $validData['email'],
|
||||||
|
'cell_phone' => $validData['cell_phone'],
|
||||||
|
'judging_preference' => $validData['judging_preference'],
|
||||||
|
'password' => Hash::make($randomPassword),
|
||||||
|
'school_id' => auth()->user()->school_id,
|
||||||
|
]);
|
||||||
|
$logMessage = 'Created user '.$newUser->full_name().' - '.$newUser->email.' as a director at '.$newUser->school->name;
|
||||||
|
$logAffected = ['users' => [$newUser->id], 'schools' => [$newUser->school_id]];
|
||||||
|
auditionLog($logMessage, $logAffected);
|
||||||
|
Mail::to($newUser->email)->send(new NewUserPassword($newUser, $randomPassword));
|
||||||
|
|
||||||
|
return redirect()->back()->with('success', 'Director added');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Hello, {{ $user->first_name }} {{ $user->last_name }}</h1>
|
<h1>Hello, {{ $user->first_name }} {{ $user->last_name }}</h1>
|
||||||
<p>Your account has been created. Here are your login details:</p>
|
<p>Your AuditionAdmin account for {{ auditionSetting('auditionAbbreviation') }} has been created. Here are your login details:</p>
|
||||||
<p><strong>Email:</strong> {{ $user->email }}</p>
|
<p><strong>Email:</strong> {{ $user->email }}</p>
|
||||||
<p><strong>Password:</strong> {{ $password }}</p>
|
<p><strong>Password:</strong> {{ $password }}</p>
|
||||||
|
<p><strong>Login at: </strong> {{route('login')}}</p>
|
||||||
<p>Please change your password after logging in for the first time.</p>
|
<p>Please change your password after logging in for the first time.</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
<x-layout.app>
|
<div x-data="{ showAddDirectorForm: false, changeHeadDirectorForm: false}">
|
||||||
|
<x-layout.app>
|
||||||
<x-slot:page_title>School Info - {{ $school->name }}</x-slot:page_title>
|
<x-slot:page_title>School Info - {{ $school->name }}</x-slot:page_title>
|
||||||
|
|
||||||
<div class="mx-auto max-w-xl">
|
<div class="mx-auto max-w-xl">
|
||||||
|
|
@ -20,9 +21,20 @@
|
||||||
<x-card.info.row row_name="Directors">
|
<x-card.info.row row_name="Directors">
|
||||||
<ul>
|
<ul>
|
||||||
@foreach($school->directors as $director)
|
@foreach($school->directors as $director)
|
||||||
<li>{{ $director->full_name() }} - <a class='text-indigo-600' href="mailto:{{ $director->email }}">{{ $director->email }}</a></li>
|
<li>
|
||||||
|
{{ $director->full_name() }}
|
||||||
|
@if($director->hasFlag('head_director')) <span class="font-semibold">(head)</span> @endif
|
||||||
|
-
|
||||||
|
<a class='text-indigo-600' href="mailto:{{ $director->email }}">{{ $director->email }}</a>
|
||||||
|
</li>
|
||||||
@endforeach
|
@endforeach
|
||||||
</ul>
|
</ul>
|
||||||
|
@if(auth()->user()->hasFlag('head_director'))
|
||||||
|
<div class="grid grid-cols-2 gap-2 mt-3">
|
||||||
|
<x-form.button type="button" @click="showAddDirectorForm=true">Add Director</x-form.button>
|
||||||
|
<x-form.button type="button" @click="changeHeadDirectorForm=true">Change Head</x-form.button>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
</x-card.info.row>
|
</x-card.info.row>
|
||||||
|
|
||||||
<x-card.info.row row_name="Associated Email Domains">
|
<x-card.info.row row_name="Associated Email Domains">
|
||||||
|
|
@ -36,4 +48,25 @@
|
||||||
</x-card.card>
|
</x-card.card>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</x-layout.app>
|
</x-layout.app>
|
||||||
|
|
||||||
|
@if(auth()->user()->hasFlag('head_director'))
|
||||||
|
<x-modal-body showVar="showAddDirectorForm">
|
||||||
|
<x-slot:title>Add Director</x-slot:title>
|
||||||
|
<x-form.form method="POST" action="{{route('schools.add_director', $school)}}">
|
||||||
|
<x-form.body-grid>
|
||||||
|
<x-form.field name="first_name" label_text="First Name" colspan="3" />
|
||||||
|
<x-form.field name="last_name" label_text="Last Name" colspan="3" />
|
||||||
|
<x-form.field name="email" type="email" label_text="Email Address" colspan="3" />
|
||||||
|
<x-form.field name="cell_phone" label_text="Cell Phone" colspan="3" />
|
||||||
|
<x-form.field name="judging_preference" label_text="Judging Preference" colspan="6" />
|
||||||
|
</x-form.body-grid>
|
||||||
|
<x-form.footer submit-button-text="Add Director" />
|
||||||
|
</x-form.form>
|
||||||
|
</x-modal-body>
|
||||||
|
|
||||||
|
<x-modal-body showVar="changeHeadDirectorForm">
|
||||||
|
<x-slot:title>Change Head Director</x-slot:title>
|
||||||
|
</x-modal-body>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ Route::middleware(['auth', 'verified'])->controller(SchoolController::class)->gr
|
||||||
Route::get('/schools/{school}/edit', 'edit')->name('schools.edit');
|
Route::get('/schools/{school}/edit', 'edit')->name('schools.edit');
|
||||||
Route::get('/schools/{school}', 'show')->name('schools.show');
|
Route::get('/schools/{school}', 'show')->name('schools.show');
|
||||||
Route::patch('/schools/{school}', 'update')->name('schools.update');
|
Route::patch('/schools/{school}', 'update')->name('schools.update');
|
||||||
|
Route::post('schools/{school}/add_director', 'addDirector')->name('schools.add_director');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Doubler Related Routes
|
// Doubler Related Routes
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue