📄 createtag.java
字号:
emailVisible = req.getParameter("emailVisible");
// Harvest the input parameters for any required extended properties
for( Iterator it=required.keySet().iterator(); it.hasNext(); ) {
prop = (String)it.next();
if( (tmp = req.getParameter(prop)) != null && tmp.length() > 0 ) {
required.put(prop,tmp);
} else {
required.put(prop,"");
extended_required = false;
}
}
// Harvest the input parameters for any optional extended properties
for( Iterator it=properties.keySet().iterator(); it.hasNext(); ) {
prop = (String)it.next();
if( (tmp = req.getParameter(prop)) != null ) {
properties.put(prop,tmp);
}
}
// Validate required fields, error string comes from yazd.tag.properties
if( email == null || email.length() == 0 || !extended_required ||
username == null || username.length() == 0 ||
((password == null || password.length() == 0) && !generate_password) ) {
jr.addError(TagPropertyManager.getTagProperty("yazd.tag.create.required"));
return SKIP_BODY;
}
// Validate password confirmation if confirm is true.
// Error string comes from yazd.tag.properties
if( confirm_password && (confirm == null || !password.equals(confirm)) ) {
password = null;
confirm = null;
jr.addError(TagPropertyManager.getTagProperty("yazd.tag.create.confirm_password"));
return SKIP_BODY;
}
// Generate a password for user if requested
if( generate_password ) {
password = jr.GeneratePassword();
properties.put("password",password);
}
// Try to create the new user account
ForumFactory ff = jr.getForumFactory();
ProfileManager pm = jr.getProfileManager();
try {
user = pm.createUser( username, password, email );
} catch( UserAlreadyExistsException e ) {
// userid is already in use, user has to try again
jr.addError(TagPropertyManager.getTagProperty("yazd.tag.create.userexists"));
username = null;
return SKIP_BODY;
}
// new user account created, save user data
try {
// Save standard user data
if( name != null && name.length() > 0 ) {
user.setName( name );
}
if( nameVisible != null && nameVisible.length() > 0) {
user.setNameVisible( true );
} else {
user.setNameVisible( false );
}
if( emailVisible != null && emailVisible.length() > 0 ) {
user.setEmailVisible( true );
} else {
user.setEmailVisible( false );
}
// Save any extended user properties
// thread_depth, message_depth, and items_per_page are special
// extended properties used for display preferences
for( Iterator it=properties.keySet().iterator(); it.hasNext(); ) {
tmp = (String)it.next();
user.setProperty( tmp, (String)properties.get(tmp));
if( tmp.equals(YazdState.MESSAGE_DEPTH) )
js.setMessageDepth(Integer.valueOf((String)properties.get(tmp)).intValue());
if( tmp.equals(YazdState.THREAD_DEPTH) )
js.setThreadDepth(Integer.valueOf((String)properties.get(tmp)).intValue());
if( tmp.equals(YazdState.ITEMS_PER_PAGE) )
js.setItemsPerPage(Integer.valueOf((String)properties.get(tmp)).intValue());
}
// Save any required extended user properties
// thread_depth, message_depth, and items_per_page are special
// extended properties used for display preferences
for( Iterator it=required.keySet().iterator(); it.hasNext(); ) {
tmp = (String)it.next();
user.setProperty( tmp, (String)required.get(tmp));
if( tmp.equals(YazdState.MESSAGE_DEPTH) )
js.setMessageDepth(Integer.valueOf((String)required.get(tmp)).intValue());
if( tmp.equals(YazdState.THREAD_DEPTH) )
js.setThreadDepth(Integer.valueOf((String)required.get(tmp)).intValue());
if( tmp.equals(YazdState.ITEMS_PER_PAGE) )
js.setItemsPerPage(Integer.valueOf((String)required.get(tmp)).intValue());
}
// Finally, get authorization for new user account
auth = AuthorizationFactory.getAuthorization( username, password );
} catch(UnauthorizedException e) {
throw new JspException("Create tag not authorized to set user values.");
}
// Account is now created
created = true;
// See if user should be automatically logged in
if( auto_login ) {
// User is now authorized as if they had logged in
js.setAuthorization(auth);
js.setLoggedIn(true);
}
// All done, the body of the create tag can now redirect the
// user some where else if needed.
return EVAL_BODY_INCLUDE;
}
/**
* Method called at end of create Tag
*
* @return <b>SKIP_PAGE</b> if new user account created, <b>EVAL_PAGE</b> if user account has not been created yet.
*/
public final int doEndTag() throws JspException
{
if( created )
return SKIP_PAGE;
return EVAL_PAGE;
}
/**
* Set a flag indicating that password changes should be confirmed
* (Optional attribute).
*/
public final void setConfirm(String name)
{
if( name.equals("true") )
confirm_password = true;
}
/**
* Set a flag indicating that password will be generated for user
* (Optional attribute).
*/
public final void setPassword(String name)
{
if( name.equals("true") )
generate_password = true;
}
/**
* Set a flag indicating that user should be logged in once account
* is created
* (Optional attribute).
*/
public final void setLogin(String name)
{
if( name.equals("true") )
auto_login = true;
}
// Get methods for standard user data which is made
// availabe to JSP author via a script variable
/**
* User Email address property which can be obtained by the JSP page
* using <jsp:getProperty name=<i>"id"</i> property="email"/>
*
* @return String - user email address
*/
public final String getEmail()
{
if( email == null )
return "";
return email;
}
/**
* User Username (userid) property which can be obtained by the JSP page
* using <jsp:getProperty name=<i>"id"</i> property="username"/>
*
* @return String - user username (forum userid)
*/
public final String getUsername()
{
if( username == null )
return "";
return username;
}
/**
* Password entered in previous HTML form submisson which can be
* obtained by the JSP page using
* <jsp:getProperty name=<i>"id"</i> property="password"/>
*
* @return String - password the user entered in the HTML form submitted
*/
public final String getPassword()
{
if( password == null )
return "";
return password;
}
/**
* Confirm Password entered in previous HTML form submisson which can be
* obtained by the JSP page using
* <jsp:getProperty name=<i>"id"</i> property="confirm"/>
*
* @return String - confirm password the user entered in the HTML form submitted
*/
public final String getConfirm()
{
if( confirm == null )
return "";
return confirm;
}
/**
* User Name (real name) property which can be obtained by the JSP page
* using <jsp:getProperty name=<i>"id"</i> property="name"/>
*
* @return String - user name (real name)
*/
public final String getName()
{
if( name == null )
return "";
return name;
}
/**
* User NameVisible (real name) property which can be obtained by the
* JSP Page using <jsp:getProperty name=<i>"id"</i> property="nameVisible"/>
*
* @return checkbox value if user real name should be visible.
*/
public final String getNameVisible()
{
if( nameVisible != null )
return "checked";
return "";
}
/**
* User EmailVisible (email address) property which can be obtained by the
* JSP Page using <jsp:getProperty name=<i>"id"</i> property="emailVisible"/>
*
* @return checkbox value if user email address should be visible.
*/
public final String getEmailVisible()
{
if( emailVisible != null )
return "checked";
return "";
}
/**
* Method used by the getYazdProperty tag to get an extended User
* property from the create tag script variable.
*
* @return String - value of the property
*/
public final String getProperty(String name)
{
String tmp = (String)properties.get(name);
if( tmp != null )
return tmp;
tmp = (String)required.get(name);
if( tmp != null )
return tmp;
return "";
}
/**
* Method used by the setYazdProperty tag to set an extended User
* property from the create tag script variable.
*/
public final void setProperty(String name, String value)
{
user.setProperty(name,value);
if( properties.containsKey(name) )
properties.put(name,value);
else if( required.containsKey(name) )
properties.put(name,value);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -