01: package forum;
02:
03: import java.io.*;
04: import javax.servlet.*;
05: import javax.servlet.http.*;
06: import java.sql.*;
07: import java.sql.Connection;
08: import java.sql.Statement;
09: import java.sql.ResultSet;
10:
11: public class AddUser extends HttpServlet {
12:
13: DBConnectie db = new DBConnectie(Variable.getDb(), Variable
14: .getDbLogin(), Variable.getDbPassword());
15:
16: public void doPost(HttpServletRequest request,
17: HttpServletResponse response) throws ServletException,
18: IOException {
19: PrintWriter out = response.getWriter();
20: try {
21: //Cookie[] cookies = request.getCookies();
22: //String username = Cookies.getCookies(cookies,"username","null");
23: //String password = Cookies.getCookies(cookies,"password","null");
24: //String type = Cookies.getCookies(cookies,"type","null");
25:
26: String RegUser = request.getParameter("user");
27: String RegEmail = request.getParameter("email");
28: String RegPass = request.getParameter("password");
29: String RegPass2 = request.getParameter("password2");
30:
31: db.connect();
32: ResultSet rs = db.selectQuery("SELECT * "
33: + "FROM forum_users " + "WHERE user_name=\""
34: + RegUser + "\"");
35:
36: String DBUsername = null;
37: while (rs.next()) {
38: DBUsername = rs.getString("user_name");
39: }
40:
41: if (DBUsername == null) {
42:
43: if (RegPass.equals(RegPass2)) {
44:
45: db
46: .query("INSERT INTO "
47: + "forum_users(user_name,password,email,registerdate,type) "
48: + "VALUES(\"" + RegUser
49: + "\",password(\"" + RegPass
50: + "\"),\"" + RegEmail
51: + "\",\"SYSDATE()\",\"user\")");
52: db.close();
53: response.sendRedirect(Variable.getForumPath()
54: + "info.jsp?action=regcomplete");
55: } else {
56: response.sendRedirect(Variable.getForumPath()
57: + "info.jsp?action=wrongpass");
58: }
59: } else {
60: response.sendRedirect(Variable.getForumPath()
61: + "info.jsp?action=userexists");
62: }
63: } catch (Exception e) {
64: out.println(e);
65: }
66:
67: }
68:
69: public void doGet(HttpServletRequest request,
70: HttpServletResponse response) throws ServletException,
71: IOException {
72: doPost(request, response);
73: }
74:
75: }
|