session creation

This commit is contained in:
Blue 2023-12-23 17:23:38 -03:00
parent 534c282226
commit 4b87b560ac
Signed by: blue
GPG key ID: 9B203B252A63EE38
12 changed files with 152 additions and 25 deletions

View file

@ -33,24 +33,34 @@ void Handler::Login::handle(Request& request) {
try {
success = server->validatePassword(login, password);
} catch (const DBInterface::NoLogin& e) {
std::cerr << "Exception on registration:\n\t" << e.what() << std::endl;
std::cerr << "Exception on logging in:\n\t" << e.what() << std::endl;
return error(request, Result::noLogin, Response::Status::badRequest); //can send unauthed instead, to exclude login spoofing
} catch (const std::exception& e) {
std::cerr << "Exception on registration:\n\t" << e.what() << std::endl;
std::cerr << "Exception on logging in:\n\t" << e.what() << std::endl;
return error(request, Result::unknownError, Response::Status::internalError);
} catch (...) {
std::cerr << "Unknown exception on registration" << std::endl;
std::cerr << "Unknown exception on ogging in" << std::endl;
return error(request, Result::unknownError, Response::Status::internalError);
}
if (!success)
return error(request, Result::noLogin, Response::Status::badRequest);
//TODO opening the session
Response& res = request.createResponse();
nlohmann::json body = nlohmann::json::object();
body["result"] = Result::success;
try {
Session& session = server->openSession(login);
body["accessToken"] = session.getAccessToken();
body["renewToken"] = session.getRenewToken();
} catch (const std::exception& e) {
std::cerr << "Exception on opening a session:\n\t" << e.what() << std::endl;
return error(request, Result::unknownError, Response::Status::internalError);
} catch (...) {
std::cerr << "Unknown exception on opening a session" << std::endl;
return error(request, Result::unknownError, Response::Status::internalError);
}
Response& res = request.createResponse();
res.setBody(body);
res.send();
}