📄 accounttag.java
字号:
/**
* Copyright (C) 2001 Yasna.com. All rights reserved.
*
* ===================================================================
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by
* Yasna.com (http://www.yasna.com)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Yazd" and "Yasna.com" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please
* contact yazd@yasna.com.
*
* 5. Products derived from this software may not be called "Yazd",
* nor may "Yazd" appear in their name, without prior written
* permission of Yasna.com.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL YASNA.COM OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of Yasna.com. For more information
* on Yasna.com, please see <http://www.yasna.com>.
*/
/**
* Copyright (C) 2000 CoolServlets.com. All rights reserved.
*
* ===================================================================
* The Apache Software License, Version 1.1
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by
* CoolServlets.com (http://www.coolservlets.com)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Jive" and "CoolServlets.com" must not be used to
* endorse or promote products derived from this software without
* prior written permission. For written permission, please
* contact webmaster@coolservlets.com.
*
* 5. Products derived from this software may not be called "Jive",
* nor may "Jive" appear in their name, without prior written
* permission of CoolServlets.com.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL COOLSERVLETS.COM OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of CoolServlets.com. For more information
* on CoolServlets.com, please see <http://www.coolservlets.com>.
*/
package com.Yasna.forum.tags;
import java.util.*;
import javax.servlet.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import javax.servlet.http.*;
import com.Yasna.forum.*;
import com.Yasna.forum.tags.*;
/**
* JSP Tag <b>account</b>, used to modify a Yazd User account.
* <p>
* Requires that attribute <b>id</b> be set to the name of a
* script variable for later use in JSP to retrieve User data
* using <jsp:getProperty/>.
* <p>
* If optional tag attribute <b>confirm</b>="true" and the
* user enters a password, they must also enter the password
* a second time to confirm their password change.
* <p>
* Requires that the User be logged in to modify their account.
* <p>
* Can be nested inside the <b>admin</b> tag so that a user
* can be modified using the permissions of the admin user.
* <p>
* The authorize tag must be used in the JSP prior to using this tag
* so that YazdState and YazdRequest are initialized, and to verify
* that a real user is logged in.
* <p>
* Uses the the following HTTP input parameters
* <p><ul>
* <li><b>modify</b> - name of submit button to use with HTML input form
* <li><b>email</b> - users email address
* <li><b>password</b> - new password
* <li><b>confirm</b> - confirm password if changing to new password
* <li><b>name</b> - users real name
* <li><b>nameVisible</b> - check box returning "checked" if real name should be visible
* <li><b>emailVisible</b> - check box returning "checked" if email address should be visible
* </ul>
* <p>
* Plus any additional parameters as specified in yazd.user.properties file.
* If a property in yazd.user.properties is named "password", that User
* property is only changed if a user's password gets changed and they
* are not a System, Forum, Group, or User Admin.
* <p>
* Sets one or more user errors if account modifications fail.
* <p>
* JSP Tag Lib Descriptor
* <p><pre>
* <name>account</name>
* <tagclass>com.Yasna.forum.tags.AccountTag</tagclass>
* <bodycontent>JSP</bodycontent>
* <info>Includes body of tag if account modifications are successful.</info>
* <attribute>
* <name>id</name>
* <required>true</required>
* <rtexprvalue>false</rtexprvalue>
* </attribute>
* <attribute>
* <name>confirm</name>
* <required>false</required>
* <rtexprvalue>false</rtexprvalue>
* </attribute>
* </pre>
*
* @see AdminUserTag
* @see TagPropertyManager
* @see YazdProperty
* @see GetYazdPropertyTag
* @see SetYazdPropertyTag
* @see YazdState
* @see YazdRequest
* @see ErrorTag
* @see ErrorLoopTag
*
* @author Glenn Nielsen
*/
public class AccountTag extends TagSupport implements YazdProperty
{
private YazdState js = null;
private YazdRequest jr = null;
private User user = null;
// Static user data, can't change username after account created.
private String username = null;
// Required input parameters
private String email = null;
// Optional input parameters
private String nameVisible = null;
private String emailVisible = null;
private String password = null;
private String confirm = null;
private String name = null;
// Extended properties of User as configured in yazd.user.properties
private Map properties = new HashMap();
// Required extended properties of User as configured in yazd.user.properties
private Map required = new HashMap();
// Flag that we must confirm password if user is setting new password
// Set by the account tag confirm attribute
private boolean confirm_password = false;
/**
* Initializes data for account tag User data and modifies User account
* if this is an HTML form submission.
*
* @throws JspException on system level error
*
* @return EVAL_BODY_INCLUDE
*/
public final int doStartTag() throws JspException
{
boolean extended_required = true;
// Get the user state information
js = (YazdState)pageContext.getAttribute("yazdUserState",
PageContext.SESSION_SCOPE);
if( js == null ) {
throw new JspException("Yazd account tag could not get yazd state.");
}
// Get the user request information
jr = (YazdRequest)pageContext.getAttribute("yazdUserRequest",
PageContext.REQUEST_SCOPE);
if( jr == null ) {
throw new JspException("Yazd account tag could not get yazd request.");
}
// If we are nested inside an admin tag, get user to administer
try {
AdminUserTag at = (AdminUserTag)this.findAncestorWithClass(this,
Class.forName("com.Yasna.forum.tags.AdminUserTag"));
user = at.getUser();
} catch(Exception e) {
}
if( user == null ) {
// Get the User data
ProfileManager pm = jr.getProfileManager();
try {
user = pm.getUser(js.getAuthorization().getUserID());
} catch( UserNotFoundException ex ) {
throw new JspException("Yazd account tag could not find user.");
}
}
// Make sure user isn't anonymous
if( user.isAnonymous() ) {
throw new JspException("Yazd account tag can not be used by an anonymous user.");
}
// Get user board name
if( user.getUsername() == null )
throw new JspException("Yazd account tag, user with id " +
user.getID() + " has no name.");
username = user.getUsername();
// Save the script variable so JSP author can access user data
pageContext.setAttribute(id,this,PageContext.PAGE_SCOPE);
// Get the User data and any extended properties
Enumeration enum = TagPropertyManager.getUserPropertyNames();
String tmp;
String prop;
ServletRequest req = pageContext.getRequest();
if( user.getEmail() != null )
email = user.getEmail();
if( user.getName() != null )
name = user.getName();
if( user.isEmailVisible() )
emailVisible = "checked";
if( user.isNameVisible() )
nameVisible = "checked";
// Get values of any extended user properties defined
// in yazd.user.properties
while( enum.hasMoreElements() ) {
prop = (String)enum.nextElement();
if( prop.startsWith( "required." ) ) {
prop = prop.substring(9);
if( (tmp = user.getProperty(prop)) != null ) {
required.put(prop,tmp);
} else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -