login now works and files are protected
This commit is contained in:
@@ -29,20 +29,21 @@ bool isLoggedIn(const crow::request& req) {
|
||||
std::optional<std::string> loginUser(const std::string& username, const std::string& password)
|
||||
{
|
||||
auto user = getVerifiedUser(username, password);
|
||||
if (user.has_value()) {
|
||||
return sessionHandler.createSession(user.value().id);
|
||||
if (user) {
|
||||
return sessionHandler.createSession(user->id);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void initLogin(crow::SimpleApp& app)
|
||||
{
|
||||
// createUser("lukas", "Trollar4928");
|
||||
|
||||
//createUser("lukas", "Trollar4928");
|
||||
|
||||
CROW_ROUTE(app, "/login").methods("POST"_method)
|
||||
([](const crow::request& req) {
|
||||
nlohmann::json body = nlohmann::json::parse(req.body); // parse JSON from HTTP body
|
||||
if (!body.empty())
|
||||
if (body.empty())
|
||||
return crow::response(400, "Invalid JSON");
|
||||
|
||||
auto usenameIt = body.find("username");
|
||||
|
||||
Reference in New Issue
Block a user