mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-24 07:28:05 +02:00
chore: add detailed login logging and update startup message
This commit is contained in:
1 parent
948e405307
commit
a149bf266c
2 files changed
+14
-3
No files matched your search
@@ -21,35 +21,46 @@ class AuthHandler {
|
|||||||
/// POST /api/auth/login
|
/// POST /api/auth/login
|
||||||
Future<Response> _login(Request request) async {
|
Future<Response> _login(Request request) async {
|
||||||
try {
|
try {
|
||||||
final payload = jsonDecode(await request.readAsString()) as Map<String, dynamic>;
|
print('[Auth] Login attempt received');
|
||||||
|
final bodyStr = await request.readAsString();
|
||||||
|
print('[Auth] Request body: $bodyStr');
|
||||||
|
|
||||||
|
final payload = jsonDecode(bodyStr) as Map<String, dynamic>;
|
||||||
final username = payload['username'] as String?;
|
final username = payload['username'] as String?;
|
||||||
final password = payload['password'] as String?;
|
final password = payload['password'] as String?;
|
||||||
|
|
||||||
if (username == null || password == null) {
|
if (username == null || password == null) {
|
||||||
|
print('[Auth] Missing username or password');
|
||||||
return Response(400, body: jsonEncode({
|
return Response(400, body: jsonEncode({
|
||||||
'success': false,
|
'success': false,
|
||||||
'error': 'Username and password are required',
|
'error': 'Username and password are required',
|
||||||
}), headers: {'Content-Type': 'application/json'},);
|
}), headers: {'Content-Type': 'application/json'},);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print('[Auth] Verifying credentials for user: $username');
|
||||||
// Verify credentials
|
// Verify credentials
|
||||||
final user = db.verifyCredentials(username, password);
|
final user = db.verifyCredentials(username, password);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
|
print('[Auth] Invalid credentials for user: $username');
|
||||||
return Response(401, body: jsonEncode({
|
return Response(401, body: jsonEncode({
|
||||||
'success': false,
|
'success': false,
|
||||||
'error': 'Invalid credentials',
|
'error': 'Invalid credentials',
|
||||||
}), headers: {'Content-Type': 'application/json'},);
|
}), headers: {'Content-Type': 'application/json'},);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print('[Auth] User verified, creating session for userId: ${user.id}');
|
||||||
// Create session
|
// Create session
|
||||||
final session = db.createSession(user.id);
|
final session = db.createSession(user.id);
|
||||||
|
print('[Auth] Session created with token: ${session.token.substring(0, 8)}...');
|
||||||
|
|
||||||
return Response.ok(jsonEncode({
|
return Response.ok(jsonEncode({
|
||||||
'success': true,
|
'success': true,
|
||||||
'user': user.toJson(),
|
'user': user.toJson(),
|
||||||
'token': session.token,
|
'token': session.token,
|
||||||
}), headers: {'Content-Type': 'application/json'},);
|
}), headers: {'Content-Type': 'application/json'},);
|
||||||
} catch (e) {
|
} catch (e, stackTrace) {
|
||||||
|
print('[Auth] ERROR during login: $e');
|
||||||
|
print('[Auth] Stack trace: $stackTrace');
|
||||||
return Response.internalServerError(
|
return Response.internalServerError(
|
||||||
body: jsonEncode({'success': false, 'error': e.toString()}),
|
body: jsonEncode({'success': false, 'error': e.toString()}),
|
||||||
headers: {'Content-Type': 'application/json'},
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
|||||||
+1
-1
@@ -278,7 +278,7 @@ void main(List<String> args) async {
|
|||||||
print('Server started on port ${server.port}');
|
print('Server started on port ${server.port}');
|
||||||
print('Serving static files from: $webPath');
|
print('Serving static files from: $webPath');
|
||||||
print('REST API available at: /api/auth/* and /api/playlists/*');
|
print('REST API available at: /api/auth/* and /api/playlists/*');
|
||||||
print('Xtream proxy available at: /api/xtream/* (Authenticated)');
|
print('Xtream proxy available at: /api/xtream/* (SSRF Protected)');
|
||||||
|
|
||||||
// Clean expired sessions periodically (every hour)
|
// Clean expired sessions periodically (every hour)
|
||||||
Timer.periodic(const Duration(hours: 1), (_) {
|
Timer.periodic(const Duration(hours: 1), (_) {
|
||||||
|
|||||||
Reference in new issue
Block a user