Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Accounting and Billing Portal
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[abportal] View of /src/main/java/eu/smartlm/abs/portal/security/login/admin/AddUserController.java
[abportal] / src / main / java / eu / smartlm / abs / portal / security / login / admin / AddUserController.java Repository:
ViewVC logotype

View of /src/main/java/eu/smartlm/abs/portal/security/login/admin/AddUserController.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (download) (annotate)
Wed Jul 28 10:05:51 2010 UTC (13 years, 9 months ago) by dgarcia
File size: 3340 byte(s)
First code commit
package eu.smartlm.abs.portal.security.login.admin;

import javax.portlet.ActionResponse;
import javax.portlet.RenderResponse;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.portlet.bind.annotation.ActionMapping;
import org.springframework.web.portlet.bind.annotation.RenderMapping;

import eu.smartlm.abs.portal.security.login.model.User;
import eu.smartlm.abs.portal.security.login.service.LoginService;

/**
 * Adds a User to the User Database to grant limited access to the acounting and billing data
 * @author David García Pérez - CESGA
 */
@Controller(value="addUserController")
@RequestMapping(value = "VIEW")
@SessionAttributes(types = User.class)
public class AddUserController {
	private User user;
	
	@Autowired
	@Qualifier("myLoginService")
	private LoginService loginService;

	
	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}
	
	@RenderMapping(params = "myaction=addUserForm")
	public String showAddUserForm(RenderResponse response) {
		return "addUserForm";
	}
	
	/**
	 * User object that it is created to be passed to the jsp page
	 * @return a User Object
	 */
	@ModelAttribute("user")
	public User getUser() {
		if (user == null) return new User();
		return user;
	}
	
	/**
	 * Initicialices the binder that associates fields of the jsp page to the user model
	 * @param binder
	 */
	@InitBinder("user")
	public void initBinder(WebDataBinder binder) { }
	
	/**
	 * Adds the user to the database
	 * @param user
	 * @param bindingResult
	 * @param response
	 * @param sessionStatus
	 */
	@ActionMapping(params = "myaction=addUser")
	public void addBook(@Valid @ModelAttribute User user, BindingResult bindingResult, ActionResponse response, SessionStatus sessionStatus) {
		
		//myValidator.validate(user, bindingResult);
		if (!bindingResult.hasErrors()) {
			int message = loginService.addUser(user);
			
			if(message == LoginService.USER_SUCCESSFULLY_ADDED)
				response.setRenderParameter("myaction", "users");
			else if (message == LoginService.USER_ALREADY_EXISTS)
				response.setRenderParameter("myaction", "addUserForm");
			else if (message == LoginService.WRONG_PASSWORD)
				response.setRenderParameter("myaction", "addUserForm");
			else if (message == LoginService.WRONG_USERNAME)
				response.setRenderParameter("myaction", "addUserForm");
		
			//--set the session status as complete to cleanup the model attributes
			//--stored using @SessionAttributes, otherwise when you click
			//--'Add Book' button you'll see the book information pre-populated
			//-- because the getCommandObject method of the controller is not
			//--invoked
			sessionStatus.setComplete();
		} else {
			response.setRenderParameter("myaction", "addUserForm");
		}
	}
}

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge