summaryrefslogtreecommitdiff
path: root/modules/extra/webcpanel/pages/index.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-10-07 22:39:58 -0400
committerAdam <Adam@anope.org>2012-10-07 22:39:58 -0400
commitb8b63ff115f0daddf479b0da507a2f731255a06d (patch)
treed6b82bf0dfc39fdfe6a6a23ba318bb0c2906d6c1 /modules/extra/webcpanel/pages/index.cpp
parent0a111c19764ed14ab5f724c78d9dd8c08a3c124f (diff)
Remove the asynchronous identifing hack and replace it with something better. Fixes m_*_authentication only being able to properly work when people identify normally using nickserv/identify
Diffstat (limited to 'modules/extra/webcpanel/pages/index.cpp')
-rw-r--r--modules/extra/webcpanel/pages/index.cpp118
1 files changed, 72 insertions, 46 deletions
diff --git a/modules/extra/webcpanel/pages/index.cpp b/modules/extra/webcpanel/pages/index.cpp
index e0db8f8de..73f7224f4 100644
--- a/modules/extra/webcpanel/pages/index.cpp
+++ b/modules/extra/webcpanel/pages/index.cpp
@@ -7,67 +7,93 @@
#include "../webcpanel.h"
-void WebCPanel::Index::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply)
+class WebpanelRequest : public IdentifyRequest
{
+ HTTPReply reply;
+ HTTPMessage message;
+ dynamic_reference<HTTPProvider> server;
+ Anope::string page_name;
+ dynamic_reference<HTTPClient> client;
TemplateFileServer::Replacements replacements;
- const Anope::string &user = message.post_data["username"], &pass = message.post_data["password"];
- replacements["TITLE"] = page_title;
+ public:
+ WebpanelRequest(HTTPReply &r, HTTPMessage &m, HTTPProvider *s, const Anope::string &p_n, HTTPClient *c, TemplateFileServer::Replacements &re, const Anope::string &user, const Anope::string &pass) : IdentifyRequest(user, pass), reply(r), message(m), server(s), page_name(p_n), client(c), replacements(re) { }
- if (!user.empty() && !pass.empty())
+ void OnSuccess() anope_override
{
- // Rate limit check.
-
- NickAlias *na = findnick(user);
-
- EventReturn MOD_RESULT = EVENT_CONTINUE;
-
- if (na)
+ if (!client)
+ return;
+ NickAlias *na = findnick(this->GetAccount());
+ if (!na)
{
- FOREACH_RESULT(I_OnCheckAuthentication, OnCheckAuthentication(NULL, NULL, std::vector<Anope::string>(), na->nc->display, pass));
+ this->OnFail();
+ return;
}
- if (MOD_RESULT == EVENT_ALLOW)
+ Anope::string id;
+ for (int i = 0; i < 64; ++i)
{
- Anope::string id;
- for (int i = 0; i < 64; ++i)
- {
- char c;
- do
- c = 48 + (rand() % 75);
- while (!isalnum(c));
- id += c;
- }
-
- na->Extend("webcpanel_id", new ExtensibleItemClass<Anope::string>(id));
- na->Extend("webcpanel_ip", new ExtensibleItemClass<Anope::string>(client->GetIP()));
-
- {
- HTTPReply::cookie c;
- c.push_back(std::make_pair("account", na->nick));
- c.push_back(std::make_pair("Path", "/"));
- reply.cookies.push_back(c);
- }
-
- {
- HTTPReply::cookie c;
- c.push_back(std::make_pair("id", id));
- c.push_back(std::make_pair("Path", "/"));
- reply.cookies.push_back(c);
- }
-
- reply.error = HTTP_FOUND;
- reply.headers["Location"] = "http://" + message.headers["Host"] + "/nickserv/info";
- return;
+ char c;
+ do
+ c = 48 + (rand() % 75);
+ while (!isalnum(c));
+ id += c;
}
- else
+
+ na->Extend("webcpanel_id", new ExtensibleItemClass<Anope::string>(id));
+ na->Extend("webcpanel_ip", new ExtensibleItemClass<Anope::string>(client->GetIP()));
+
{
- replacements["INVALID_LOGIN"] = "Invalid username or password";
+ HTTPReply::cookie c;
+ c.push_back(std::make_pair("account", na->nick));
+ c.push_back(std::make_pair("Path", "/"));
+ reply.cookies.push_back(c);
+ }
+
+ {
+ HTTPReply::cookie c;
+ c.push_back(std::make_pair("id", id));
+ c.push_back(std::make_pair("Path", "/"));
+ reply.cookies.push_back(c);
}
+
+ reply.error = HTTP_FOUND;
+ reply.headers["Location"] = "http://" + message.headers["Host"] + "/nickserv/info";
+
+ client->SendReply(&reply);
}
- TemplateFileServer page("login.html");
+ void OnFail() anope_override
+ {
+ if (!client)
+ return;
+ replacements["INVALID_LOGIN"] = "Invalid username or password";
+ TemplateFileServer page("login.html");
+ page.Serve(server, page_name, client, message, reply, replacements);
+ client->SendReply(&reply);
+ }
+};
+
+bool WebCPanel::Index::OnRequest(HTTPProvider *server, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply)
+{
+ TemplateFileServer::Replacements replacements;
+ const Anope::string &user = message.post_data["username"], &pass = message.post_data["password"];
+
+ replacements["TITLE"] = page_title;
+
+ if (!user.empty() && !pass.empty())
+ {
+ // Rate limit check.
+
+ WebpanelRequest *req = new WebpanelRequest(reply, message, server, page_name, client, replacements, user, pass);
+ FOREACH_MOD(I_OnCheckAuthentication, OnCheckAuthentication(NULL, req));
+ req->Dispatch();
+ return false;
+ }
+
+ TemplateFileServer page("login.html");
page.Serve(server, page_name, client, message, reply, replacements);
+ return true;
}