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.h"
|
||||||
|
#include "crow/middlewares/cookie_parser.h"
|
||||||
#include "database.cpp"
|
#include "database.cpp"
|
||||||
#include "utilities.cpp"
|
#include "utilities.cpp"
|
||||||
#include <pqxx/pqxx>
|
#include <pqxx/pqxx>
|
||||||
@ -19,21 +20,10 @@ int main(int argc, char *argv[]) {
|
|||||||
return 1;
|
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;
|
string databaseURI = configuration.databaseConnectionString;
|
||||||
|
|
||||||
|
// Create app with Middleware
|
||||||
|
crow::App<crow::CookieParser> app;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Freelancer Profile listing for customers
|
* Freelancer Profile listing for customers
|
||||||
@ -118,7 +108,6 @@ int main(int argc, char *argv[]) {
|
|||||||
return page.render(ctx);
|
return page.render(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Page representing a freelancers Template
|
* Page representing a freelancers Template
|
||||||
*/
|
*/
|
||||||
@ -250,6 +239,51 @@ int main(int argc, char *argv[]) {
|
|||||||
return page.render(ctx);
|
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();*/
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
24
templates/freelancer_login.html
Normal file
24
templates/freelancer_login.html
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
{{> templateIncludes/style.css.html}}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>Freelancer Login</h2>
|
||||||
|
<div>
|
||||||
|
{{^cookieloggedin}}
|
||||||
|
<form action="/freelancer/login" method="get">
|
||||||
|
<button type="submit" name="userLogIn" value="{{id}}" class="button">Freelancer Login</button>
|
||||||
|
</form>
|
||||||
|
{{/cookieloggedin}}
|
||||||
|
{{#cookieloggedin}}
|
||||||
|
<form action="/freelancer/profile" method="get">
|
||||||
|
<button type="submit" class="button">Already Logged in proceed to Profile</button>
|
||||||
|
</form>
|
||||||
|
{{/cookieloggedin}}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user