Loading src/blogi.cpp +40 −29 Original line number Diff line number Diff line Loading @@ -895,7 +895,36 @@ void blogi::Blogi::loginPage(libhttppp::HttpRequest &curreq,const int tid,const libhtmlpp::HtmlString out; if (username.empty() || password.empty()) { // Check for automatic login credentials in the configuration std::string username = ctx.config->getUsername(); std::string password = ctx.config->getPassword(); if (!username.empty() && !password.empty()) { // Attempt automatic login uuid::uuid sessid; if (PlgArgs->auth->login(tid, username.c_str(), password.c_str(), sessid, loginSessionId, ctx.domainName)) { // Login successful, redirect to start page libhttppp::HttpResponse curres; libhttppp::HttpCookie authid; libhttppp::HttpCookie scook; if (createdLoginSession) { scook.setcookie(curres, "sessionid", loginSessionId, "", cookieDomain(curreq).c_str(), (1000*60*60*1), "/", false, "1", "Lax", false); } authid.setcookie(curres,"authid",sessid.c_str(),"",cookieDomain(curreq).c_str(),(1000*60*60*1),"/",false,"1","Lax",false); curres.setState(HTTP303); curres.setHeaderData("location")->push_back(ctx.startPage); curres.setContentType("text/html"); sendCompressed(curreq,curres, "", 0); return; } else { // Automatic login failed, proceed to show form std::cerr << "Automatic login failed. Showing login form." << std::endl; } } // If no credentials or automatic login failed, show the form std::string _lang = blogi::getLang(*PlgArgs->database[tid]); libhtmlpp::HtmlString condat; condat << "<div id=\"content\">" Loading @@ -910,24 +939,6 @@ void blogi::Blogi::loginPage(libhttppp::HttpRequest &curreq,const int tid,const if(index.getElementbyID("main")) index.getElementbyID("main")->insertChild(condat.parse()); for(const blogi::Plugin::PluginData *curplg=BlogiPlg->getFirstPlugin(); curplg; curplg=curplg->getNextPlg()){ if(curreq.isMobile()) curplg->getInstace()->Rendering(tid,curreq,&index,RenderingType::Mobile,sessionid); else curplg->getInstace()->Rendering(tid,curreq,&index,RenderingType::Desktop,sessionid); } PlgArgs->theme->printSite(tid,out,&index,curreq.getRequestURL(),false); libhttppp::HttpResponse curres; // Clear stale auth cookie when showing login form libhttppp::HttpCookie cookclr; cookclr.setcookie(curres,"authid","","",cookieDomain(curreq).c_str(),0,"/"); curres.setState(HTTP200); curres.setContentType("text/html"); sendCompressed(curreq,curres,out.c_str(),out.length()); return; } std::string loginSessionId = sessionid; bool createdLoginSession = false; if (loginSessionId.empty()) { Loading Loading
src/blogi.cpp +40 −29 Original line number Diff line number Diff line Loading @@ -895,7 +895,36 @@ void blogi::Blogi::loginPage(libhttppp::HttpRequest &curreq,const int tid,const libhtmlpp::HtmlString out; if (username.empty() || password.empty()) { // Check for automatic login credentials in the configuration std::string username = ctx.config->getUsername(); std::string password = ctx.config->getPassword(); if (!username.empty() && !password.empty()) { // Attempt automatic login uuid::uuid sessid; if (PlgArgs->auth->login(tid, username.c_str(), password.c_str(), sessid, loginSessionId, ctx.domainName)) { // Login successful, redirect to start page libhttppp::HttpResponse curres; libhttppp::HttpCookie authid; libhttppp::HttpCookie scook; if (createdLoginSession) { scook.setcookie(curres, "sessionid", loginSessionId, "", cookieDomain(curreq).c_str(), (1000*60*60*1), "/", false, "1", "Lax", false); } authid.setcookie(curres,"authid",sessid.c_str(),"",cookieDomain(curreq).c_str(),(1000*60*60*1),"/",false,"1","Lax",false); curres.setState(HTTP303); curres.setHeaderData("location")->push_back(ctx.startPage); curres.setContentType("text/html"); sendCompressed(curreq,curres, "", 0); return; } else { // Automatic login failed, proceed to show form std::cerr << "Automatic login failed. Showing login form." << std::endl; } } // If no credentials or automatic login failed, show the form std::string _lang = blogi::getLang(*PlgArgs->database[tid]); libhtmlpp::HtmlString condat; condat << "<div id=\"content\">" Loading @@ -910,24 +939,6 @@ void blogi::Blogi::loginPage(libhttppp::HttpRequest &curreq,const int tid,const if(index.getElementbyID("main")) index.getElementbyID("main")->insertChild(condat.parse()); for(const blogi::Plugin::PluginData *curplg=BlogiPlg->getFirstPlugin(); curplg; curplg=curplg->getNextPlg()){ if(curreq.isMobile()) curplg->getInstace()->Rendering(tid,curreq,&index,RenderingType::Mobile,sessionid); else curplg->getInstace()->Rendering(tid,curreq,&index,RenderingType::Desktop,sessionid); } PlgArgs->theme->printSite(tid,out,&index,curreq.getRequestURL(),false); libhttppp::HttpResponse curres; // Clear stale auth cookie when showing login form libhttppp::HttpCookie cookclr; cookclr.setcookie(curres,"authid","","",cookieDomain(curreq).c_str(),0,"/"); curres.setState(HTTP200); curres.setContentType("text/html"); sendCompressed(curreq,curres,out.c_str(),out.length()); return; } std::string loginSessionId = sessionid; bool createdLoginSession = false; if (loginSessionId.empty()) { Loading