com.stephenschafer.email/WebContent/register.jsp

101 lines
2.1 KiB
Text
Raw Normal View History

2024-12-05 13:35:23 -07:00
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.stephenschafer.email.Util"%>
<%@ page import="com.stephenschafer.email.Session"%>
<%@ page import="com.stephenschafer.email.User"%>
<%
final String message;
if("post".equalsIgnoreCase(request.getMethod())) {
final String username = request.getParameter("username");
final String password1 = request.getParameter("password1");
final String password2 = request.getParameter("password2");
final String displayName = request.getParameter("displayName");
final boolean canWrite = "true".equals(request.getParameter("canWrite"));
if(!password1.equals(password2)) {
message = "Passwords don't match.";
}
else {
final User user = Util.register(username, password1, displayName, canWrite);
if(user != null) {
Session emailSession = new Session();
emailSession.setUser(user);
session.setAttribute("email-session", emailSession);
response.sendRedirect("index.jsp");
return;
}
message = "That didn't work.";
}
}
else {
message = null;
}
%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Register</title>
<style>
body {
font-family: sans-serif;
font-size: 10pt;
}
table {
font-family: inherit;
font-size: inherit;
}
table {
border-spacing: 0px;
}
table.td {
padding: 0px;
}
div.buttons {
margin-top: 10px;
}
</style>
</head>
<body>
<%
if(message != null) {
%><div class="fail">
<%=message %>
</div>
<%
}
%><form name="register" action="register.jsp" method="post">
<table>
<tr>
<td>Username</td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password1"/></td>
</tr>
<tr>
<td>Confirm password</td>
<td><input type="password" name="password2"/></td>
</tr>
<tr>
<td>Display name</td>
<td><input type="text" name="displayName"/></td>
</tr>
<tr>
<td>Can write</td>
<td><input type="checkbox" name="canWrite" value="true"/></td>
</tr>
</table>
<div class="buttons">
<button type="submit">Register</button>
</div>
</form>
</body>
</html>