RegisterConfirmController.java 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* ===================================================================
  2. * RegisterConfirmController.java
  3. *
  4. * Created Oct 5, 2004 8:45:27 PM
  5. *
  6. * Copyright (c) 2004 Matt Magoffin (spamsqr@msqr.us)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  21. * 02111-1307 USA
  22. * ===================================================================
  23. * $Id: RegisterConfirmController.java 28 2009-05-04 01:19:45Z msqr $
  24. * ===================================================================
  25. */
  26. package magoffin.matt.ieat.web;
  27. import javax.servlet.http.HttpServletRequest;
  28. import javax.servlet.http.HttpServletResponse;
  29. import magoffin.matt.ieat.AuthorizationException;
  30. import magoffin.matt.ieat.biz.BizContext;
  31. import magoffin.matt.ieat.domain.User;
  32. import magoffin.matt.ieat.util.LogonCommand;
  33. import org.springframework.validation.BindException;
  34. import org.springframework.web.servlet.ModelAndView;
  35. /**
  36. * Controller for handing the registration confirmation request.
  37. *
  38. * @author Matt Magoffin (spamsqr@msqr.us)
  39. * @version $Revision: 28 $ $Date: 2009-05-04 13:19:45 +1200 (Mon, 04 May 2009) $
  40. */
  41. public class RegisterConfirmController extends AbstractEatCommandController {
  42. @Override
  43. protected ModelAndView handle(HttpServletRequest request,
  44. HttpServletResponse response, Object command, BindException errors)
  45. throws Exception {
  46. LogonCommand logonCommand = (LogonCommand)command;
  47. BizContext context = WebUtil.getBizContext(request, false);
  48. User user = null;
  49. try {
  50. user = userBiz.confirmRegisteredUser(logonCommand.getLogin(),logonCommand.getCode(), context);
  51. } catch ( AuthorizationException e ) {
  52. switch ( e.getReason() ) {
  53. case AuthorizationException.REGISTRATION_ALREADY_CONFIRMED:
  54. errors.reject("error.already.confirmed.registration","Registration already confirmed.");
  55. break;
  56. default:
  57. errors.reject("error.not.confirmed.registration", "Unable to confirm registration.");
  58. break;
  59. }
  60. return new ModelAndView(getErrorView(),errors.getModel());
  61. }
  62. // log the user in
  63. WebUtil.saveUserSessionData(request,getDomainObjectFactory(),user);
  64. return new ModelAndView(getSuccessView(),errors.getModel());
  65. }
  66. }