Beispiel #1
0
 @Override
 public User retrieveUser(User user) {
   final String SQL = "SELECT * FROM users WHERE username = ?";
   PreparedStatement preparedStatement = PreparedStatementCreator.createPreparedStatement(SQL);
   ResultSet resultSet = null;
   try {
     preparedStatement.setString(1, user.getUsername());
     resultSet = preparedStatement.executeQuery();
     rowAffected = resultSet.getFetchSize();
     System.out.println("Row: " + rowAffected);
   } catch (SQLException e) {
     e.printStackTrace();
   }
   User retrievedUser = null;
   try {
     while (resultSet.next()) {
       retrievedUser = new User();
       retrievedUser.setFirstName(resultSet.getString("first_name"));
       retrievedUser.setLastName(resultSet.getString("last_name"));
       retrievedUser.setUsername(resultSet.getString("username"));
       retrievedUser.setEmail(resultSet.getString("email"));
       retrievedUser.setPassword(resultSet.getString("password"));
       retrievedUser.setType(resultSet.getString("user_type"));
     }
   } catch (SQLException e) {
     e.printStackTrace();
   }
   return retrievedUser;
 }
Beispiel #2
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String firstname = request.getParameter("firstname");
    String lastname = request.getParameter("lastname");
    String email = request.getParameter("email");
    String username = request.getParameter("username");
    String password1 = request.getParameter("password");
    String password2 = request.getParameter("password1");
    String gender = request.getParameter("gender");
    String address = request.getParameter("address");
    String contact = request.getParameter("contact");
    String superPassword = request.getParameter("superPassword");

    User user = new User();
    UserService service = new UserService(user);
    MySQLUserDao userDao = new MySQLUserDao();

    //		if(!service.isUsernameAvailable()){
    //			response.sendRedirect("Error.jsp");
    //			return;
    //		}
    //
    //		else if(!service.isPasswordMatch(password1, password2)){
    //			response.sendRedirect("Error.jsp");
    //			return;
    //		}
    //

    user.setFirstName(firstname);
    user.setLastName(lastname);
    user.setUsername(username);
    user.setEmail(email);
    user.setPassword(password1);
    user.setAddress(address);
    user.setContactNumber(contact);
    user.setType("admin");

    int status = userDao.createUser(user);
    if (status > 0) {
      RequestDispatcher rd = request.getRequestDispatcher("AdminLogin");
      rd.forward(request, response);
    } else {
      RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
      request.setAttribute("error", true);
      rd.forward(request, response);
    }
  }