@Override @Transactional public boolean changeAdminRole(long userId) { User loggedInUser = findLoggedInUser(); User user = repository.findOne(userId); if (loggedInUser.getId().equals(user.getId())) { return user.isAdmin(); } user.setAdmin(!user.isAdmin()); repository.save(user); return user.isAdmin(); }
private void sendPasswordToUser(long userId, String password) { User user = repository.findOne(userId); String mailTitle = "Photo Ordering Tool - Password"; String mailBody = mailService.generateBody(user, password); mailService.send(user.getEmail(), mailTitle, mailBody); }
@Override @Transactional public void afterPropertiesSet() throws Exception { if (repository.count() > 0) { return; } saveNew(defaultUser.getEmail(), true); User u = findByEmail(defaultUser.getEmail()); changePassword(u.getId(), defaultUser.getPassword()); }
public void saveNew(String email, boolean admin) { Assert.notNull(email); Assert.isTrue(!email.trim().isEmpty()); if (alreadyExists(email)) { return; } User u = new User(); u.setEmail(email); u.setAdmin(admin); repository.save(u); }
private void changePassword(long userId, String password) { User user = repository.findOne(userId); user.setPassword(encoder.encode(password)); repository.save(user); }
@Override public List<User> findAll() { return repository.findAll(); }
@Override public User findByEmail(String email) { return repository.findByEmail(email); }
private boolean alreadyExists(String email) { return repository.findByEmail(email) != null; }