コード例 #1
0
  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);
  }
コード例 #2
0
 @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();
 }