public String doPost(WikiContext context)
{
HttpServletRequest request = context.getHttpRequest();
WikiSession session = context.getWikiSession();
UserManager mgr = context.getEngine().getUserManager();
String loginid = request.getParameter("loginid");
String loginname = request.getParameter("loginname");
String fullname = request.getParameter("fullname");
String password = request.getParameter("password");
String password2 = request.getParameter("password2");
String email = request.getParameter("email");
if( request.getParameter("action").equalsIgnoreCase("remove") )
{
try
{
mgr.getUserDatabase().deleteByLoginName(loginid);
session.addMessage("User profile "+loginid+" ("+fullname+") has been deleted");
}
catch (NoSuchPrincipalException e)
{
session.addMessage("User profile has already been removed");
}
catch (WikiSecurityException e)
{
session.addMessage("Security problem: "+e);
}
return "";
}
if( password != null && password.length() > 0 && !password.equals(password2) )
{
session.addMessage("Passwords do not match!");
return "";
}
UserProfile p;
if( loginid.equals("--New--") )
{
// Create new user
p = mgr.getUserDatabase().newProfile();
p.setCreated( new Date() );
}
else
{
try
{
p = mgr.getUserDatabase().findByLoginName( loginid );
}
catch (NoSuchPrincipalException e)
{
session.addMessage("I could not find user profile "+loginid);
return "";
}
}
p.setEmail(email);
p.setFullname(fullname);
if( password != null && password.length() > 0 ) p.setPassword(password);
p.setLoginName(loginname);
try
{
mgr.getUserDatabase().save( p );
}
catch( WikiSecurityException e )
{
session.addMessage("Unable to save "+e.getMessage());
}