Anträge annehmen und Benutzer zu Mitglied machen
This commit is contained in:
parent
1137a794aa
commit
84c8e5b846
5 changed files with 164 additions and 4 deletions
|
|
@ -7,6 +7,7 @@ namespace App\Controllers;
|
|||
use App\Core\Auth;
|
||||
use App\Models\MembershipApplication;
|
||||
use App\Models\Page;
|
||||
use App\Models\User;
|
||||
|
||||
class AdminController
|
||||
{
|
||||
|
|
@ -64,7 +65,92 @@ class AdminController
|
|||
exit('Antrag nicht gefunden.');
|
||||
}
|
||||
|
||||
view('admin.application', ['application' => $application]);
|
||||
view('admin.application', [
|
||||
'application' => $application,
|
||||
'acceptedBy' => $application->accepted_by ? User::find((int) $application->accepted_by) : null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function acceptApplication(string $id): void
|
||||
{
|
||||
$application = MembershipApplication::find((int) $id);
|
||||
|
||||
if ($application === null) {
|
||||
flash_set('error', 'Der Antrag wurde nicht gefunden.');
|
||||
redirect('/admin/antraege');
|
||||
}
|
||||
|
||||
if (!empty($application->accepted_at)) {
|
||||
flash_set('status', 'Der Antrag wurde bereits angenommen.');
|
||||
redirect('/admin/antraege/' . $id);
|
||||
}
|
||||
|
||||
$user = $application->user_id ? User::find((int) $application->user_id) : null;
|
||||
|
||||
if ($user === null && !empty($application->email)) {
|
||||
$user = User::byEmail((string) $application->email);
|
||||
}
|
||||
|
||||
if ($user === null) {
|
||||
flash_set('error', 'Zu diesem Antrag wurde kein Benutzerkonto gefunden. Bitte zuerst ein Konto mit der angegebenen E-Mail-Adresse anlegen.');
|
||||
redirect('/admin/antraege/' . $id);
|
||||
}
|
||||
|
||||
$roleChanged = false;
|
||||
|
||||
if ($user->role === 'GUEST') {
|
||||
$user->role = 'MEMBER';
|
||||
$user->updated_at = now();
|
||||
$user->save();
|
||||
$roleChanged = true;
|
||||
}
|
||||
|
||||
$application->user_id = (int) $user->id;
|
||||
$application->accepted_at = now();
|
||||
$application->accepted_by = Auth::id();
|
||||
$application->updated_at = now();
|
||||
$application->save();
|
||||
|
||||
app_log('info', 'Mitgliedsantrag angenommen', [
|
||||
'application_id' => (int) $id,
|
||||
'user_id' => (int) $user->id,
|
||||
'role' => $user->role,
|
||||
]);
|
||||
|
||||
flash_set('status', $roleChanged
|
||||
? 'Antrag angenommen. Der Benutzer ist jetzt Mitglied.'
|
||||
: 'Antrag angenommen. Der Benutzer hatte bereits eine Mitglieds- oder höhere Rolle.');
|
||||
|
||||
redirect('/admin/antraege/' . $id);
|
||||
}
|
||||
|
||||
public function deleteApplication(string $id): void
|
||||
{
|
||||
$application = MembershipApplication::find((int) $id);
|
||||
|
||||
if ($application === null) {
|
||||
flash_set('error', 'Der Antrag wurde nicht gefunden.');
|
||||
redirect('/admin/antraege');
|
||||
}
|
||||
|
||||
$dir = storage_path('img_storage/mitgliedsantrag');
|
||||
|
||||
foreach (['unterschrift_1', 'unterschrift_2'] as $field) {
|
||||
$file = basename((string) $application->$field);
|
||||
|
||||
if ($file !== '' && is_file($dir . '/' . $file)) {
|
||||
@unlink($dir . '/' . $file);
|
||||
}
|
||||
}
|
||||
|
||||
$application->delete();
|
||||
|
||||
app_log('info', 'Mitgliedsantrag gelöscht', [
|
||||
'application_id' => (int) $id,
|
||||
]);
|
||||
|
||||
flash_set('status', 'Der Antrag wurde gelöscht.');
|
||||
redirect('/admin/antraege');
|
||||
}
|
||||
|
||||
public function editHome(): void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue