[Cruce-commit] SF.net SVN: cruce:[152] JSP/trunk/Forum
Status: Beta
Brought to you by:
caiusb
|
From: <ali...@us...> - 2010-05-18 08:38:51
|
Revision: 152
http://cruce.svn.sourceforge.net/cruce/?rev=152&view=rev
Author: alinposho
Date: 2010-05-18 08:38:40 +0000 (Tue, 18 May 2010)
Log Message:
-----------
Am schimbat putin pagina de index si am adugat paginile pentru register si login.
Modified Paths:
--------------
JSP/trunk/Forum/WebContent/Thread.jsp
JSP/trunk/Forum/WebContent/index.jsp
JSP/trunk/Forum/src/prc/bubulina/forum/businessLogic/Singleton.java
JSP/trunk/Forum/src/prc/bubulina/forum/data_access/ForumDAOFactory.java
JSP/trunk/Forum/src/prc/bubulina/forum/data_access/ForumThreadDAO.java
Added Paths:
-----------
JSP/trunk/Forum/WebContent/commitRegister.jsp
JSP/trunk/Forum/WebContent/login.jsp
JSP/trunk/Forum/WebContent/register.jsp
Modified: JSP/trunk/Forum/WebContent/Thread.jsp
===================================================================
--- JSP/trunk/Forum/WebContent/Thread.jsp 2010-05-17 18:07:33 UTC (rev 151)
+++ JSP/trunk/Forum/WebContent/Thread.jsp 2010-05-18 08:38:40 UTC (rev 152)
@@ -15,7 +15,7 @@
<%
String sID = request.getParameter("id");
int id = Integer.parseInt(sID);
- ForumThread thread = Singleton.getInstance().getThreadDAO().get(id);
+ ForumThread thread = Singleton.getInstance().getThreadDAO().get(id);;
%>
<title>Forum Bubulina: Thread - <% out.println(thread.name); %></title>
</head>
Added: JSP/trunk/Forum/WebContent/commitRegister.jsp
===================================================================
--- JSP/trunk/Forum/WebContent/commitRegister.jsp (rev 0)
+++ JSP/trunk/Forum/WebContent/commitRegister.jsp 2010-05-18 08:38:40 UTC (rev 152)
@@ -0,0 +1,99 @@
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+ pageEncoding="ISO-8859-1"%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+
+<%@page import="prc.bubulina.forum.data_access.UserDAO"%>
+<%@page import="prc.bubulina.forum.businessLogic.Singleton"%><html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Insert title here</title>
+</head>
+<body>
+
+<%
+ //checking the validity of the fields
+ UserDAO userDAO = Singleton.getInstance().getUserDAO();
+ String userName = request.getParameter("userName");
+ String password = request.getParameter("password");
+ String checkPassword = request.getParameter("checkPassword");
+ String email = request.getParameter("email");
+ String problem = null;
+ if(userName == null || userName.isEmpty() || userName.equals("null") ||
+ (userDAO.get(userName) != null))
+ {
+ problem = "Wrong userName!";
+ }
+ else
+ {
+ if(password == null || password.isEmpty() || password.equals("null"))
+ {
+ problem = "null or empty password!";
+ }
+ else
+ {
+ if(checkPassword == null || checkPassword.isEmpty() || checkPassword.equals("null"))
+ {
+ problem = "null or empty password retyper!";
+ }
+ else
+ {
+ if(password.equals(checkPassword) == false)
+ {
+ problem = "Please retype password!";
+ }
+ else
+ {
+ if(email == null || email.isEmpty() || email.equals("null"))
+ {
+ problem = "null or empty email!";
+ }
+ }
+ }
+ }
+ }
+ if(problem != null)
+ {
+ %>
+ <!-- Forwarding problem -->
+ <form name="dummy2">
+ <input type="hidden" name="problem" value="<%out.print(problem);%>"
+ >
+ </form>
+ <jsp:forward page="register.jsp"></jsp:forward>
+ <%
+ }
+ if(userDAO.add(userName, password, email) == null)
+ {
+ %>
+ <script type="text/javascript">
+ alert("Problem registering user! Please try again");
+ </script>
+ <input type="hidden" name="problem" value="<% out.print(problem);%>"
+ >
+ <jsp:forward page="register.jsp"></jsp:forward>
+ <%
+
+ }
+ else
+ {
+ %>
+ <p>
+ Congratulations <%out.print(userName);%>. You have been successfully registered.
+ </p>
+ <form action="index.jsp" method="post">
+ <input type="submit" value="Back to main">
+ </form>
+ <!-- Forwarding user name -->
+ <form name="dummy">
+ <input type="hidden" name="user"
+ value="<%out.print(userName); %>"
+ >
+ </form>
+
+ <%
+
+ }
+
+%>
+</body>
+</html>
\ No newline at end of file
Modified: JSP/trunk/Forum/WebContent/index.jsp
===================================================================
--- JSP/trunk/Forum/WebContent/index.jsp 2010-05-17 18:07:33 UTC (rev 151)
+++ JSP/trunk/Forum/WebContent/index.jsp 2010-05-18 08:38:40 UTC (rev 152)
@@ -11,32 +11,127 @@
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Team Bubulina's Forum</title>
<style type="text/css">
-table,th,td {
- border: 1px solid blue;
+
+table{
+ border: 10px solid blue;
border-collapse: collapse;
+ align: center;
+ width: 80%
}
+th{
+ align: center;
+}
+td{
+ border: 3px solid blue;
+ border-collapse: collapse;
+ height: 40px;
+}
+
a:link {
- color: green;
- background: red
+ color: green;
}
h1 {
font-weight: bold;
text-align: center;
}
+
+#leftContent {
+ float: left;
+ padding: 10px;
+ width: 300px; /* ie5win fudge begins */
+ voice-family: "\"}\"";
+ voice-family:inherit;
+ width: 270px;
+ }
+html>body #leftContent {
+ width: 270px; /* ie5win fudge ends */
+ }
+#rigthContent {
+ float: left;
+ padding: 10px;
+ width: 300px; /* ie5win fudge begins */
+ voice-family: "\"}\"";
+ voice-family:inherit;
+ width: 270px;
+ }
+html>body #rigthContent {
+ width: 270px; /* ie5win fudge ends */
+ }
</style>
</head>
<body>
+
+<%
+ //This form is to be dispayed only if the user is logged in
+ String user = request.getParameter("user");
+ if(user != null && !user.equalsIgnoreCase("null"))
+ {
+%>
+ <!-- The form for adding a new Thread -->
+ <div id="leftContent" align="right">
+ <FORM NAME="AddThread" action="index.jsp" method="get">
+ Thread name: <INPUT TYPE="TEXT" NAME="ThreadName" value="">
+ <INPUT TYPE="submit" VALUE="Add Thread">
+ </FORM>
+ </div>
+
+<%
+ //If the user has logged in
+ %>
+ <p> Hello <%out.print(user); %>!</p>
+ <%
+ }
+ else
+ {
+ %>
+
+ <div id="#rigthContent" align="right" >
+ <form name="LoginForm" action="login.jsp" method="post">
+ User name: <input type="text" name="username"><br>
+ Password: <input type="password" name="password"><br>
+ <input type="submit" value="login">
+ <%
+ //Handling posible login problems
+ String problem = request.getParameter("problem");
+ if(problem != null && (problem.isEmpty() == false)
+ && (problem.equals("null")) == false)
+ {
+ %>
+ <font color="red" size="14">
+ There is the following problem: <%out.println(problem); %>
+ </font>
+ <%
+ }
+ %>
+ </form>
+ <form action="register.jsp" action=post>
+ <input type="submit" value="register">
+ </form>
+ </div>
+<% }
+%>
+
+<!-- The actual table with threads -->
+
<div>
-<table>
- <caption align="top">The threads running on this forum are:</caption>
+<table align = center>
+ <caption align="top">The threads running on this forum are:<br></caption>
<tr>
<th>Thread name</th>
<th>Topic count</th>
</tr>
<%
ForumThreadDAO threads = Singleton.getInstance().getThreadDAO();
+
+ //Checking for a thread that was added in the previous page
+ String threadName = request.getParameter("ThreadName");
+ if(threadName != null && !threadName.equals(""))
+ {
+ threads.add(threadName);
+ }
+
for (ForumThread thread : threads.getAllThreads()) {
%>
<tr>
@@ -58,6 +153,13 @@
%>
</table>
</div>
+
+<!-- Forwarding user name -->
+<form name="dummy">
+<input type="hidden" name="user"
+ value="<%request.getParameter("user"); %>"
+ >
+</form>
<p>
</p>
</body>
Added: JSP/trunk/Forum/WebContent/login.jsp
===================================================================
--- JSP/trunk/Forum/WebContent/login.jsp (rev 0)
+++ JSP/trunk/Forum/WebContent/login.jsp 2010-05-18 08:38:40 UTC (rev 152)
@@ -0,0 +1,75 @@
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+ pageEncoding="ISO-8859-1"%>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+
+<%@page import="prc.bubulina.forum.data_access.UserDAO"%>
+<%@page import="prc.bubulina.forum.businessLogic.Singleton"%>
+<%@page import="prc.bubulina.forum.dataclasses.*"%>
+
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+<title>Insert title here</title>
+</head>
+<body>
+ <%
+ //checking the validity of the fields
+ UserDAO userDAO = Singleton.getInstance().getUserDAO();
+ String userName = request.getParameter("username");
+ String password = request.getParameter("password");
+ String problem = null;
+ User userToLoggin = null;
+ if(userName == null || userName.isEmpty() || userName.equals("null"))
+ {
+ problem = "Wrong userName!";
+ }
+ else
+ {
+ if(password == null || password.isEmpty() || password.equals("null"))
+ {
+ problem = "null or empty password!";
+ }
+ else
+ {
+ userToLoggin = userDAO.get(userName);
+ if(userToLoggin == null ||
+ userToLoggin.password.equals(password) == false)
+ {
+ problem = "Wrong username or password!";
+ }
+ }
+ }
+ if(problem != null)
+ {
+ %>
+ <!-- Forwarding problem -->
+ <form name="dummy2">
+ <input type="hidden" name="problem" value="<%out.print(problem);%>"
+ >
+ </form>
+ <jsp:forward page="index.jsp"></jsp:forward>
+ <%
+ }
+ else
+ {
+ //All OK
+ %>
+ <p>
+ Congratulations <%out.print(userName);%>. You have been successfully logged in.
+ </p>
+ <form action="index.jsp" method="post">
+ <input type="submit" value="Back to main">
+ </form>
+ <!-- Forwarding user name -->
+ <form name="dummy">
+ <input type="hidden" name="user"
+ value="<%request.getParameter("username");%>"
+ >
+ </form>
+
+ <%
+ }
+%>
+
+</body>
+</html>
\ No newline at end of file
Added: JSP/trunk/Forum/WebContent/register.jsp
===================================================================
--- JSP/trunk/Forum/WebContent/register.jsp (rev 0)
+++ JSP/trunk/Forum/WebContent/register.jsp 2010-05-18 08:38:40 UTC (rev 152)
@@ -0,0 +1,76 @@
+<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
+ pageEncoding="ISO-8859-1"%>
+<!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=ISO-8859-1">
+<title>Register</title>
+
+<style type="text/css">
+
+
+td
+{
+
+}
+</style>
+
+
+</head>
+<body>
+ <%
+ String problem = request.getParameter("problem");
+ if(problem != null && (problem.isEmpty() == false)
+ && (problem.equals("null")) == false)
+ {
+ %>
+ <font color="red" size="14">
+ There is the following problem: <%out.println(problem); %>
+ </font>
+ <%
+ }
+ %>
+ <form name="register" action="commitRegister.jsp" method="post">
+ <table align="center" width="80%">
+ <tr>
+ <td align="right">
+ User name:
+ </td>
+ <td>
+ <input type="text" value="" name="userName">
+ </td>
+ </tr>
+ <tr>
+ <td align="right">
+ password:
+ </td>
+ <td>
+ <input type="password" value="" name="password">
+ </td>
+ </tr>
+ <tr>
+ <td align="right">
+ Retype Password:
+ </td>
+ <td>
+ <input type="password" value="" name="checkPassword">
+ </td>
+ </tr>
+ <tr>
+ <td align="right">
+ Email:
+ </td>
+ <td>
+ <input type="text" value="" name="email">
+ </td>
+ </tr>
+ <tr>
+ <td></td>
+ <td>
+ <input type="submit" value="Submit" name="submit">
+ </td>
+ </tr>
+ </table>
+ </form>
+</body>
+</html>
\ No newline at end of file
Modified: JSP/trunk/Forum/src/prc/bubulina/forum/businessLogic/Singleton.java
===================================================================
--- JSP/trunk/Forum/src/prc/bubulina/forum/businessLogic/Singleton.java 2010-05-17 18:07:33 UTC (rev 151)
+++ JSP/trunk/Forum/src/prc/bubulina/forum/businessLogic/Singleton.java 2010-05-18 08:38:40 UTC (rev 152)
@@ -2,15 +2,18 @@
import prc.bubulina.forum.data_access.ForumDAOFactory;
import prc.bubulina.forum.data_access.ForumThreadDAO;
+import prc.bubulina.forum.data_access.UserDAO;
public class Singleton
{
private ForumThreadDAO threadDAO;
+ private UserDAO users;
private static Singleton instance = null;
private Singleton()
{
threadDAO = ForumDAOFactory.getThreadDAO();
+ users = ForumDAOFactory.getUserDAO();
}
public static Singleton getInstance()
@@ -27,5 +30,9 @@
{
return threadDAO;
}
-
+
+ public UserDAO getUserDAO()
+ {
+ return users;
+ }
}
Modified: JSP/trunk/Forum/src/prc/bubulina/forum/data_access/ForumDAOFactory.java
===================================================================
--- JSP/trunk/Forum/src/prc/bubulina/forum/data_access/ForumDAOFactory.java 2010-05-17 18:07:33 UTC (rev 151)
+++ JSP/trunk/Forum/src/prc/bubulina/forum/data_access/ForumDAOFactory.java 2010-05-18 08:38:40 UTC (rev 152)
@@ -2,14 +2,13 @@
import java.sql.Connection;
import java.sql.DriverManager;
-import java.sql.SQLException;
public class ForumDAOFactory {
public static final String DRIVER = "com.mysql.jdbc.Driver";
public static final String DBURL = "jdbc:mysql://localhost:3306/forum";
public static Connection createConnection() {
- try {
+ try {
Class.forName(DRIVER);
return DriverManager.getConnection(DBURL, "horia", "barcelona");
} catch (Exception e) {
Modified: JSP/trunk/Forum/src/prc/bubulina/forum/data_access/ForumThreadDAO.java
===================================================================
--- JSP/trunk/Forum/src/prc/bubulina/forum/data_access/ForumThreadDAO.java 2010-05-17 18:07:33 UTC (rev 151)
+++ JSP/trunk/Forum/src/prc/bubulina/forum/data_access/ForumThreadDAO.java 2010-05-18 08:38:40 UTC (rev 152)
@@ -45,7 +45,6 @@
}
return null;
}
-
public ForumThread add(String name) {
try {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|