📄 accounttag.java
字号:
required.put(prop,"");
}
} else {
if( (tmp = user.getProperty(prop)) != null ) {
properties.put(prop,tmp);
} else {
properties.put(prop,"");
}
}
}
if( (tmp = req.getParameter("modify")) == null ) {
// First time account info display, so continue on with rest of page
return EVAL_BODY_INCLUDE;
}
// User has submitted a page requesting changes to their user data
// Harvest the standard user data input parameters from page
email = req.getParameter("email");
password = req.getParameter("password");
confirm = req.getParameter("confirm");
name = req.getParameter("name");
nameVisible = req.getParameter("nameVisible");
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 email address, error string comes from yazd.tag.properties
if( email == null || email.length() == 0 || !extended_required ) {
jr.addError(TagPropertyManager.getTagProperty("yazd.tag.account.required"));
return EVAL_BODY_INCLUDE;
}
// Validate password confirmation if a password change is being made,
// and confirm is true. Error string comes from yazd.tag.properties
if( password != null && password.length() > 0 ) {
if( confirm_password && (confirm == null || !password.equals(confirm)) ) {
password = null;
confirm = null;
jr.addError(TagPropertyManager.getTagProperty("yazd.tag.account.confirm_password"));
return EVAL_BODY_INCLUDE;
}
}
try {
// Save standard user data if changed
if( password != null && password.length() > 0 ) {
user.setPassword(password);
if( properties.get("password") != null ) {
ForumPermissions perms =
jr.getForumFactory().getPermissions(js.getAuthorization());
if( !perms.get(ForumPermissions.SYSTEM_ADMIN) &&
!perms.get(ForumPermissions.FORUM_ADMIN) &&
!perms.get(ForumPermissions.GROUP_ADMIN) &&
!perms.get(ForumPermissions.USER_ADMIN) ) {
user.setProperty( "password", (String)properties.get("password"));
}
}
}
if( name != null && name.length() > 0 ) {
user.setName( name );
}
if( nameVisible != null && nameVisible.length() > 0) {
user.setNameVisible( true );
} else {
user.setNameVisible( false );
}
if( email != null && email.length() > 0 ) {
user.setEmail( email );
}
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();
if( !tmp.equals("password") )
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 extended required 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();
if( !tmp.equals("password") )
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());
}
} catch(UnauthorizedException e) {
throw new JspException("Yazd account tag, user with id " +
user.getID() + " is not authorized to set user values.");
}
// All done, the body of the account tag can now redirect the
// user some where else if needed.
return EVAL_BODY_INCLUDE;
}
/**
* 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;
}
// 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 <b>checked</b> 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 <b>checked</b> 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 account 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 account 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);
}
/**
* Method used to determine if user is a member of a yazd Group.
*
* @return true if a member, false if not a member
*/
public final boolean isMember(String name) throws JspException
{
// Get the group data
ProfileManager pm = jr.getProfileManager();
try {
Group group = pm.getGroup(name);
return group.isMember(user);
} catch( GroupNotFoundException ex ) {
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -