/src/main/java/com/tmo/storefront/web/controller/RegistrationController.java

https://bitbucket.org/gazaay/storefront · Java · 83 lines · 54 code · 15 blank · 14 comment · 0 complexity · c7520c1935b31c3af9260a44d5d24c52 MD5 · raw file

  1. package com.tmo.storefront.web.controller;
  2. import java.util.List;
  3. import javax.servlet.http.HttpServletRequest;
  4. import org.apache.log4j.Logger;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.security.core.userdetails.UserDetailsService;
  7. import org.springframework.stereotype.Controller;
  8. import org.springframework.ui.Model;
  9. import org.springframework.web.bind.annotation.ModelAttribute;
  10. import org.springframework.web.bind.annotation.PathVariable;
  11. import org.springframework.web.bind.annotation.RequestBody;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestMethod;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.ResponseBody;
  16. import com.tmo.storefront.domain.InventoryAttribute;
  17. import com.tmo.storefront.domain.Message;
  18. import com.tmo.storefront.domain.Users;
  19. import com.tmo.storefront.web.services.InventoryService;
  20. import com.tmo.storefront.web.services.RegistrationService;
  21. import com.tmo.storefront.web.services.SecurityService;
  22. @Controller
  23. public class RegistrationController extends BaseController {
  24. Logger logger = Logger.getLogger(RegistrationController.class);
  25. @Autowired
  26. private RegistrationService service;
  27. @Autowired
  28. private SecurityService securityService;
  29. @Autowired
  30. RegistrationService registration_service;
  31. // @RequestMapping(value="/signup2", method = RequestMethod.POST)
  32. // public @ResponseBody Message signUpNewUser(@ModelAttribute("userProfile") UserProfile profile) throws Exception {
  33. // logger.info("User Profile Name" + profile.getFirstname());
  34. // logger.info("User Profile country" + profile.getCountry());
  35. // logger.info("User Profile email" + profile.getEmail());
  36. // logger.info("User Profile lastname" + profile.getLastname());
  37. // logger.info("User Profile phone" + profile.getPhone());
  38. // logger.info("User Profile salutation" + profile.getSalutation());
  39. // Message message = new Message();
  40. // message.setDescription("Testing message only");
  41. // message.setValid(true);
  42. // return message;
  43. // }
  44. @RequestMapping(value="/validate/{input}/{value}", method = RequestMethod.GET)
  45. public @ResponseBody boolean validateOnRegistration(@PathVariable String input, @PathVariable String value) throws Exception {
  46. String type = "";
  47. return true;
  48. }
  49. @RequestMapping(value = "/signup", method = RequestMethod.POST)
  50. @ResponseBody
  51. public Message registerUser(@RequestBody Users user, Model model,
  52. HttpServletRequest request) throws Exception {
  53. // TODO: configure it by database later
  54. Message msg = new Message();
  55. try {
  56. securityService.saveUser(user);
  57. super.doAutoLogin(user.getUsername(), user.getPassword(), request);
  58. logger.info("User Signup and login automatically for first time. user:" + user.getUsername());
  59. registration_service.sendWelcomeRegistrationEmail(user.getUsername());
  60. } catch (Exception ex) {
  61. logger.error(ex.getMessage());
  62. msg.setDescription("Error occur while saving user. Please contact us for more information.");
  63. return msg;
  64. }
  65. msg.setDescription("Registration successfully done !");
  66. return msg;
  67. }
  68. }