migrate the switchuser and register
This commit is contained in:
@ -145,9 +145,12 @@ public class BlogManager {
|
||||
public BlogInfo createInfo(SigningPublicKey pub, SigningPrivateKey priv, String name, SigningPublicKey posters[],
|
||||
String description, String contactURL, String archives[], int edition) {
|
||||
Properties opts = new Properties();
|
||||
if (name == null) name = "";
|
||||
opts.setProperty("Name", name);
|
||||
if (description == null) description = "";
|
||||
opts.setProperty("Description", description);
|
||||
opts.setProperty("Edition", Integer.toString(edition));
|
||||
if (contactURL == null) contactURL = "";
|
||||
opts.setProperty("ContactURL", contactURL);
|
||||
for (int i = 0; archives != null && i < archives.length; i++)
|
||||
opts.setProperty("Archive." + i, archives[i]);
|
||||
@ -609,6 +612,13 @@ public class BlogManager {
|
||||
if (!user.getAuthenticated()) return;
|
||||
storeUser(user);
|
||||
}
|
||||
public User register(String login, String password, String registrationPassword, String blogName, String blogDescription, String contactURL) {
|
||||
User user = new User(_context);
|
||||
if (User.LOGIN_OK.equals(register(user, login, password, registrationPassword, blogName, blogDescription, contactURL)))
|
||||
return user;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
public String register(User user, String login, String password, String registrationPassword, String blogName, String blogDescription, String contactURL) {
|
||||
System.err.println("Register [" + login + "] pass [" + password + "] name [" + blogName + "] descr [" + blogDescription + "] contact [" + contactURL + "] regPass [" + registrationPassword + "]");
|
||||
String hashedRegistrationPassword = getRegistrationPasswordHash();
|
||||
|
@ -412,8 +412,11 @@ public class ThreadedHTMLRenderer extends HTMLRenderer {
|
||||
return buildProfileURL(blog);
|
||||
}
|
||||
public static String buildProfileURL(Hash blog) {
|
||||
return "profile.jsp?" + ThreadedHTMLRenderer.PARAM_AUTHOR + "=" +
|
||||
Base64.encode(blog.getData());
|
||||
if ( (blog != null) && (blog.getData() != null) )
|
||||
return "profile.jsp?" + ThreadedHTMLRenderer.PARAM_AUTHOR + "=" +
|
||||
Base64.encode(blog.getData());
|
||||
else
|
||||
return "profile.jsp";
|
||||
}
|
||||
protected String getEntryURL() { return getEntryURL(_user != null ? _user.getShowImages() : false); }
|
||||
protected String getEntryURL(boolean showImages) {
|
||||
|
@ -33,6 +33,11 @@ public abstract class BaseServlet extends HttpServlet {
|
||||
|
||||
if (req.getParameter("regenerateIndex") != null)
|
||||
forceNewIndex = true;
|
||||
|
||||
User oldUser = user;
|
||||
user = handleRegister(user, req);
|
||||
if (oldUser != user)
|
||||
forceNewIndex = true;
|
||||
|
||||
if (user == null) {
|
||||
if ("Login".equals(action)) {
|
||||
@ -199,6 +204,22 @@ public abstract class BaseServlet extends HttpServlet {
|
||||
boolean updated = BlogManager.instance().updateMetadata(user, user.getBlog(), opts);
|
||||
}
|
||||
|
||||
private User handleRegister(User user, HttpServletRequest req) {
|
||||
String l = req.getParameter("login");
|
||||
String p = req.getParameter("password");
|
||||
String name = req.getParameter("accountName");
|
||||
String desc = req.getParameter("description");
|
||||
String contactURL = req.getParameter("url");
|
||||
String regPass = req.getParameter("registrationPass");
|
||||
String action = req.getParameter("action");
|
||||
|
||||
if ( (action != null) && ("Register".equals(action)) && !empty(l) ) {
|
||||
return BlogManager.instance().register(l, p, regPass, name, desc, contactURL);
|
||||
} else {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
protected void render(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index) throws ServletException, IOException {
|
||||
Archive archive = BlogManager.instance().getArchive();
|
||||
int numThreads = 10;
|
||||
@ -248,7 +269,7 @@ public abstract class BaseServlet extends HttpServlet {
|
||||
}
|
||||
//out.write("</td><td class=\"topNav_admin\">\n");
|
||||
out.write("</span><span class=\"topNav_admin\">\n");
|
||||
if (user.getAuthenticated() && user.getAllowAccessRemote()) {
|
||||
if (BlogManager.instance().authorizeRemote(user)) {
|
||||
out.write("<a href=\"syndicate.jsp\" title=\"Syndicate data between other Syndie nodes\">Syndicate</a>\n");
|
||||
out.write("<a href=\"importfeed.jsp\" title=\"Import RSS/Atom data\">Import RSS/Atom</a>\n");
|
||||
out.write("<a href=\"admin.jsp\" title=\"Configure this Syndie node\">Admin</a>\n");
|
||||
@ -629,13 +650,12 @@ public abstract class BaseServlet extends HttpServlet {
|
||||
".topNav_user {\n" +
|
||||
" text-align: left;\n" +
|
||||
" float: left;\n" +
|
||||
" align: left;\n" +
|
||||
" display: inline;\n" +
|
||||
"}\n" +
|
||||
".topNav_admin {\n" +
|
||||
" text-align: right;\n" +
|
||||
" float: right;\n" +
|
||||
" align: right;\n" +
|
||||
" margin: 0 5px 0 0;\n" +
|
||||
" display: inline;\n" +
|
||||
"}\n" +
|
||||
".controlBar {\n" +
|
||||
|
48
apps/syndie/java/src/net/i2p/syndie/web/SwitchServlet.java
Normal file
48
apps/syndie/java/src/net/i2p/syndie/web/SwitchServlet.java
Normal file
@ -0,0 +1,48 @@
|
||||
package net.i2p.syndie.web;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.client.naming.*;
|
||||
import net.i2p.data.*;
|
||||
import net.i2p.syndie.*;
|
||||
import net.i2p.syndie.data.*;
|
||||
import net.i2p.syndie.sml.*;
|
||||
|
||||
/**
|
||||
* Login/register form
|
||||
*
|
||||
*/
|
||||
public class SwitchServlet extends BaseServlet {
|
||||
private final String FORM = "<form action=\"" + getControlTarget() + "\" method=\"POST\">\n" +
|
||||
"<tr><td colspan=\"3\"><b>Log in to an existing account</b></td></tr>\n" +
|
||||
"<tr><td colspan=\"3\">Login: <input type=\"text\" name=\"login\" /></td></tr>\n" +
|
||||
"<tr><td colspan=\"3\">Password: <input type=\"password\" name=\"password\" /></td></tr>\n" +
|
||||
"<tr><td colspan=\"3\"><input type=\"submit\" name=\"action\" value=\"Login\" />\n" +
|
||||
"<input type=\"submit\" name=\"action\" value=\"Cancel\" />\n" +
|
||||
"<input type=\"submit\" name=\"action\" value=\"Logout\" /></td></tr>\n" +
|
||||
"</form>\n" +
|
||||
"<tr><td colspan=\"3\"><hr /></td></tr>\n" +
|
||||
"<form action=\"" + ThreadedHTMLRenderer.buildProfileURL(null) + "\" method=\"POST\">\n" +
|
||||
"<tr><td colspan=\"3\"><b>Register a new account</b></td></tr>\n" +
|
||||
"<tr><td colspan=\"3\">Login: <input type=\"text\" name=\"login\" /> (only known locally)</td></tr>\n" +
|
||||
"<tr><td colspan=\"3\">Password: <input type=\"password\" name=\"password\" /></td></tr>\n" +
|
||||
"<tr><td colspan=\"3\">Public name: <input type=\"text\" name=\"accountName\" /></td></tr>\n" +
|
||||
"<tr><td colspan=\"3\">Description: <input type=\"text\" name=\"description\" /></td></tr>\n" +
|
||||
"<tr><td colspan=\"3\">Contact URL: <input type=\"text\" name=\"contactURL\" /></td></tr>\n" +
|
||||
"<tr><td colspan=\"3\">Registration password: <input type=\"password\" name=\"registrationPass\" />" +
|
||||
" (only necessary if the Syndie administrator requires it)</td></tr>\n" +
|
||||
"<tr><td colspan=\"3\"><input type=\"submit\" name=\"action\" value=\"Register\" /></td></tr>\n" +
|
||||
"</form>\n";
|
||||
|
||||
protected void renderServletDetails(User user, HttpServletRequest req, PrintWriter out, ThreadIndex index,
|
||||
int threadOffset, BlogURI visibleEntry, Archive archive) throws IOException {
|
||||
out.write(FORM);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="net.i2p.syndie.web.*" %><%
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Syndie</title>
|
||||
<link href="style.jsp" rel="stylesheet" type="text/css" >
|
||||
</head>
|
||||
<body>
|
||||
<form action="threads.jsp" method="GET">
|
||||
Syndie login: <input type="text" name="login" /><br />
|
||||
Password: <input type="password" name="password" /><br />
|
||||
<input type="submit" name="action" value="Login" />
|
||||
<input type="submit" name="action" value="Cancel" />
|
||||
<input type="submit" name="action" value="Logout" />
|
||||
</form>
|
||||
</body>
|
Reference in New Issue
Block a user