Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. @Column(name = "description")
  2. private String description;
  3.  
  4. private String description;
  5.  
  6. public class UserExtra implements Serializable {
  7.  
  8. private static final long serialVersionUID = 1L;
  9.  
  10. @Id
  11. private Long id;
  12.  
  13. @Column(name = "phone")
  14. private String phone;
  15.  
  16. @OneToOne
  17. @MapsId
  18. private User user;
  19. ...
  20.  
  21. }
  22.  
  23. <input class="form-control" id="phone" ng-model="vm.registerAccount.phone" placeholder="global.form.phone.placeholder" />
  24.  
  25. public class ManagedUserVM extends UserDTO {
  26.  
  27. // Default attributes omitted for brevity
  28.  
  29. private String phone;
  30.  
  31. ...
  32.  
  33. public String getPhone() {
  34. return phone;
  35. }
  36.  
  37. }
  38.  
  39. public ResponseEntity<?> registerAccount(@Valid @RequestBody ManagedUserVM managedUserVM) {
  40.  
  41. HttpHeaders textPlainHeaders = new HttpHeaders();
  42. textPlainHeaders.setContentType(MediaType.TEXT_PLAIN);
  43.  
  44. return userRepository.findOneByLogin(managedUserVM.getLogin().toLowerCase())
  45. .map(user -> new ResponseEntity<>("login already in use", textPlainHeaders, HttpStatus.BAD_REQUEST))
  46. .orElseGet(() -> userRepository.findOneByEmail(managedUserVM.getEmail())
  47. .map(user -> new ResponseEntity<>("e-mail address already in use", textPlainHeaders, HttpStatus.BAD_REQUEST))
  48. .orElseGet(() -> {
  49. User user = userService
  50. .createUser(managedUserVM.getLogin(), managedUserVM.getPassword(),
  51. managedUserVM.getFirstName(), managedUserVM.getLastName(),
  52. managedUserVM.getEmail().toLowerCase(), managedUserVM.getLangKey(),
  53. managedUserVM.getPhone());
  54.  
  55. mailService.sendActivationEmail(user);
  56. return new ResponseEntity<>(HttpStatus.CREATED);
  57. })
  58. );
  59. }
  60.  
  61. @Inject
  62. private UserExtraRepository userExtraRepository;
  63.  
  64. @Inject
  65. private UserExtraSearchRepository userExtraSearchRepository;
  66.  
  67. ...
  68.  
  69. public User createUser(String login, String password, String firstName, String lastName, String email,
  70. String langKey, String phone) {
  71.  
  72. User newUser = new User();
  73. Authority authority = authorityRepository.findOne(AuthoritiesConstants.USER);
  74. Set<Authority> authorities = new HashSet<>();
  75. String encryptedPassword = passwordEncoder.encode(password);
  76. newUser.setLogin(login);
  77. // new user gets initially a generated password
  78. newUser.setPassword(encryptedPassword);
  79. newUser.setFirstName(firstName);
  80. newUser.setLastName(lastName);
  81. newUser.setEmail(email);
  82. newUser.setLangKey(langKey);
  83. // new user is not active
  84. newUser.setActivated(false);
  85. // new user gets registration key
  86. newUser.setActivationKey(RandomUtil.generateActivationKey());
  87. authorities.add(authority);
  88. newUser.setAuthorities(authorities);
  89. userRepository.save(newUser);
  90. userSearchRepository.save(newUser);
  91. log.debug("Created Information for User: {}", newUser);
  92.  
  93. // Create and save the UserExtra entity
  94. UserExtra newUserExtra = new UserExtra();
  95. newUserExtra.setUser(newUser);
  96. newUserExtra.setPhone(phone);
  97. userExtraRepository.save(newUserExtra);
  98. userExtraSearchRepository.save(newUserExtra);
  99. log.debug("Created Information for UserExtra: {}", newUserExtra);
  100.  
  101. return newUser;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement