Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Column(name = "description")
- private String description;
- private String description;
- public class UserExtra implements Serializable {
- private static final long serialVersionUID = 1L;
- @Id
- private Long id;
- @Column(name = "phone")
- private String phone;
- @OneToOne
- @MapsId
- private User user;
- ...
- }
- <input class="form-control" id="phone" ng-model="vm.registerAccount.phone" placeholder="global.form.phone.placeholder" />
- public class ManagedUserVM extends UserDTO {
- // Default attributes omitted for brevity
- private String phone;
- ...
- public String getPhone() {
- return phone;
- }
- }
- public ResponseEntity<?> registerAccount(@Valid @RequestBody ManagedUserVM managedUserVM) {
- HttpHeaders textPlainHeaders = new HttpHeaders();
- textPlainHeaders.setContentType(MediaType.TEXT_PLAIN);
- return userRepository.findOneByLogin(managedUserVM.getLogin().toLowerCase())
- .map(user -> new ResponseEntity<>("login already in use", textPlainHeaders, HttpStatus.BAD_REQUEST))
- .orElseGet(() -> userRepository.findOneByEmail(managedUserVM.getEmail())
- .map(user -> new ResponseEntity<>("e-mail address already in use", textPlainHeaders, HttpStatus.BAD_REQUEST))
- .orElseGet(() -> {
- User user = userService
- .createUser(managedUserVM.getLogin(), managedUserVM.getPassword(),
- managedUserVM.getFirstName(), managedUserVM.getLastName(),
- managedUserVM.getEmail().toLowerCase(), managedUserVM.getLangKey(),
- managedUserVM.getPhone());
- mailService.sendActivationEmail(user);
- return new ResponseEntity<>(HttpStatus.CREATED);
- })
- );
- }
- @Inject
- private UserExtraRepository userExtraRepository;
- @Inject
- private UserExtraSearchRepository userExtraSearchRepository;
- ...
- public User createUser(String login, String password, String firstName, String lastName, String email,
- String langKey, String phone) {
- User newUser = new User();
- Authority authority = authorityRepository.findOne(AuthoritiesConstants.USER);
- Set<Authority> authorities = new HashSet<>();
- String encryptedPassword = passwordEncoder.encode(password);
- newUser.setLogin(login);
- // new user gets initially a generated password
- newUser.setPassword(encryptedPassword);
- newUser.setFirstName(firstName);
- newUser.setLastName(lastName);
- newUser.setEmail(email);
- newUser.setLangKey(langKey);
- // new user is not active
- newUser.setActivated(false);
- // new user gets registration key
- newUser.setActivationKey(RandomUtil.generateActivationKey());
- authorities.add(authority);
- newUser.setAuthorities(authorities);
- userRepository.save(newUser);
- userSearchRepository.save(newUser);
- log.debug("Created Information for User: {}", newUser);
- // Create and save the UserExtra entity
- UserExtra newUserExtra = new UserExtra();
- newUserExtra.setUser(newUser);
- newUserExtra.setPhone(phone);
- userExtraRepository.save(newUserExtra);
- userExtraSearchRepository.save(newUserExtra);
- log.debug("Created Information for UserExtra: {}", newUserExtra);
- return newUser;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement