Java Code Examples for com.in28minutes.web.common.form.LoginForm#setPassword()

The following examples show how to use com.in28minutes.web.common.form.LoginForm#setPassword() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoginServlet.java    From MavenIn28Minutes with MIT License 5 votes vote down vote up
protected void doPost(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	String email = request.getParameter("email");
	String password = request.getParameter("password");

	LoginForm loginForm = new LoginForm();
	loginForm.setEmail(email);
	loginForm.setPassword(password);

	validateCredentials(request, loginForm);

	if (isInvalid(request)) {
		request.getRequestDispatcher(LOGIN_PAGE).forward(request, response);
		return;
	}

	if (isValidUser(email, password)) {
		request.setAttribute("error",
				resourceBundle.getString("login.form.invalid.credentials"));
		request.getRequestDispatcher(LOGIN_PAGE).forward(request, response);
		return;
	}

	HttpSession session = request.getSession(true);// create session
	User user = userService.getUserByEmail(email);
	session.setAttribute(TodoListUtils.SESSION_USER, user);
	request.getRequestDispatcher(REDIRECT_HOME_PAGE).forward(request,
			response);
}
 
Example 2
Source File: LoginServlet.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 5 votes vote down vote up
protected void doPost(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	String email = request.getParameter("email");
	String password = request.getParameter("password");

	LoginForm loginForm = new LoginForm();
	loginForm.setEmail(email);
	loginForm.setPassword(password);

	validateCredentials(request, loginForm);

	if (isInvalid(request)) {
		request.getRequestDispatcher(LOGIN_PAGE).forward(request, response);
		return;
	}

	if (isValidUser(email, password)) {
		request.setAttribute("error",
				resourceBundle.getString("login.form.invalid.credentials"));
		request.getRequestDispatcher(LOGIN_PAGE).forward(request, response);
		return;
	}

	HttpSession session = request.getSession(true);// create session
	User user = userService.getUserByEmail(email);
	session.setAttribute(TodoListUtils.SESSION_USER, user);
	request.getRequestDispatcher(REDIRECT_HOME_PAGE).forward(request,
			response);
}