Skip to content

Instantly share code, notes, and snippets.

@xor-freenet
Created August 24, 2013 17:27
Show Gist options
  • Save xor-freenet/6329331 to your computer and use it in GitHub Desktop.
Save xor-freenet/6329331 to your computer and use it in GitHub Desktop.
public class LogInWebInterfaceToadlet extends WebInterfaceToadlet {
protected LogInWebInterfaceToadlet(HighLevelSimpleClient client, WebInterface wi, NodeClientCore core, String pageTitle) {
super(client, wi, core, pageTitle);
}
/** Log an user in from a POST and redirect to the BoardsPage */
@Override
public void handleMethodPOST(URI uri, HTTPRequest request, ToadletContext ctx) throws ToadletContextClosedException, IOException, RedirectException {
if(!ctx.checkFullAccess(this))
return;
String pass = request.getPartAsString("formPassword", 32);
if ((pass.length() == 0) || !pass.equals(core.formPassword)) {
writeHTMLReply(ctx, 403, "Forbidden", "Invalid form password.");
return;
}
try {
OwnIdentity ownIdentity = mFreetalk.getIdentityManager().getOwnIdentity(request.getPartAsString("OwnIdentityID", 64));
mSessionManager.createSession(ownIdentity.getID(), ctx);
} catch(NoSuchIdentityException e) {
throw new RedirectException(logIn);
}
writeTemporaryRedirect(ctx, "Login successful, redirecting to home page", Freetalk.PLUGIN_URI + "/");
}
@Override
WebPage makeWebPage(HTTPRequest req, ToadletContext context) throws RedirectException {
if(!mFreetalk.wotConnected())
return new WoTIsMissingPage(webInterface, req, mFreetalk.wotOutdated(), l10n());
return new LogInPage(webInterface , req, l10n());
}
@Override
public boolean isEnabled(ToadletContext ctx) {
// Do not call super.isEnabled(): The LogInWebInterfaceToadlet should be enabled when the WoT-plugin is not present.
return !mSessionManager.sessionExists(ctx);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment