schneespur/release/schneespur-1.0.2/app/Http/Middleware/AuthenticateOwntracks.php
Michael 7288b93500 Release v1.0.2: diagnostic infrastructure core
Add neutral diagnostic framework for future reporting modules:
- DiagnosticReporterInterface, Registry, Manager, PayloadSanitizer
- Laravel exception hook in bootstrap/app.php
- Module permission declarations (requires_permissions in module.json)
- Core diagnostic report points (module boot/install/update failures)
- Module documentation update (moduldoku.md)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-18 16:54:11 +00:00

32 lines
847 B
PHP

<?php
namespace App\Http\Middleware;
use App\Models\User;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Symfony\Component\HttpFoundation\Response;
class AuthenticateOwntracks
{
public function handle(Request $request, Closure $next): Response
{
$username = $request->getUser();
$password = $request->getPassword();
if ($username === null || $password === null) {
return response()->json(['error' => 'Unauthorized'], 401);
}
$user = User::where('owntracks_username', $username)->first();
if (! $user || ! Hash::check($password, $user->owntracks_password_hash)) {
return response()->json(['error' => 'Unauthorized'], 401);
}
$request->setUserResolver(fn () => $user);
return $next($request);
}
}