Added loging page
This commit is contained in:
@@ -41,7 +41,7 @@ void initLogin(crow::SimpleApp& app)
|
||||
|
||||
CROW_ROUTE(app, "/login").methods("POST"_method)
|
||||
([](const crow::request& req) {
|
||||
auto body = utils::parseBody(req.body);
|
||||
nlohmann::json body = nlohmann::json::parse(req.body); // parse JSON from HTTP body
|
||||
if (!body.empty())
|
||||
return crow::response(400, "Invalid JSON");
|
||||
|
||||
@@ -50,8 +50,8 @@ void initLogin(crow::SimpleApp& app)
|
||||
if(usenameIt == body.end() || passwordIt == body.end())
|
||||
return crow::response(400, "No username or password in body");
|
||||
|
||||
const std::string& username = usenameIt->second;
|
||||
const std::string& password = passwordIt->second;
|
||||
const std::string& username = *usenameIt;
|
||||
const std::string& password = *passwordIt;
|
||||
|
||||
// Validate credentials
|
||||
auto sessionId = loginUser(username, password);
|
||||
@@ -67,6 +67,8 @@ void initLogin(crow::SimpleApp& app)
|
||||
"; HttpOnly; Path=/; SameSite=Strict"
|
||||
// add "; Secure" when using HTTPS
|
||||
);
|
||||
res.set_header("Access-Control-Allow-Credentials", "true");
|
||||
res.set_header("Access-Control-Allow-Origin", "http://localhost:5173");
|
||||
|
||||
res.body = "Logged in";
|
||||
return res;
|
||||
|
||||
Reference in New Issue
Block a user