Beispiel #1
0
  private void createUserIfNeeded(LDAPResource ldap, String cn) throws LdapException {
    Entry ldapUser = ldap.getUser(cn);
    String email = ldap.getAttribute(ldapUser, emailAttr);
    User user = users.findByEmail(email);
    if (user == null) {
      String fullName = ldap.getAttribute(ldapUser, nameAttr);
      if (isNotEmpty(surnameAttr)) {
        fullName += " " + ldap.getAttribute(ldapUser, surnameAttr);
      }

      user = new User(fromTrustedText(fullName.trim()), email);

      LoginMethod brutalLogin = LoginMethod.brutalLogin(user, email, PLACHOLDER_PASSWORD);
      user.add(brutalLogin);

      users.save(user);
      loginMethods.save(brutalLogin);
    }

    // update moderator status
    // if (isNotEmpty(moderatorGroup) && ldap.getGroups(ldapUser).contains(moderatorGroup)) {
    //	user = user.asModerator();
    // } else {
    //	user.removeModerator();
    // }
    // updateAvatarImage(ldap, ldapUser, user);

    users.save(user);
  }
Beispiel #2
0
  @Test
  public void should_log_in() {
    User user = randomUser();
    UserFlow navigation = login(navigate(), user.getEmail());
    VRaptorTestResult loginResult = navigation.followRedirect().execute();
    loginResult.wasStatus(200).isValid();

    LoggedUser loggedUser = loginResult.getObject("currentUser");
    User currentUser = loggedUser.getCurrent();

    assertThat(currentUser.getId(), equalTo(user.getId()));
  }
Beispiel #3
0
 public boolean shouldShowAds() {
   if (!loggedUser.isLoggedIn()) {
     return true;
   }
   User current = loggedUser.getCurrent();
   if (current.getKarma() <= 50) {
     return true;
   }
   if (current.getKarma() <= 1000) {
     return shouldShowWithPercentage(50);
   }
   return shouldShowWithPercentage(25);
 }
Beispiel #4
0
 private void updateAvatarImage(LDAPResource ldap, Entry entry, User user) {
   try {
     byte[] jpegBytes = getAvatarImage(ldap, entry);
     if (jpegBytes != null) {
       String fileName = user.getEmail() + ".jpg";
       DefaultUploadedFile avatar =
           new DefaultUploadedFile(
               new ByteArrayInputStream(jpegBytes), fileName, "image/jpeg", jpegBytes.length);
       Attachment attachment = imageStore.processAndStore(avatar, user, clientIp);
       Attachment old = user.getAvatar();
       if (old != null) {
         imageStore.delete(old);
       }
       user.setAvatar(attachment);
     }
   } catch (LdapException | IOException e) {
     // problems with avatar processing are non-fatal
     logger.warn("Error updating user avatar from LDAP: " + user.getName(), e);
   }
 }