use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-mongodb by jhipster.
the class UserService method registerUser.
public User registerUser(UserDTO userDTO, String password) {
User newUser = new User();
String encryptedPassword = passwordEncoder.encode(password);
newUser.setLogin(userDTO.getLogin());
// new user gets initially a generated password
newUser.setPassword(encryptedPassword);
newUser.setFirstName(userDTO.getFirstName());
newUser.setLastName(userDTO.getLastName());
newUser.setEmail(userDTO.getEmail());
newUser.setImageUrl(userDTO.getImageUrl());
newUser.setLangKey(userDTO.getLangKey());
// new user is not active
newUser.setActivated(false);
// new user gets registration key
newUser.setActivationKey(RandomUtil.generateActivationKey());
Set<Authority> authorities = new HashSet<>();
authorityRepository.findById(AuthoritiesConstants.USER).ifPresent(authorities::add);
newUser.setAuthorities(authorities);
userRepository.save(newUser);
log.debug("Created Information for User: {}", newUser);
return newUser;
}
use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-mongodb by jhipster.
the class UserService method createUser.
public User createUser(UserDTO userDTO) {
User user = new User();
user.setLogin(userDTO.getLogin());
user.setFirstName(userDTO.getFirstName());
user.setLastName(userDTO.getLastName());
user.setEmail(userDTO.getEmail());
user.setImageUrl(userDTO.getImageUrl());
if (userDTO.getLangKey() == null) {
// default language
user.setLangKey(Constants.DEFAULT_LANGUAGE);
} else {
user.setLangKey(userDTO.getLangKey());
}
if (userDTO.getAuthorities() != null) {
Set<Authority> authorities = userDTO.getAuthorities().stream().map(authorityRepository::findById).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toSet());
user.setAuthorities(authorities);
}
String encryptedPassword = passwordEncoder.encode(RandomUtil.generatePassword());
user.setPassword(encryptedPassword);
user.setResetKey(RandomUtil.generateResetKey());
user.setResetDate(Instant.now());
user.setActivated(true);
userRepository.save(user);
log.debug("Created Information for User: {}", user);
return user;
}
use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-mongodb by jhipster.
the class UserMapper method userFromId.
public User userFromId(String id) {
if (id == null) {
return null;
}
User user = new User();
user.setId(id);
return user;
}
use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-mongodb by jhipster.
the class InitialSetupMigration method addUsers.
@ChangeSet(order = "02", author = "initiator", id = "02-addUsers")
public void addUsers(MongoTemplate mongoTemplate) {
Authority adminAuthority = new Authority();
adminAuthority.setName(AuthoritiesConstants.ADMIN);
Authority userAuthority = new Authority();
userAuthority.setName(AuthoritiesConstants.USER);
User systemUser = new User();
systemUser.setId("user-0");
systemUser.setLogin("system");
systemUser.setPassword("$2a$10$mE.qmcV0mFU5NcKh73TZx.z4ueI/.bDWbj0T1BYyqP481kGGarKLG");
systemUser.setFirstName("");
systemUser.setLastName("System");
systemUser.setEmail("system@localhost");
systemUser.setActivated(true);
systemUser.setLangKey("en");
systemUser.setCreatedBy(systemUser.getLogin());
systemUser.setCreatedDate(Instant.now());
systemUser.getAuthorities().add(adminAuthority);
systemUser.getAuthorities().add(userAuthority);
mongoTemplate.save(systemUser);
User anonymousUser = new User();
anonymousUser.setId("user-1");
anonymousUser.setLogin("anonymoususer");
anonymousUser.setPassword("$2a$10$j8S5d7Sr7.8VTOYNviDPOeWX8KcYILUVJBsYV83Y5NtECayypx9lO");
anonymousUser.setFirstName("Anonymous");
anonymousUser.setLastName("User");
anonymousUser.setEmail("anonymous@localhost");
anonymousUser.setActivated(true);
anonymousUser.setLangKey("en");
anonymousUser.setCreatedBy(systemUser.getLogin());
anonymousUser.setCreatedDate(Instant.now());
mongoTemplate.save(anonymousUser);
User adminUser = new User();
adminUser.setId("user-2");
adminUser.setLogin("admin");
adminUser.setPassword("$2a$10$gSAhZrxMllrbgj/kkK9UceBPpChGWJA7SYIb1Mqo.n5aNLq1/oRrC");
adminUser.setFirstName("admin");
adminUser.setLastName("Administrator");
adminUser.setEmail("admin@localhost");
adminUser.setActivated(true);
adminUser.setLangKey("en");
adminUser.setCreatedBy(systemUser.getLogin());
adminUser.setCreatedDate(Instant.now());
adminUser.getAuthorities().add(adminAuthority);
adminUser.getAuthorities().add(userAuthority);
mongoTemplate.save(adminUser);
User userUser = new User();
userUser.setId("user-3");
userUser.setLogin("user");
userUser.setPassword("$2a$10$VEjxo0jq2YG9Rbk2HmX9S.k1uZBGYUHdUcid3g/vfiEl7lwWgOH/K");
userUser.setFirstName("");
userUser.setLastName("User");
userUser.setEmail("user@localhost");
userUser.setActivated(true);
userUser.setLangKey("en");
userUser.setCreatedBy(systemUser.getLogin());
userUser.setCreatedDate(Instant.now());
userUser.getAuthorities().add(userAuthority);
mongoTemplate.save(userUser);
}
use of io.github.jhipster.sample.domain.User in project jhipster-sample-app-mongodb by jhipster.
the class DomainUserDetailsServiceIntTest method init.
@Before
public void init() {
userRepository.deleteAll();
userOne = new User();
userOne.setLogin(USER_ONE_LOGIN);
userOne.setPassword(RandomStringUtils.random(60));
userOne.setActivated(true);
userOne.setEmail(USER_ONE_EMAIL);
userOne.setFirstName("userOne");
userOne.setLastName("doe");
userOne.setLangKey("en");
userRepository.save(userOne);
userTwo = new User();
userTwo.setLogin(USER_TWO_LOGIN);
userTwo.setPassword(RandomStringUtils.random(60));
userTwo.setActivated(true);
userTwo.setEmail(USER_TWO_EMAIL);
userTwo.setFirstName("userTwo");
userTwo.setLastName("doe");
userTwo.setLangKey("en");
userRepository.save(userTwo);
userThree = new User();
userThree.setLogin(USER_THREE_LOGIN);
userThree.setPassword(RandomStringUtils.random(60));
userThree.setActivated(false);
userThree.setEmail(USER_THREE_EMAIL);
userThree.setFirstName("userThree");
userThree.setLastName("doe");
userThree.setLangKey("en");
userRepository.save(userThree);
}
Aggregations