
<%
/**
 *	$RCSfile: account.jsp,v $
 *	$Revision: 1.1.1.1 $
 *	$Date: 2002/09/09 13:50:22 $
 */
%>

<%@	page import="com.jivesoftware.forum.*,
                 com.jivesoftware.forum.util.*"
	errorPage="error.jsp"
%>

<%@ include file="include/branding/style.jsp" %>

<%@ include file="include/forumSetup.jsp" %>

<%	//////////////////
	// get parameters
	
	boolean doCreate = ParamUtils.getBooleanParameter(request,"doCreate");
	String newUsername = ParamUtils.getParameter(request,"username");
	String newPassword = ParamUtils.getParameter(request,"password");
	String confirmPassword = ParamUtils.getParameter(request,"confirmPassword");
	String newEmail = ParamUtils.getParameter(request,"email");
	String newName = ParamUtils.getParameter(request,"name");
	boolean autoLogin = ParamUtils.getBooleanParameter(request,"autoLogin");
	String referringPage = ParamUtils.getParameter(request,"referringPage");
        if (referringPage == null) {
            referringPage = request.getHeader("REFERER");
        }
%>

<%	//////////////////
	// global error vars
	
	String errorMessage = "";
	
	boolean errorUsername         = (newUsername == null);
	boolean errorPassword         = (newPassword == null);
	boolean errorConfirmPassword  = (confirmPassword == null);
	boolean errorEmail            = (newEmail == null);
	boolean errorName             = (newName == null);
	boolean errorNoMatchPasswords = true;
	if( !errorPassword && !errorConfirmPassword ) {
		errorNoMatchPasswords = !newPassword.equals(confirmPassword);
	}
	boolean errors = (errorUsername || errorPassword || errorConfirmPassword
						|| errorEmail || errorName || errorNoMatchPasswords );
%>

<%	//////////////////
	// error message
	if( errors ) {
		errorMessage = "Oops! There were errors in the form. Please check each field.";
	}
%>

<%	//////////////////////////
	// create user, if no errors
	if( doCreate && !errors ) { 
		try {
			User newUser = forumFactory.getUserManager()
			                           .createUser(newUsername,newPassword,newEmail);
			newUser.setName( newName );
			// getting to this point means the account was created successfully.
			// We store a success message so the main page can display it.
			session.setAttribute("message",
				"Account created successfully. You are logged in as <b>" + newUsername + "</b>.");
			// set this new user's authorization token
			SkinUtils.setUserAuthorization(request,response,newUsername,newPassword,autoLogin);
			// redirect to main page
			response.sendRedirect("index.jsp");
			return;
		}
		catch(UserAlreadyExistsException uaee) {
			errorMessage = "Sorry, the username \"" + newUsername + "\" already "
				+ "exists. Try a different username.";
			errorUsername = true;
			errors = true;
		}
	}
%>

<%  String title = titlePrefix; %>
<%@ include file="include/header.jsp" %>

<%@ include file="include/branding/header.jsp" %>

<span class="header">
<%  if (rootBreadcrumbText != null && rootBreadcrumbLink != null) { %>
<a href="<%= rootBreadcrumbLink %>" class="header"
><%= rootBreadcrumbText %></a>
&raquo;
<%  } %>
<a href="index.jsp" class="header" title="Go back to the forum listing"
>Forums</a>
&raquo;
Create User Account
</span>
<p>

<%	if( doCreate && errors ) {
%>
	<font size="-1"><i><%= errorMessage %></i></font>
    <p>
<%	}
%>

<center>
<font size="-1">
	<i>All fields are required!</i>
</font>
</center>

<p>

<form action="account.jsp" method="post" name="userForm">
<input type="hidden" name="doCreate" value="true">
<input type="hidden" name="referringPage" value="<%=referringPage%>">

	<table cellpadding="3" cellspacing="0" border="0" width="100%">
	<tr>
		<td align="right">
        <font size="-1">
			Your Name:
		</font>
		</td>
		<td>
		<%	if( doCreate && errorName ) { %>
		    <input type="text" name="name" size="30" maxlength="50" 
			 value="<%= (newName!=null)?newName:"" %>" style="background-color:#ffffcc">
		<%	} else { %> 
		    <input type="text" name="name" size="30" maxlength="50" 
			 value="<%= (newName!=null)?newName:"" %>">
		<%	} %>
		</td>
	</tr>
	<tr>
		<td align="right"><font size="-1">Email:</font></td>
		<td>
		<%	if( doCreate && errorEmail ) { %>
		    <input type="text" name="email" size="30" maxlength="50" 
			 value="<%= (newEmail!=null)?newEmail:"" %>" style="background-color:#ffffcc">
		<%	} else { %>
		    <input type="text" name="email" size="30" maxlength="50" 
			 value="<%= (newEmail!=null)?newEmail:"" %>">
		<%	} %>
		</td>
	</tr>
	<tr>
		<td align="right"><font size="-1">Desired Username:</font></td>
		<td>
		<%	if( doCreate && errorUsername ) { %>
		    <input type="text" name="username" size="30" maxlength="50" 
			 value="<%= (newUsername!=null)?newUsername:"" %>" style="background-color:#ffffcc">
		<%	} else { %>
		    <input type="text" name="username" size="30" maxlength="50" 
			 value="<%= (newUsername!=null)?newUsername:"" %>">
		<%	} %>
		</td>
	</tr>
	<tr>
		<td align="right"><font size="-1">Password:</font></td>
		<td>
		<%	if( doCreate && (errorPassword || errorNoMatchPasswords) ) { %>
		    <input type="password" name="password" size="30" maxlength="50" 
			 value="<%= (newPassword!=null)?newPassword:"" %>" style="background-color:#ffffcc">
		<%	} else { %>
		    <input type="password" name="password" size="30" maxlength="50" 
			 value="<%= (newPassword!=null)?newPassword:"" %>">
		<%	} %>
		</td>
	</tr>
	<tr>
		<td align="right"><font size="-1">Confirm Password:</font></td>
		<td>
		<%	if( doCreate && (errorConfirmPassword || errorNoMatchPasswords) ) { %>
		    <input type="password" name="confirmPassword" size="30" maxlength="50" 
			 value="<%= (confirmPassword!=null)?confirmPassword:"" %>" style="background-color:#ffffcc">
		<%	} else { %>
		    <input type="password" name="confirmPassword" size="30" maxlength="50" 
			 value="<%= (confirmPassword!=null)?confirmPassword:"" %>">
		<%	} %>
		</td>
	</tr>
	<tr>
		<td align="center" colspan="2">
			<br>
			<input type="submit" value="Create Account">
		</td>
	</tr>
	</table>
	<script language="JavaScript" type="text/javascript">
	<!--
		document.userForm.name.focus();
	//-->
	</script>
</form>

<br>

<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
    <td align="right">
    <a href="http://www.jivesoftware.com/poweredby/" target="_blank"
    ><img src="images/powered_by_jive.gif" width="100" height="30" alt="Powered by Jive" border="0"></a>
    </td>
</tr>
</table>

<%@ include file="include/branding/footer.jsp" %>

<%@ include file="include/footer.jsp" %>