Fix: Encode Response body as JSON string in _watch endpoint
This commit is contained in:
@@ -30,6 +30,7 @@ class AuthRoutes {
|
|||||||
final user = await database.findUserByLogin(login);
|
final user = await database.findUserByLogin(login);
|
||||||
|
|
||||||
if (user == null || !BCrypt.checkpw(password, user.pwdHash)) {
|
if (user == null || !BCrypt.checkpw(password, user.pwdHash)) {
|
||||||
|
await database.createLog(login, 'Failed login attempt');
|
||||||
return Response(401, body: 'Invalid credentials');
|
return Response(401, body: 'Invalid credentials');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,6 +43,7 @@ class AuthRoutes {
|
|||||||
);
|
);
|
||||||
final token = jwt.sign(SecretKey(secret));
|
final token = jwt.sign(SecretKey(secret));
|
||||||
|
|
||||||
|
await database.createLog(login, 'Successful login');
|
||||||
return Response(200, body: jsonEncode({
|
return Response(200, body: jsonEncode({
|
||||||
'user': user.toMap(),
|
'user': user.toMap(),
|
||||||
'token': token
|
'token': token
|
||||||
@@ -56,22 +58,26 @@ class AuthRoutes {
|
|||||||
final password = data['password'];
|
final password = data['password'];
|
||||||
|
|
||||||
final user = await database.createUser(login, password);
|
final user = await database.createUser(login, password);
|
||||||
|
await database.createLog(login, 'User registration');
|
||||||
return Response(201, body: jsonEncode(user.toMap()));
|
return Response(201, body: jsonEncode(user.toMap()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Response> _watch(Request request) async {
|
Future<Response> _watch(Request request, String login) async {
|
||||||
final uniqueId = request.url.queryParameters['unique_id'];
|
final uniqueId = request.url.queryParameters['unique_id'];
|
||||||
|
|
||||||
if (!database.isValidShareId(uniqueId!)) {
|
if (!database.isValidShareId(uniqueId!)) {
|
||||||
|
await database.createLog(login, 'Accessed invalid share link');
|
||||||
return Response(404, body: 'Share link not found');
|
return Response(404, body: 'Share link not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
final position = await database.getLatestPosition();
|
final position = await database.getLatestPosition();
|
||||||
|
|
||||||
if (position == null) {
|
if (position == null) {
|
||||||
|
await database.createLog(login, 'Accessed share link - no position');
|
||||||
return Response(404, body: 'No position available');
|
return Response(404, body: 'No position available');
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response(200, body: position.toJson());
|
await database.createLog(login, 'Accessed share link');
|
||||||
|
return Response(200, body: jsonEncode(position.toJson()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user