練功房推薦書單

  • Google!Android 3手機應用程式設計入門(第四版)
  • 賈伯斯傳(軟皮精裝版)
  • 猛虎出閘制霸版:最新OCP Java SE 6 Programmer專業認證(附原始程式碼及範例檔)
  • SCWCD 5 猛虎出閘:Java Web 應用程式專業認證
Messages posted by: andowson
Forum Index » Profile for andowson » Messages posted by andowson
Message

語法:
[imvlog]http://www.im.tv/vlog/Personal/447302/4031618[/imvlog]

語法:
[xuite]http://vlog.xuite.net/vlog/guest/basic.php?media_id=d2g4eDFkLTkwOTQyNy5mbHY=[/xuite]
Solaris 10當然有CDE,可以參考鳥哥的這篇文章:
http://linux.vbird.org/solaris/0110install.php#login_cde
不錯的一篇文章,很多觀念應該可以適用於其他的系統上
http://www.sage.org/pubs/whitepapers/solarisadmin.html
有關Sun patch的部分,我找到一篇文章介紹Solaris™ Patch Manager,您可以參考看看。
http://www.samag.com/documents/s=7667/sam0213i/0213i.htm
照文件看來,直接裝下去,中間重新切partition就行了。
我找到了一篇文章供您參考
Step-by-Step Instructions to re-install Solaris
請參考一下這篇文章的內容,看能不能幫上忙:
http://www.andowson.com/posts/list/214.page
先確認以下兩點:
1.改完defaultrouter,有沒有重新開機?
2.執行netstat -rn的輸出為何?
我們可以透過JavaScript動態修改表單的action值來達成
<SCRIPT language="JavaScript">
function OnSubmitForm()
{
  if(document.pressed == 'Insert')
  {
   document.myform.action ="insert.html";
  }
  else
  if(document.pressed == 'Update')
  {
    document.myform.action ="update.html";
  }
  return true;
}
</SCRIPT>

<FORM name="myform" onSubmit="return OnSubmitForm();">
<INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Insert">
<INPUT TYPE="SUBMIT" name="Operation" onClick="document.pressed=this.value" VALUE="Update">
</FORM> 


參考資料
How to switch the 'action' field in an HTML form dynamically
If we do an SSO integration with user's username as his social security number or identification number from another webapp, and it is not good to show this information to public. We need to display the name of JForum's user as his real name instead of his username(login ID).

After finishing JForum SSO with user's first name and last name saved.
Here is a guideline for doing this:

1.We need to get user's real name as first_name and last_name from the jfoum_users table. Modify net.jforum.dao.generic.GenericUserDAO.java:
protected void fillUserFromResultSet(User u, ResultSet rs) throws SQLException
{
		...
		u.setFirstName(rs.getString("first_name"));
		u.setLastName(rs.getString("last_name"));
}

protected List processSelectAll(ResultSet rs) throws SQLException
{
			...
			u.setFirstName(rs.getString("first_name"));
			u.setLastName(rs.getString("last_name"));
			...
}

public User getLastUserInfo()
{
			...
			u.setUsername(rs.getString("username"));
			u.setId(rs.getInt("user_id"));
			u.setFirstName(rs.getString("first_name"));
			u.setLastName(rs.getString("last_name"));

			return u;
			...
}

2.Modify WEB-INF/config/database/generic/generic_queries.sql, add first_name, last_name to the original SQL statement. Here are some queries needing modification:
UserModel.selectAll = SELECT user_email, user_id, user_posts, user_regdate, username, deleted, user_karma, user_from, \
	user_website, user_viewemail, first_name, last_name FROM jforum_users ORDER BY user_id

UserModel.selectAllByLimit = SELECT user_email, user_id, user_posts, user_regdate, username, deleted, user_karma, user_from, user_website, user_viewemail, first_name, last_name \
	FROM jforum_users ORDER BY username LIMIT ?, ?

UserModel.selectAllByGroup = SELECT user_email, u.user_id, user_posts, user_regdate, username, deleted, user_karma, user_from, \
	user_website, user_viewemail, first_name, last_name \
	FROM jforum_users u, jforum_user_groups ug \
	WHERE u.user_id = ug.user_id \
	AND ug.group_id = ? \
	ORDER BY user_id LIMIT ?, ?

UserModel.findByName = SELECT user_id, username, user_email, deleted, first_name, last_name FROM jforum_users WHERE UPPER(username) LIKE UPPER(?) 

UserModel.update = UPDATE jforum_users SET user_aim = ?, \
	user_avatar = ?,\
	gender = ?, \
	themes_id = ?,\
	user_allow_pm = ?, \
	user_allowavatar = ?, \
	user_allowbbcode = ?, \
	user_allowhtml = ?, \
	user_allowsmilies = ?, \
	user_email = ?, \
	user_from = ?, \
	user_icq = ?, \
	user_interests = ?, \
	user_occ = ?, \
	user_sig = ?, \
	user_website = ?, \
	user_yim = ?, \
	user_msnm = ?, \
	user_password = ?, \
	user_viewemail = ?, \
	user_viewonline = ?, \
	user_notify = ?, \
	user_attachsig = ?, \
	username = ?, \
	user_lang = ?, \
	user_notify_pm = ?, \
	user_biography = ?, \
	user_lastvisit = ?, \
	user_notify_always = ?, \
	user_notify_text = ?, \
	rank_id = ?, \
	first_name = ?, \
	last_name = ? \
	WHERE user_id = ?

UserModel.lastUserRegistered=SELECT user_id, username, first_name, last_name FROM jforum_users ORDER BY user_regdate DESC LIMIT 1

ForumModel.lastPostInfo = SELECT post_time, p.topic_id, t.topic_replies, post_id, u.user_id, username, first_name, last_name \
	FROM jforum_posts p, jforum_users u, jforum_topics t , jforum_forums f \
	WHERE t.forum_id = f.forum_id \
	AND t.topic_id = p.topic_id \
	AND f.forum_last_post_id = t.topic_last_post_id \
	AND t.topic_last_post_id = p.post_id \
	AND p.forum_id = ? \
	AND p.user_id = u.user_id \
    AND p.need_moderate = 0

TopicModel.topicPosters = SELECT user_id, username, user_karma, user_avatar, user_allowavatar, user_regdate, user_posts, user_icq, \
	user_from, user_email, rank_id, user_sig, user_attachsig, user_viewemail, user_msnm, user_yim, user_website, user_sig, user_aim, first_name, last_name \
	FROM jforum_users \
	WHERE user_id IN (:ids:)

TopicModel.getUserInformation = SELECT user_id, username, first_name, last_name FROM jforum_users WHERE user_id IN (#ID#)

 
SearchModel.getPostsDataForLucene = SELECT p.post_id, p.forum_id, p.topic_id, p.user_id, u.username, p.enable_bbcode, p.enable_smilies, p.post_time, pt.post_subject, pt.post_text, t.topic_title, u.first_name, u.last_name \
	FROM jforum_posts p, jforum_posts_text pt, jforum_users u, jforum_topics t \
	WHERE p.post_id IN (:posts:) \
	AND p.post_id = pt.post_id  \
	AND p.topic_id = t.topic_id \
	AND p.user_id = u.user_Id

PrivateMessageModel.baseListing = SELECT pm.privmsgs_type, pm.privmsgs_id, pm.privmsgs_date, pm.privmsgs_subject, u.user_id, u.username, u.first_name, u.last_name \
	FROM jforum_privmsgs pm, jforum_users u \
	#FILTER# \
	ORDER BY pm.privmsgs_date DESC

ModerationModel.topicsByForum = SELECT p.post_id, t.topic_id, t.topic_title, t.topic_replies, p.user_id, enable_bbcode, p.attach, \
	enable_html, enable_smilies, pt.post_subject, pt.post_text, username, first_name, last_name \
	FROM jforum_posts p, jforum_posts_text pt, jforum_users u, jforum_topics t \
	WHERE p.post_id = pt.post_id \
	AND p.topic_id = t.topic_id \
	AND t.forum_id = ? \
	AND p.user_id = u.user_id \
	AND p.need_moderate = 1 \
	ORDER BY t.topic_id, post_time ASC

ModerationLog.selectAll = SELECT l.*, u.username, u2.username AS poster_username, u2.first_name AS poster_first_name, u2.last_name AS poster_last_name FROM jforum_moderation_log l \
	LEFT JOIN jforum_users u2 ON u2.user_id = l.post_user_id \
	LEFT JOIN jforum_users u ON l.user_id = u.user_id \
	ORDER BY log_id DESC \
	LIMIT ?, ?

3.JForum provide a method getName() in net.jforum.entities.User.java, we can modify it as follows to change the order of first name and last name for some languages like zh_CN and zh_TW:
	public String getName()
	{
		String defaultLang = SystemGlobals.getValue(ConfigKeys.I18N_DEFAULT);
		if ((this.lang != null && this.lang.startsWith("zh")) || defaultLang.startsWith("zh")) {
			return this.lastName + this.firstName;
		} else {
		    return this.firstName + " " + this.lastName;
		}
	}

4.Modify net.jforum.entities.UserSession.java, add a new attribute "name" and modify some method to store its value:
private String name;
public String getName()
public String setName(String name)

public UserSession(UserSession us)
{
                ...
		this.name = us.getName();
                ...
}

public void dataToUser(User user)
{
                ...
		this.setName(user.getName());
                ...
}

5.Modify net.jforum.dao.generic.GenericUserSessionDAO.java
public UserSession selectById(UserSession us, Connection conn)
	public UserSession selectById(UserSession us, Connection conn)
	{
                        ...
			if (rs.next()) {
				returnUs.setSessionTime(rs.getLong("session_time"));
				returnUs.setStartTime(rs.getTimestamp("session_start"));
				found = true;
			}
			rs.close();
			rs = null;
			p.close();			
			p = null;
			
			p = conn.prepareStatement(SystemGlobals.getSql("UserModel.selectById"));
			p.setInt(1, us.getUserId());
			rs = p.executeQuery();
			if (rs.next()) {
				String defaultLang = SystemGlobals.getValue(ConfigKeys.I18N_DEFAULT);
				String lang = returnUs.getLang();
				if ((lang != null && lang.startsWith("zh")) || defaultLang.startsWith("zh")) {				
				    returnUs.setName(rs.getString("last_name")+rs.getString("first_name"));
				} else {
					returnUs.setName(rs.getString("first_name") + " " + rs.getString("last_name"));
				}
			}
			return (found ? returnUs : null);
		}
                ...
	}

6.Modify net.jforum.entities.LastPostInfo.java
private String name;
public String getName()
public String setName(String name)

7.Modify net.jforum.repository.ForumRepository.java
public static synchronized void updateForumStats(Topic t, User u, Post p)
{
                        ...
			lpi.setUsername(u.getUsername());
			lpi.setName(u.getName());
			forum.setLastPostInfo(lpi);
                        ...
}

8.Modify net.jforum.dao.generic.GenericForumDAO.java
private LastPostInfo getLastPostInfo(int forumId, boolean tryFix)
{
                                ...
			if (rs.next()) {
                                ...
				String defaultLang = SystemGlobals.getValue(ConfigKeys.I18N_DEFAULT);
				if (defaultLang.startsWith("zh")) {
				    lpi.setName(rs.getString("last_name")+ rs.getString("first_name"));
				} else {
					lpi.setName(rs.getString("first_name")+ " " + rs.getString("last_name"));								
				}
                                ...
}

9.Modify net.jforum.view.forum.UserAction.java
public void edit()
{
                        ...
			this.context.put("u", u);
			this.context.put("action", "editSave");
			this.context.put("pageTitle", I18n.getMessage("UserProfile.profileFor") + " " + u.getName());
                        ...
}

public void profile()
{
                        ...
			this.context.put("pageTitle", I18n.getMessage("UserProfile.allAbout")+" "+u.getName());
                        ...
}

10.Modify net.jforum.dao.generic.GenericTopicDAO.java
public List fillTopicsData(PreparedStatement p)
{
                               ...
				while (rs.next()) {
					User u = new User();
					u.setId(rs.getInt("user_id"));
					u.setUsername(rs.getString("username"));
					u.setFirstName(rs.getString("first_name"));
					u.setLastName(rs.getString("last_name"));
					users.put(new Integer(rs.getInt("user_id")), u);
				}
                                 ...
				for (Iterator iter = l.iterator(); iter.hasNext();) {
					Topic t = (Topic) iter.next();					
					t.setPostedBy((User)users.get(new Integer(t.getPostedBy().getId())));
					t.setLastPostBy((User)users.get(new Integer(t.getLastPostBy().getId())));
				}
                                ...
}

public Map topicPosters(int topicId)
{
                                ...
				u.setSignature(rs.getString("user_sig"));
				u.setFirstName(rs.getString("first_name"));
				u.setLastName(rs.getString("last_name"));

				m.put(new Integer(u.getId()), u);
                                ...
}

11.Modify net.jforum.dao.generic.GenericPrivateMessageDAO.java
public List selectFromInbox(User user)
{
                               ...
				fromUser.setFirstName(rs.getString("first_name"));
				fromUser.setLastName(rs.getString("last_name"));
                               ...
}

public List selectFromSent(User user)
{
                                ...
				toUser.setFirstName(rs.getString("first_name"));
				toUser.setLastName(rs.getString("last_name"));
                                ...
}

12.Modify net.jforum.view.forum.PrivateMessageAction.java
public void sendTo()
{
                        ...	
			this.context.put("toUsername", recipient.getName());
			this.context.put("pageTitle", I18n.getMessage("PrivateMessage.title") 
				+ " " + I18n.getMessage("PrivateMessage.to") 
				+ " " + recipient.getName());
                        ...
}

public void quote()
{
                ...
		this.context.put("quote", "true");
		this.context.put("quoteUser", pm.getFromUser().getNickname());
		this.context.put("post", pm.getPost());
                ...
}

13.Modify net.jforum.entities.Post.java
private String authorName;
public String getAuthorName()
public void setAuthorName(String authorName)
public Post(Post p) {
...
this.setAuthorName(p.getAuthorName());
}

14.Modify net.jforum.dao.generic.GenericLuceneDAO.java
public List getPostsData(int[] postIds)
{
                                                ...
			while (rs.next()) {
				Post post = this.makePost(rs);
				post.setPostUsername(rs.getString("username"));
				String lang = SystemGlobals.getValue(ConfigKeys.I18N_DEFAULT);
				if (lang.startsWith("zh")) {
				    post.setAuthorName(rs.getString("last_name") + rs.getString("first_name"));
				} else {
				    post.setAuthorName(rs.getString("first_name") + " " + rs.getString("last_name"));
				}
				
				l.add(post);
			}
                                                ...
}

15.Modify net.jforum.view.forum.PostAction.java
public void quote()
{
                                ...
		this.context.put("quoteUser", u.getName());
                                ...
}

public void listByUser()
{
		...
		this.context.put("pageTitle", I18n.getMessage("PostShow.userPosts") + " " + u.getName());
		...
}

16.Modify net.jforum.view.forum.RecentTopicsAction.java
public void showTopicsByUser() 
{
		...
		this.context.put("pageTitle", I18n.getMessage("ForumListing.userTopics") + " " + u.getName());
		...
}

17. Modify net.jforum.view.forum.HottestTopicsAction.java
public void showTopicsByUser() 
{
                ...
		this.context.put("u", u);
		this.context.put("pageTitle", I18n.getMessage("ForumListing.userTopics") + " " + u.getNickname());
                ...

}

18. Modify net.jforum.dao.generic.GenericModerationDAO.java
	protected Post getPost(ResultSet rs) throws SQLException
	{
		Post p = new Post();
		
		p.setPostUsername(rs.getString("username"));
                                String lang = SystemGlobals.getValue(ConfigKeys.I18N_DEFAULT);
		if (lang.startsWith("zh")) {
		    p.setAuthorName(rs.getString("last_name") + rs.getString("first_name"));
		} else {
		    p.setAuthorName(rs.getString("first_name") + " " + rs.getString("last_name"));
		}
		p.setId(rs.getInt("post_id"));
		p.setUserId(rs.getInt("user_id"));
		p.setBbCodeEnabled(rs.getInt("enable_bbcode") == 1);
		p.setHtmlEnabled(rs.getInt("enable_html") == 1);
		p.setSmiliesEnabled(rs.getInt("enable_smilies") == 1);
		p.setSubject(rs.getString("post_subject"));
		p.setText(this.getPostTextFromResultSet(rs));
		
		return p;
	}

19.Modify net.jforum.view.forum.BookmarkAction.java
	private void addUser()
	{
		User u = DataAccessDriver.getInstance().newUserDAO().selectById(
				this.request.getIntParameter("relation_id"));
		String title = u.getName();
                ...
        }
 
	public void list()
	{
		...
		this.context.put("pageTitle", I18n.getMessage("Bookmarks.for")+" "+u.getName());				
	}

20.Modify net.jforum.view.forum.ForumAction.java
public void list()
{
...
if (onlineUsersList.size() == 0) {
UserSession us = new UserSession();

us.setUserId(aid);
us.setUsername(I18n.getMessage("Guest"));
us.setFirstName(I18n.getMessage("Guest"));

onlineUsersList.add(us);
}
...
}
21.Replace ".username" with ".name" in the following files under templates/default/ diectory:
forum_list.htm
forum_show.htm
recent_thread.htm
hottest_thread.htm
new_message.htm
user_list.htm
user_posts_show.htm
user_topics_show.htm
post_show_user_inc.htm
topic_review.htm
pm_list.htm
pm_finduser.htm
pm_read_message.htm
pm_review_message.htm
bookmark_list.htm

22.Replace ${topic.postedBy.username?html} with ${u.name?html} and replace ${topic.lastPostBy.username?html? with ${u.name?html} in the following files under templates/default/ diectory:
user_topics_show.htm
new_message.htm

23.Replace ".postUsername" with ".authorName" in the following files under templates/default/ diectory:
search_result.htm
forum_show.htm
1.Add these two columns (first_name and last_name) into jforum_users table:
ALTER TABLE jforum_users ADD first_name VARCHAR(50);
ALTER TABLE jforum_users ADD last_name VARCHAR(50);

2.Add these keys to WEB-INF/config/jforum-custom.conf:
authentication.type=sso
sso.implementation=net.jforum.sso.MyUserSSO
sso.redirect=http\://member.andowson.com/sso/login.jsp
cookie.name.user=username
cookie.name.email=email
cookie.name.first=firstname
cookie.name.last=lastname
sso.firstname.attribute=firstname
sso.lastname.attribute=lastname
sso.default.firstname=Unknown
sso.default.lastname=User

member.andowson.com is where we are going to authenticate the user. Change to your real case.

3.Modify net.jforum.util.preferences.ConfigKeys.java:
Add these lines into ConfigKeys.java
	public static final String SSO_FIRSTNAME_ATTRIBUTE = "sso.firstname.attribute";
	public static final String SSO_LASTNAME_ATTRIBUTE = "sso.lastname.attribute";
	public static final String SSO_DEFAULT_FIRSTNAME = "sso.default.firstname";
	public static final String SSO_DEFAULT_LASTNAME = "sso.default.lastname";
	public static final String COOKIE_NAME_EMAIL = "cookie.name.email";
	public static final String COOKIE_NAME_FIRST = "cookie.name.first";
	public static final String COOKIE_NAME_LAST = "cookie.name.last";

4.Add net.jforum.sso.MyUserSSO.java which implements net.jforum.sso.SSO interface
package net.jforum.sso;

import java.io.UnsupportedEncodingException;

import java.net.URLDecoder;
import javax.servlet.http.Cookie;
import net.jforum.context.RequestContext;
import net.jforum.context.SessionContext;
import net.jforum.ControllerUtils;
import net.jforum.JForumExecutionContext;
import net.jforum.entities.UserSession;
import net.jforum.util.preferences.ConfigKeys;
import net.jforum.util.preferences.SystemGlobals;
import org.apache.log4j.Logger;

public class MyUserSSO implements SSO {

	static final Logger logger = Logger.getLogger(CookieUserSSO.class.getName());

	public String authenticateUser(RequestContext request) {		
		// myapp login cookie, contain logged username
		Cookie myCookie = ControllerUtils.getCookie(SystemGlobals.getValue(ConfigKeys.COOKIE_NAME_USER));		
		String username = null;
		String email = null;
		String firstName = null;
		String lastName = null;
		
		if (myCookie != null) {
			username = myCookie.getValue();		
		}
		SessionContext session = JForumExecutionContext.getRequest().getSessionContext();
		String encoding = "Big5";
		try {			
			myCookie = ControllerUtils.getCookie(SystemGlobals.getValue(ConfigKeys.COOKIE_NAME_EMAIL));
			if (myCookie != null) {
				email = myCookie.getValue();
				session.setAttribute(SystemGlobals.getValue(ConfigKeys.SSO_EMAIL_ATTRIBUTE), URLDecoder.decode(email, encoding));
			}
			myCookie = ControllerUtils.getCookie(SystemGlobals.getValue(ConfigKeys.COOKIE_NAME_FIRST));
			if (myCookie != null) {
				firstName = myCookie.getValue();
				session.setAttribute(SystemGlobals.getValue(ConfigKeys.SSO_FIRSTNAME_ATTRIBUTE), URLDecoder.decode(firstName, encoding));
			}
			myCookie = ControllerUtils.getCookie(SystemGlobals.getValue(ConfigKeys.COOKIE_NAME_LAST));
			if (myCookie != null) {
				lastName = myCookie.getValue();
				session.setAttribute(SystemGlobals.getValue(ConfigKeys.SSO_LASTNAME_ATTRIBUTE), URLDecoder.decode(lastName, encoding));
			} 
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return username; // jforum username
	}

	public boolean isSessionValid(UserSession userSession, RequestContext request) {
		Cookie SSOCookie = ControllerUtils.getCookie(
				SystemGlobals.getValue(ConfigKeys.COOKIE_NAME_USER)); // myapp login cookie		
		String remoteUser = null;

		if (SSOCookie != null) {
			remoteUser = SSOCookie.getValue(); //  jforum username
		}

		// user has since logged out
		if (remoteUser == null 
				&& userSession.getUserId() != SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {
			return false;
			// user has since logged in
		} else if (remoteUser != null
				&& userSession.getUserId() == SystemGlobals.getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {
			return false;
			// user has changed user
		} else if (remoteUser != null && !remoteUser.equals(userSession.getUsername())) {
			return false;
		}
		return true; // myapp user and forum user the same
	}
}

5.Modify net.jforum.ControllerUtils.java:
edit method: protected void checkSSO(UserSession userSession)
	/**
	 * Checks for user authentication using some SSO implementation
     * @param userSession UserSession
     */
	protected void checkSSO(UserSession userSession)
	{
		try {
			SSO sso = (SSO) Class.forName(SystemGlobals.getValue(ConfigKeys.SSO_IMPLEMENTATION)).newInstance();
			String username = sso.authenticateUser(JForumExecutionContext.getRequest());

			if (username == null || username.trim().equals("")) {
				userSession.makeAnonymous();
			}
			else {
				SSOUtils utils = new SSOUtils();

				if (!utils.userExists(username)) {
					SessionContext session = JForumExecutionContext.getRequest().getSessionContext();

					String email = (String) session.getAttribute(SystemGlobals.getValue(ConfigKeys.SSO_EMAIL_ATTRIBUTE));
					String password = (String) session.getAttribute(SystemGlobals.getValue(ConfigKeys.SSO_PASSWORD_ATTRIBUTE));
					String firstName = (String) session.getAttribute(SystemGlobals.getValue(ConfigKeys.SSO_FIRSTNAME_ATTRIBUTE));
					String lastName = (String) session.getAttribute(SystemGlobals.getValue(ConfigKeys.SSO_LASTNAME_ATTRIBUTE));
          
					if (email == null) {
						email = SystemGlobals.getValue(ConfigKeys.SSO_DEFAULT_EMAIL);
					}

					if (password == null) {
						password = SystemGlobals.getValue(ConfigKeys.SSO_DEFAULT_PASSWORD);
					}

					if (firstName == null) {
						firstName = SystemGlobals.getValue(ConfigKeys.SSO_DEFAULT_FIRSTNAME);
					}

					if (lastName == null) {
						lastName = SystemGlobals.getValue(ConfigKeys.SSO_DEFAULT_LASTNAME);
					}
          					
					utils.register(password, email, firstName, lastName);
				}

				this.configureUserSession(userSession, utils.getUser());
			}
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new ForumException("Error while executing SSO actions: " + e);
		}
	}

6.Modify net.jforum.sso.SSOUtils.java
add a new method: public void register(String password, String email, String firstName, String lastName)
	/**
	 * Registers a new user. 
	 * This method should be used together with {@link #userExists(String)}. 
	 * 
	 * @param password the user's password. It <em>should</em> be the real / final 
	 * password. In other words, the data passed as password is the data that'll be
	 * written to the database
	 * @param email the user's email
	 * @param firstName the user's first name
	 * @param lasstName the user's last name 
	 * @see #getUser()
	 */
	public void register(String password, String email, String firstName, String lastName)
	{
		if (this.exists) {
			return;
		}
		
		// Is a new user for us. Register him
		this.user = new User();
		user.setUsername(this.username);		
		user.setPassword(password);
		user.setEmail(email);
		user.setActive(1);		
		user.setFirstName(firstName);
		user.setLastName(lastName);
		
		this.dao.addNew(user);
	}

7.Modify net.jforum.dao.generic.GenericUserDAO.java
store firstName and lastName to database
	protected void initNewUser(User user, PreparedStatement p) throws SQLException
	{
		p.setString(1, user.getUsername());
		p.setString(2, user.getPassword());
		p.setString(3, user.getEmail());
		p.setTimestamp(4, new Timestamp(System.currentTimeMillis()));
		p.setString(5, user.getActivationKey());
		p.setString(6, user.getFirstName());
		p.setString(7, user.getLastName());
	}

8.Modify WEB-INF/config/database/generic/generic_queries.sql
UserModel.addNew = INSERT INTO jforum_users (username, user_password, user_email, user_regdate, user_actkey, rank_id, first_name, last_name) VALUES (?, ?, ?, ?, ?, 0, ?, ?)

Oracle Database user have to edit WEB-INF/config/database/oracle/oracle.sql
UserModel.addNew = INSERT INTO jforum_users (user_id, username, user_password, user_email, user_regdate, user_actkey, rank_id, first_name, last_name) VALUES (jforum_users_seq.nextval, ?, ?, ?, ?, ?, 0, ?, ?)

9.Edit /sso/login.jsp on member.andowson.com
<%@ page contentType="text/html;charset=big5" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5" />
<title>JForum SSO Login</title>
</head>
<body>
<form name="loginform" method="post" action="proc_login.jsp">
  <input type="hidden" name="redirect" value="<%=request.getParameter("returnUrl")%>" />
  <div align="center">
  Username: <input type="text" name="username" /><br />
  Password: <input type="password" name="password" /><br />
  <input type="submit" value="Login" />
  </div>
</form>
</body>
</html>

10.Edit /sso/proc_login.jsp on member.andowson.com
<%@ page contentType="text/html;charset=big5" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.Properties" %>
<%@ page import="com.oreilly.servlet.ParameterParser" %>
<%    
    ParameterParser parser = new ParameterParser(request);
    parser.setCharacterEncoding("Big5");
    String username = parser.getStringParameter("username", null);
    String password = parser.getStringParameter("password", null);
    String redirect = parser.getStringParameter("redirect", null);
        
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    String sql = null;
    String email = null;
    String firstName = null;
    String lastName =  null;    
    boolean login = false;
        
    if (username != null && password != null) {
        try {    
            final String url = "jdbc:postgresql://127.0.0.1:5432/member";
            final Properties info = new Properties();
            info.setProperty("user", "member");
            info.setProperty("password", "member");
            Class.forName("org.postgresql.Driver");             
            con = DriverManager.getConnection(url, info);
            sql = "select * from users where username = ? and password = ?";
            pstmt = con.prepareStatement(sql);
            pstmt.setString(1, username);
            pstmt.setString(2, password);
            rs = pstmt.executeQuery();
            if (rs.next()) {
                email = rs.getString("email");        
                firstName = rs.getString("first_name");
                lastName = rs.getString("last_name");
                login = true;             
            }
            rs.close();
            rs = null;
            pstmt.close();
            pstmt = null;
            con.close();
            con = null;
        } catch (SQLException se) {
            out.println(se.getMessage());
        } finally {
            // Always make sure result sets and statements are closed,
            // and the connection is returned to the pool
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    out.println(e.getMessage());
                }
                rs = null;
            }
            if (pstmt != null) {
                try {
                    pstmt.close();
                } catch (SQLException e) {
                    out.println(e.getMessage());
                }
                pstmt = null;
            }
            if (con != null) {
                try {
                    con.close();
                } catch (SQLException e) {
                    out.println(e.getMessage());
                }
                con = null;
            }
        }
    }
    if (login) {            
        Cookie cookieUsername = new Cookie("username", username);
        cookieUsername.setMaxAge(-1);
        cookieUsername.setPath("/");
        response.addCookie(cookieUsername);

        Cookie cookieEmail = new Cookie("email", java.net.URLEncoder.encode(email, "Big5"));
        cookieEmail.setMaxAge(-1);
        cookieEmail.setPath("/");
        response.addCookie(cookieEmail);
    
        Cookie cookieFirstName = new Cookie("firstname", java.net.URLEncoder.encode(firstName, "Big5"));
        cookieFirstName.setMaxAge(-1);
        cookieFirstName.setPath("/");
        response.addCookie(cookieFirstName);
    
        Cookie cookieLastName = new Cookie("lastname", java.net.URLEncoder.encode(lastName, "Big5"));
        cookieLastName.setMaxAge(-1);
        cookieLastName.setPath("/");
        response.addCookie(cookieLastName);
    
        if (redirect != null && redirect.trim().length() > 0 && !"null".equals(redirect)) {
            response.sendRedirect(redirect);
        }
    } else {
        out.println("Login failed!");
    }            
%>

Windows Server 2003 提供的終端機服務預設聽取的Port是TCP 3389,並可允許最高兩個工作階段,只要開放防火牆可以連入後,就可進行遠端管理,非常方便。如果沒有設定好,就會碰到類似下面的這種訊息:「您的終端機服務臨時用戶端授權將在 N 天後到期。請連絡您的系統管理員以取得永久的授權。」,例如
image
解決方法是開啟「系統管理工具」裡面的「終端機服務設定」,調整授權模式為每個使用者
image
修改完成後,畫面如下:
image
如果要讓同一個使用者帳號可以同時給兩個連線使用(開兩窗,或兩個人各開一窗),可順便調整「限制每個使用者只能有一個工作階段」為「否」
image
修改完成後,畫面如下:
image
這樣子就可以繼續使用終端機服務了。

參考資料:
http://support.microsoft.com/default.aspx/kb/822134/zh-tw
1.編輯server.xml,加入<Resource>到<Context>
        <Context path="" docBase="webapps/forum.mycompany.com" debug="0" reloadable="false">
          <Resource name="jdbc/JForumDB" auth="Container"
                    type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"                   url="jdbc:oracle:thin:@(description=(ENABLE=BROKEN)(load_balance=on)(FAILOVER_MODE=(RETRIES=20)(DELAY=15))(address=(protocol=tcp)(host=LISTENER_DB1)(port=1521))(address=(protocol=tcp)(host=LISTENER_DB2)(port=1521))(connect_data=(service_name=racdb)))"
                    username="jforum" password="jforum" maxActive="100" maxIdle="1"
                    maxWait="-1" removeAbandoned="true"	removeAbandonedTimeout="60" 
                    logAbandoned="true"/>
        </Context>


其中LISTENER_DB1和LISTENER_DB2已經在/etc/hosts設定好對應到兩部資料庫的主機IP。

2.編輯WEB-INF/web.xml,加入<resource-ref>:
  <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/JForumDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>


3.修改WEB-INF/config/jforum-custom.conf,將database.connection.implementation改為net.jforum.DataSourceConnection,並加入database.datasource.name這個key,並設定其值為java:/comp/env/jdbc/JForumDB。接著我們可以把其他database開頭的資料庫連線相關設定key一併刪除,完成後看起來就像下面的樣子:
...
dao.driver=net.jforum.dao.oracle.OracleDataAccessDriver
database.connection.implementation=net.jforum.DataSourceConnection
database.datasource.name=java:/comp/env/jdbc/JForumDB
database.driver.name=oracle
database.support.autokeys=false
database.support.subqueries=true
...


4.複製WEB-INF/lib/下的資料庫JDBC Driver到Tomcat的common/lib下,例如ojdbc14.jar。

5.重新啟動Tomcat

6.連線到討論區網站首頁,如果正常顯示即OK。

參考資料:
http://www.jforum.net/posts/list/1363.page
http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.html
image
GreyBox can be used to display websites, images and other content in a beautiful way.

另外一個用jQuery實作的Greybox Redux也可以參考看看。
功能需求:讓匿名訪客不用登入前也可以選擇自己偏好的語言。

設計:
1.在header.htm上新增一個超連結到/user/changeLang.page。
2.按下/user/changeLang.page時JForum內部呼叫UserAction.java的changeLang()來顯示選擇語言畫面(user_lang.htm)。
3.按下送出後JForum呼叫UserAction.java的changeLangDone()來修改UserSession中的語言設定。

參考作法:
1.修改WEB-INF/config/urlPattern.properties,增加兩個keys:
user.changeLang.0 =
user.changeLangDone.0 =


2.修改WEB-INF/config/templatesMapping.properties,增加一個key:
user.changeLang = user_lang.htm


3.修改templates/default/user_forum.htm,將跟語言無關的欄位刪除,另存新檔為user_lang.htm。

4.修改templates/default/header.htm,加上超連結,例如我選擇在原本登入的後面加上。

5.修改net/jforum/view/forum/UserAction.java,加上以下兩個methods:
	public void changeLang()
	{
		int userId = SessionFacade.getUserSession().getUserId();
		UserDAO um = DataAccessDriver.getInstance().newUserDAO();
		User u = um.selectById(userId);
		this.context.put("u", u);
		this.context.put("action", "changeLangDone");
		this.context.put("pageTitle", I18n.getMessage("UserProfile.profileFor") + " " + u.getUsername());			
		this.setTemplateName(TemplateKeys.USER_CHANGE_LANG); 
	}

	public void changeLangDone()
	{
		SessionFacade.getUserSession().setLang(request.getParameter("language"));
		this.context.put("editDone", true);
		this.changeLang();
	}


6.修改net/jforum/util/preferences/TemplateKeys.java,增加一個key:
	public static final String USER_CHANGE_LANG = "user.changeLang";


7.編譯程式

8.重新載入JForum,測試是否正常。

大功告成!
 
Forum Index » Profile for andowson » Messages posted by andowson
Go to: