Package edu.drexel.goodwin.cpd.domain

Examples of edu.drexel.goodwin.cpd.domain.Researcher


  }

  @Test
  @Transactional
  public void testCanResetPasswordIfEmailAddressExists() throws Exception {
    Researcher researcher = dod.getRandomResearcher();

    ForgotPasswordRequest resetRequest = new ForgotPasswordRequest();
    resetRequest.setRecaptcha_challenge_field("test");
    resetRequest.setRecaptcha_response_field("test");
    resetRequest.setEmailAddress(researcher.getEmail());
    BindingResult bindingResult = new BeanPropertyBindingResult(resetRequest, "resetRequest");

    String oldPassword = researcher.getPassword();

    researcherManager.resetPassword(resetRequest, bindingResult);

    Query queryResult = Researcher.findResearchersByEmailEquals(researcher.getEmail());
    assertEquals(1, queryResult.getResultList().size());
    Researcher researcherAgain = (Researcher) queryResult.getSingleResult();
    assertTrue("password should have changed", !oldPassword.equals(researcherAgain.getPassword()));
  }
View Full Code Here


  }

  @Test
  @Transactional
  public void testResetPasswordSaltsThePassword() throws Exception {
    Researcher researcher = dod.getRandomResearcher();

    ForgotPasswordRequest resetRequest = new ForgotPasswordRequest();
    resetRequest.setRecaptcha_challenge_field("test");
    resetRequest.setRecaptcha_response_field("test");
    resetRequest.setEmailAddress(researcher.getEmail());
    BindingResult bindingResult = new BeanPropertyBindingResult(resetRequest, "resetRequest");

    String oldPassword = researcher.getPassword();

    researcherManager.resetPassword(resetRequest, bindingResult);

    Query queryResult = Researcher.findResearchersByEmailEquals(researcher.getEmail());
    assertEquals(1, queryResult.getResultList().size());
    Researcher researcherAgain = (Researcher) queryResult.getSingleResult();
    assertTrue("password should have changed", !oldPassword.equals(researcherAgain.getPassword()));
  }
View Full Code Here

    if (Researcher.findResearchersByEmailEquals(dto.getEmail()).getResultList().size() != 0) {
      result.rejectValue("email", "researcher.error.email", "There is already an account under that email address. If you forgot your password use the forgot password link from the login page to get help.");
    }
   
    Researcher researcher = copyFormDataFromDtoToResearcher(dto, new Researcher());
    researcher.setPassword(dto.getPassword());

    Set<ConstraintViolation<Researcher>> violatedConstraints = Validation.buildDefaultValidatorFactory().getValidator().validate(researcher);
    for (ConstraintViolation<Researcher> constraint : violatedConstraints) {
      result.rejectValue(constraint.getPropertyPath().toString(), "researcher.error." + constraint.getPropertyPath(), constraint.getMessage());
    }

    if (!result.hasErrors()) {
      uploadProfilePictureIfEntered(dto, researcher);

      researcher.setSalt(getRandomSalt());
      researcher.setPassword(getHashedPassword(dto.getPassword(), researcher.getSalt()));
      researcher.persist();
     
      String message = generateMessage(accountCreatedMessage, new Object[] {researcher.getEmail(), applicationUrl});
      messageSender.sendMessage("Community Profile Database Account Created", researcher.getEmail(), message);
    }
  }
View Full Code Here

  }

  @PreAuthorize("hasRole('ROLE_ADMIN')")
  @Override
  public void deleteResearcher(Long id) {
    Researcher researcher = Researcher.findResearcher(id);
    researcher.setDeleted(true);
    researcher.merge();
  }
View Full Code Here

  @PreAuthorize("hasRole('ROLE_ADMIN') or (#dto.id == principal.id)")
  @Override
  public void update(ResearcherDto dto, BindingResult result) {
    checkAllUserInputsForInvalidHtml(dto, result);

    Researcher researcher = copyFormDataFromDtoToResearcher(dto, getResearcherForEditing(dto.getId()));

    for (ConstraintViolation<Researcher> constraint : Validation.buildDefaultValidatorFactory().getValidator().validate(researcher)) {
      if ("password".equals(constraint.getPropertyPath().toString())) {
        continue; // We do not validate the password on updates
      }
      result.rejectValue(constraint.getPropertyPath().toString(), "researcher.error." + constraint.getPropertyPath(), constraint.getMessage());
    }

    if (!result.hasErrors()) {
      uploadProfilePictureIfEntered(dto, researcher);

      researcher.merge();
      String message = generateMessage(accountUpdatedMessage, new Object[] {applicationUrl});
      messageSender.sendMessage("Community Profile Database Account Updated", researcher.getEmail(), message);
    }
  }
View Full Code Here

  @PreAuthorize("hasRole('ROLE_ADMIN') or #dto.Id == principal.Id")
  @Override
  public void updatePassword(ResearcherDto dto, BindingResult result) {
    if (isPasswordValidAndMatchesConfirm(dto, result)) {
      Researcher researcher = getResearcherForEditing(dto.getId());
      researcher.setPassword(getHashedPassword(dto.getPassword(), researcher.getSalt()));
      researcher.merge();
    }
  }
View Full Code Here

    if (queryResult.getResultList().size() == 0) {
      // Email address does not exist in database
      return;
    }

    Researcher researcher = (Researcher) queryResult.getSingleResult();

    String temporaryPassword = RandomStringUtils.randomAlphanumeric(8);
    researcher.setPassword(getHashedPassword(temporaryPassword, researcher.getSalt()));

    String message = generateMessage(resetPasswordMessage, new Object[] {temporaryPassword, applicationUrl});
    messageSender.sendMessage("Community Profile Database Forgot Password", researcher.getEmail(), message);
  }
View Full Code Here

  }

  @Override
  public ResearcherDto getCurrentlyLoggedInResearcherDto() {
    String currentlyLoggedInReseacher = ((Researcher) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername();
    Researcher researcher = (Researcher) Researcher.findResearchersByEmailEquals(currentlyLoggedInReseacher).getSingleResult();

    return researcherDtoAssembler.assemble(researcher);
  }
View Full Code Here

TOP

Related Classes of edu.drexel.goodwin.cpd.domain.Researcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.