예제 #1
0
 @Override
 public void checkLogin(int userId, String password) {
   User u = userRepository.findOne(userId);
   if (u == null || !passwordEncoder.matches(password, u.getPassword())) {
     throw new UserServiceException("Username or password isn't correct");
   }
 }
예제 #2
0
  private void validateUser(User user) {
    if (user == null) throw new UserServiceException("User cannot be null");

    if (user.getUsername() == null || user.getUsername().trim().isEmpty()) {
      throw new UserServiceException("username of user cannot be null or empty");
    }

    if (user.getEmail() == null || user.getUsername().trim().isEmpty()) {
      throw new UserServiceException("email of user cannot be null or empty");
    }
  }
예제 #3
0
  @Test(expected = SessionServiceException.class)
  public void addSessionAsNonOrganizerThrowsException() {
    User nonOrganizer = new User("test-non-organizer", "pass");
    nonOrganizer.setEmail("nonorganizer@localhost");
    nonOrganizer = userRepository.save(nonOrganizer);

    Session session = new SynchronousSession();
    session.setCategory(category);
    session.setOrganizer(nonOrganizer);

    sessionService.addSession(session);
  }
예제 #4
0
  @Override
  public User addUser(User user) {
    validateUser(user);
    try {
      String unencryptedPassword = user.getPassword();
      String encryptedPassword = passwordEncoder.encode(unencryptedPassword);
      user.setPassword(encryptedPassword);

      return userRepository.save(user);
    } catch (Exception e) {
      throw new UserServiceException(
          String.format("Could not save user with username %s", user.getUsername()));
    }
  }
예제 #5
0
  @Before
  public void setup() {
    user = new User("test-user", "pass");
    user.setEmail("test@localhost");
    user = userRepository.save(user);

    organization = new Organization("test-organization", user);
    organization = organizationRepository.save(organization);

    category = new Category();
    category.setOrganization(organization);
    category.setName("Category 1");
    category.setDescription("Category description");
    category = categoryRepository.save(category);

    topic = new Topic();
    topic.setCategory(category);
    topic.setName("Topic 1");
    topic.setDescription("Topic description");
    topic = topicRepository.save(topic);

    cardDetails1 = new CardDetails();
    cardDetails1.setCategory(category);
    cardDetails1.setCreator(user);
    cardDetails1.setText("Card 1");
    cardDetails1 = cardDetailsRepository.save(cardDetails1);

    cardDetails2 = new CardDetails();
    cardDetails2.setCategory(category);
    cardDetails2.setCreator(user);
    cardDetails2.setText("Card 2");
    cardDetails2 = cardDetailsRepository.save(cardDetails2);

    cardDetails3 = new CardDetails();
    cardDetails3.setCategory(category);
    cardDetails3.setCreator(user);
    cardDetails3.setText("Card 3");
    cardDetails3 = cardDetailsRepository.save(cardDetails3);

    cardDetails4 = new CardDetails();
    cardDetails4.setCategory(category);
    cardDetails4.setCreator(user);
    cardDetails4.setText("Card 4");
    cardDetails4 = cardDetailsRepository.save(cardDetails4);

    cardDetails5 = new CardDetails();
    cardDetails5.setCategory(category);
    cardDetails5.setCreator(user);
    cardDetails5.setText("Card 5");
    cardDetails5 = cardDetailsRepository.save(cardDetails5);

    category.setCards(new HashSet<>());
    category.getCards().add(cardDetails1);
    category.getCards().add(cardDetails2);
    category.getCards().add(cardDetails3);
    category.getCards().add(cardDetails4);
    category.getCards().add(cardDetails5);

    category = categoryRepository.save(category);
  }