Java Code Examples for com.in28minutes.domain.User

The following examples show how to use com.in28minutes.domain.User. These examples are extracted from open source projects. 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 Project: MavenIn28Minutes   Source File: ListTodoServlet.java    License: MIT License 6 votes vote down vote up
@Override
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	HttpSession session = request.getSession();
	User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);
	TodoItemList todoList = todoService.getTodoListByUser(user.getId());

	// todo list is request scoped to avoid storing and synchronizing it in
	// session for each CRUD operation
	request.setAttribute("todoList", todoList.getItems());
	request.setAttribute("homeTabStyle", "active");

	request.setAttribute("totalCount", todoList.getCount());
	request.setAttribute("doneCount", todoList.getDoneCount());
	request.setAttribute("todoCount", todoList.getTodoCount());

	request.getRequestDispatcher(HOME_PAGE).forward(request, response);
}
 
Example 2
@Override
protected void doGet(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	HttpSession session = request.getSession();
	User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);
	TodoItemList todoList = todoService.getTodoListByUser(user.getId());

	// todo list is request scoped to avoid storing and synchronizing it in
	// session for each CRUD operation
	request.setAttribute("todoList", todoList.getItems());
	request.setAttribute("homeTabStyle", "active");

	request.setAttribute("totalCount", todoList.getCount());
	request.setAttribute("doneCount", todoList.getDoneCount());
	request.setAttribute("todoCount", todoList.getTodoCount());

	request.getRequestDispatcher(HOME_PAGE).forward(request, response);
}
 
Example 3
Source Project: MavenIn28Minutes   Source File: LoginServlet.java    License: 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 4
Source Project: MavenIn28Minutes   Source File: SessionCheckFilter.java    License: MIT License 5 votes vote down vote up
public void doFilter(ServletRequest request, ServletResponse response,
		FilterChain chain) throws ServletException, IOException {

	HttpServletRequest req = (HttpServletRequest) request;
	HttpSession session = req.getSession();

	User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);

	if (user != null) {
		chain.doFilter(request, response);
	} else {
		request.getRequestDispatcher(LOGIN_PAGE).forward(request, response);
	}

}
 
Example 5
Source Project: MavenIn28Minutes   Source File: UserDataServiceImpl.java    License: MIT License 5 votes vote down vote up
public void remove(final User user) {
	entityManager.createNativeQuery(
			"DELETE FROM todo t WHERE t.userId = " + user.getId())
			.executeUpdate();
	User u = entityManager.find(User.class, user.getId());
	entityManager.remove(u);
}
 
Example 6
Source Project: MavenIn28Minutes   Source File: UserDataServiceImpl.java    License: MIT License 5 votes vote down vote up
public User getUserByEmail(final String email) {
	TypedQuery<User> query = entityManager.createNamedQuery(
			"findUserByEmail", User.class);
	query.setParameter("p_email", email);
	List<User> users = query.getResultList();
	return (users != null && !users.isEmpty()) ? users.get(0) : null;
}
 
Example 7
Source Project: MavenIn28Minutes   Source File: UserDataServiceImpl.java    License: MIT License 5 votes vote down vote up
public boolean login(final String email, final String password) {
	TypedQuery<User> query = entityManager.createNamedQuery(
			"findUserByEmailAndPassword", User.class);
	query.setParameter("p_email", email);
	query.setParameter("p_password", password);
	List<User> users = query.getResultList();
	return (users != null && !users.isEmpty());
}
 
Example 8
Source Project: SpringIn28Minutes   Source File: TodoController.java    License: MIT License 5 votes vote down vote up
@RequestMapping(value = "/user/todos/new", method = RequestMethod.POST)
public String createNewTodo(@ModelAttribute TodoItem todoItem) {
	final User user = sessionData.getUser();
	todoItem.setDone(false);
	todoItem.setUserId(user.getId());
	todoService.create(todoItem);
	return REDIRECT_TO_VIEW_TODOS_CONTROLLER;
}
 
Example 9
Source Project: SpringIn28Minutes   Source File: UserDataServiceImpl.java    License: MIT License 5 votes vote down vote up
@Override
public void remove(final User user) {
	entityManager.createNativeQuery(
			"DELETE FROM todo t WHERE t.userId = " + user.getId())
			.executeUpdate();
	User u = entityManager.find(User.class, user.getId());
	entityManager.remove(u);
}
 
Example 10
Source Project: SpringIn28Minutes   Source File: UserDataServiceImpl.java    License: MIT License 5 votes vote down vote up
@Override
public User getUserByEmail(final String email) {
	TypedQuery<User> query = entityManager.createNamedQuery(
			"findUserByEmail", User.class);
	query.setParameter("p_email", email);
	List<User> users = query.getResultList();
	return users != null && !users.isEmpty() ? users.get(0) : null;
}
 
Example 11
Source Project: SpringIn28Minutes   Source File: UserDataServiceImpl.java    License: MIT License 5 votes vote down vote up
@Override
public boolean login(final String email, final String password) {
	TypedQuery<User> query = entityManager.createNamedQuery(
			"findUserByEmailAndPassword", User.class);
	query.setParameter("p_email", email);
	query.setParameter("p_password", password);
	List<User> users = query.getResultList();
	return users != null && !users.isEmpty();
}
 
Example 12
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 13
public void doFilter(ServletRequest request, ServletResponse response,
		FilterChain chain) throws ServletException, IOException {

	HttpServletRequest req = (HttpServletRequest) request;
	HttpSession session = req.getSession();

	User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);

	if (user != null) {
		chain.doFilter(request, response);
	} else {
		request.getRequestDispatcher(LOGIN_PAGE).forward(request, response);
	}

}
 
Example 14
public void remove(final User user) {
	entityManager.createNativeQuery(
			"DELETE FROM todo t WHERE t.userId = " + user.getId())
			.executeUpdate();
	User u = entityManager.find(User.class, user.getId());
	entityManager.remove(u);
}
 
Example 15
public User getUserByEmail(final String email) {
	TypedQuery<User> query = entityManager.createNamedQuery(
			"findUserByEmail", User.class);
	query.setParameter("p_email", email);
	List<User> users = query.getResultList();
	return (users != null && !users.isEmpty()) ? users.get(0) : null;
}
 
Example 16
public boolean login(final String email, final String password) {
	TypedQuery<User> query = entityManager.createNamedQuery(
			"findUserByEmailAndPassword", User.class);
	query.setParameter("p_email", email);
	query.setParameter("p_password", password);
	List<User> users = query.getResultList();
	return (users != null && !users.isEmpty());
}
 
Example 17
Source Project: MavenIn28Minutes   Source File: CreateTodoServlet.java    License: MIT License 4 votes vote down vote up
@Override
protected void doPost(HttpServletRequest request,
		HttpServletResponse response) throws ServletException, IOException {

	HttpSession session = request.getSession();
	User user = (User) session.getAttribute(TodoListUtils.SESSION_USER);

	String title = request.getParameter("title");
	String dueDate = request.getParameter("dueDate");
	String priority = request.getParameter("priority");

	TodoItem todoItem = new TodoItem(user.getId(), title, false,
			Priority.valueOf(priority), new Date(dueDate));

	todoService.create(todoItem);

	request.getRequestDispatcher("/todos").forward(request, response);

}
 
Example 18
Source Project: MavenIn28Minutes   Source File: UserDataServiceImpl.java    License: MIT License 4 votes vote down vote up
public User create(final User user) {
	entityManager.persist(user);
	return user;
}
 
Example 19
Source Project: MavenIn28Minutes   Source File: UserDataServiceImpl.java    License: MIT License 4 votes vote down vote up
public User update(User user) {
	return entityManager.merge(user);
}
 
Example 20
Source Project: MavenIn28Minutes   Source File: UserServiceImpl.java    License: MIT License 4 votes vote down vote up
public User create(final User user) {
	return userDataService.create(user);
}
 
Example 21
Source Project: MavenIn28Minutes   Source File: UserServiceImpl.java    License: MIT License 4 votes vote down vote up
public User update(User user) {
	return userDataService.update(user);
}
 
Example 22
Source Project: MavenIn28Minutes   Source File: UserServiceImpl.java    License: MIT License 4 votes vote down vote up
public void remove(final User user) {
	userDataService.remove(user);
}
 
Example 23
Source Project: MavenIn28Minutes   Source File: UserServiceImpl.java    License: MIT License 4 votes vote down vote up
@Transactional(readOnly = true)
public User getUserByEmail(final String email) {
	return userDataService.getUserByEmail(email);
}
 
Example 24
Source Project: SpringIn28Minutes   Source File: SessionData.java    License: MIT License 4 votes vote down vote up
public User getUser() {
	return user;
}
 
Example 25
Source Project: SpringIn28Minutes   Source File: SessionData.java    License: MIT License 4 votes vote down vote up
public void setUser(User user) {
	this.user = user;
}
 
Example 26
Source Project: SpringIn28Minutes   Source File: UserDataServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
public User create(final User user) {
	entityManager.persist(user);
	return user;
}
 
Example 27
Source Project: SpringIn28Minutes   Source File: UserDataServiceImpl.java    License: MIT License 4 votes vote down vote up
@Override
public User update(User user) {
	return entityManager.merge(user);
}
 
Example 28
Source Project: SpringIn28Minutes   Source File: UserServiceImpl.java    License: MIT License 4 votes vote down vote up
public User create(final User user) {
	return userDataService.create(user);
}
 
Example 29
Source Project: SpringIn28Minutes   Source File: UserServiceImpl.java    License: MIT License 4 votes vote down vote up
public User update(User user) {
	return userDataService.update(user);
}
 
Example 30
Source Project: SpringIn28Minutes   Source File: UserServiceImpl.java    License: MIT License 4 votes vote down vote up
public void remove(final User user) {
	userDataService.remove(user);
}