Phase 8 Mobil: REST-API, Web-Push, installierbare App (0.25.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m54s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m0s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m54s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m50s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m48s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m38s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m56s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 7m5s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m54s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 4m0s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m54s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m50s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m48s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m38s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m56s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 7m5s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
232dc5c59c
commit
f11a3e24b3
201 changed files with 3604 additions and 427 deletions
70
app/Http/Controllers/Api/AuthController.php
Normal file
70
app/Http/Controllers/Api/AuthController.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Support\Audit;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class AuthController extends Controller
|
||||
{
|
||||
/**
|
||||
* Token für eine App (nur Konten mit Portal-Passwort; bei Anmeldung über
|
||||
* Microsoft & Co. erzeugt man das Token unter „Profil → Apps & Geräte“).
|
||||
*/
|
||||
public function token(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'email' => ['required', 'email'],
|
||||
'password' => ['required', 'string'],
|
||||
'device_name' => ['required', 'string', 'max:100'],
|
||||
]);
|
||||
|
||||
$user = User::query()->where('email', $data['email'])->first();
|
||||
|
||||
if (! $user || ! $user->is_active || $user->password === null || ! Hash::check($data['password'], $user->password)) {
|
||||
throw ValidationException::withMessages(['email' => 'Diese Kombination aus Zugangsdaten wurde nicht gefunden.']);
|
||||
}
|
||||
|
||||
$token = $user->createToken(trim($data['device_name']));
|
||||
Audit::log('api.token_created', ['user' => $user->id, 'device' => $data['device_name']]);
|
||||
|
||||
return response()->json(['token' => $token->plainTextToken, 'user' => self::profile($user)], 201);
|
||||
}
|
||||
|
||||
public function me(Request $request): JsonResponse
|
||||
{
|
||||
return response()->json(['user' => self::profile($request->user())]);
|
||||
}
|
||||
|
||||
public function revoke(Request $request): JsonResponse
|
||||
{
|
||||
$request->user()->currentAccessToken()?->delete();
|
||||
|
||||
return response()->json(['revoked' => true]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private static function profile(User $user): array
|
||||
{
|
||||
return [
|
||||
'id' => $user->id,
|
||||
'name' => $user->name,
|
||||
'first_name' => $user->first_name,
|
||||
'last_name' => $user->last_name,
|
||||
'email' => $user->email,
|
||||
'job_title' => $user->job_title,
|
||||
'department' => $user->department,
|
||||
'location' => $user->location,
|
||||
'avatar_url' => $user->avatarUrl(256),
|
||||
'cover_url' => $user->coverUrl(),
|
||||
'unread_notifications' => $user->unreadNotifications()->count(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue