Temporary login page until proper login system is done
Basic cookie implementation
This commit is contained in:
62
src/main.cpp
62
src/main.cpp
@ -1,4 +1,5 @@
|
||||
#include "crow.h"
|
||||
#include "crow/middlewares/cookie_parser.h"
|
||||
#include "database.cpp"
|
||||
#include "utilities.cpp"
|
||||
#include <pqxx/pqxx>
|
||||
@ -19,21 +20,10 @@ int main(int argc, char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
crow::SimpleApp app;
|
||||
|
||||
// CROW_ROUTE(app, "/test.json")
|
||||
// ([](){
|
||||
// pqxx::connection db("postgresql://cavecommadmin:cavecomm@localhost:5432/cavecomm");
|
||||
// pqxx::work work(db);
|
||||
// pqxx::result result = work.exec("SELECT * from public.requests;");
|
||||
// work.commit();
|
||||
// return crow::json::wvalue x({{"message", rows[0][0].as<int>();}});
|
||||
// });
|
||||
|
||||
|
||||
|
||||
string databaseURI = configuration.databaseConnectionString;
|
||||
|
||||
// Create app with Middleware
|
||||
crow::App<crow::CookieParser> app;
|
||||
|
||||
/*
|
||||
* Freelancer Profile listing for customers
|
||||
@ -118,7 +108,6 @@ int main(int argc, char *argv[]) {
|
||||
return page.render(ctx);
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
* Page representing a freelancers Template
|
||||
*/
|
||||
@ -250,6 +239,51 @@ int main(int argc, char *argv[]) {
|
||||
return page.render(ctx);
|
||||
});
|
||||
|
||||
/*
|
||||
* redirect to /freelancer/login
|
||||
*/
|
||||
CROW_ROUTE(app, "/login")
|
||||
([](crow::response& res) {
|
||||
res.redirect("/freelancer/login");
|
||||
res.end();
|
||||
});
|
||||
|
||||
/*
|
||||
* redirect to /freelancer/logout
|
||||
*/
|
||||
CROW_ROUTE(app, "/logout")
|
||||
([](crow::response& res) {
|
||||
res.redirect("/freelancer/logout");
|
||||
res.end();
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
* Page for freelancer to log in
|
||||
*/
|
||||
CROW_ROUTE(app, "/freelancer/login")
|
||||
([&,databaseURI](const crow::request& getRequest ) {
|
||||
|
||||
auto& ctx = app.get_context<crow::CookieParser>(getRequest);
|
||||
// Read cookies with get_cookie
|
||||
auto value = ctx.get_cookie("cookieloggedin");
|
||||
if (value.compare("true") != 0) {
|
||||
value = "false";
|
||||
ctx.set_cookie("cookieloggedin", "true");
|
||||
}
|
||||
else
|
||||
{
|
||||
ctx.set_cookie("cookieloggedin", "false");
|
||||
}
|
||||
return "cookieloggedin: " + value;
|
||||
|
||||
|
||||
|
||||
/*string templateHTML = "customer_Freelancer_Template_Request.html";
|
||||
auto page = crow::mustache::load(templateHTML);
|
||||
|
||||
return page.render();*/
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user