com.in28minutes.web.common.form.LoginForm Java Examples

The following examples show how to use com.in28minutes.web.common.form.LoginForm. 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 MavenIn28Minutes with MIT License 5 votes vote down vote up
private void validatePassword(HttpServletRequest request,
		LoginForm loginForm) {
	Set<ConstraintViolation<LoginForm>> constraintViolations = validator
			.validateProperty(loginForm, "password");
	if (!constraintViolations.isEmpty()) {
		request.setAttribute("errorPassword", constraintViolations
				.iterator().next().getMessage());
		addGlobalLoginErrorAttribute(request);
	}
}
 
Example #3
Source File: LoginServlet.java    From MavenIn28Minutes with MIT License 5 votes vote down vote up
private void validateEmail(HttpServletRequest request, LoginForm loginForm) {
	Set<ConstraintViolation<LoginForm>> constraintViolations = validator
			.validateProperty(loginForm, "email");
	if (!constraintViolations.isEmpty()) {
		request.setAttribute("errorEmail", constraintViolations.iterator()
				.next().getMessage());
		addGlobalLoginErrorAttribute(request);
	}
}
 
Example #4
Source File: LoginController.java    From SpringIn28Minutes with MIT License 5 votes vote down vote up
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView redirectToLoginPage() {

	if (sessionData.getUser() != null) {
		return new ModelAndView(REDIRECT_TO_VIEW_TODOS_CONTROLLER);
	}

	ModelAndView modelAndView = new ModelAndView(USER_LOGIN_PAGE);
	modelAndView.addObject("loginTabStyle", "active");
	modelAndView.addObject("loginForm", new LoginForm());
	return modelAndView;
}
 
Example #5
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);
}
 
Example #6
Source File: LoginServlet.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 5 votes vote down vote up
private void validatePassword(HttpServletRequest request,
		LoginForm loginForm) {
	Set<ConstraintViolation<LoginForm>> constraintViolations = validator
			.validateProperty(loginForm, "password");
	if (!constraintViolations.isEmpty()) {
		request.setAttribute("errorPassword", constraintViolations
				.iterator().next().getMessage());
		addGlobalLoginErrorAttribute(request);
	}
}
 
Example #7
Source File: LoginServlet.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 5 votes vote down vote up
private void validateEmail(HttpServletRequest request, LoginForm loginForm) {
	Set<ConstraintViolation<LoginForm>> constraintViolations = validator
			.validateProperty(loginForm, "email");
	if (!constraintViolations.isEmpty()) {
		request.setAttribute("errorEmail", constraintViolations.iterator()
				.next().getMessage());
		addGlobalLoginErrorAttribute(request);
	}
}
 
Example #8
Source File: LoginServlet.java    From MavenIn28Minutes with MIT License 4 votes vote down vote up
private void validateCredentials(HttpServletRequest request,
		LoginForm loginForm) {
	validateEmail(request, loginForm);

	validatePassword(request, loginForm);
}
 
Example #9
Source File: LoginController.java    From SpringIn28Minutes with MIT License 4 votes vote down vote up
private boolean isValidUser(LoginForm loginForm) {
	return userService.isValidUser(loginForm.getEmail(),
			loginForm.getPassword());
}
 
Example #10
Source File: LoginServlet.java    From RealWorldWebApplicationWithServletsAndJspIn28Minutes with MIT License 4 votes vote down vote up
private void validateCredentials(HttpServletRequest request,
		LoginForm loginForm) {
	validateEmail(request, loginForm);

	validatePassword(request, loginForm);
}