Search in sources :

Example 21 with EmailEntity

use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.

the class EmailDaoTest method testVerifyCaseSensitive.

@Test
public void testVerifyCaseSensitive() {
    EmailEntity email = emailDao.find("teddybass3public@semantico.com");
    assertNotNull(email);
    assertFalse(email.getVerified());
    emailDao.verifyEmail("TeDdYbAsS3PuBlIc@semantico.com");
    email = emailDao.find("teddybass3public@semantico.com");
    assertNotNull(email);
    assertTrue(email.getVerified());
}
Also used : EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) Test(org.junit.Test) DBUnitTest(org.orcid.test.DBUnitTest)

Example 22 with EmailEntity

use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.

the class ManageProfileController method searchForDelegateByEmail.

@RequestMapping(value = "/search-for-delegate-by-email/{email}/")
@ResponseBody
public Map<String, Boolean> searchForDelegateByEmail(@PathVariable String email) {
    Map<String, Boolean> map = new HashMap<>();
    EmailEntity emailEntity = emailManager.findCaseInsensitive(email);
    if (emailEntity == null) {
        map.put(FOUND, Boolean.FALSE);
        return map;
    } else {
        map.put(FOUND, Boolean.TRUE);
        map.put(IS_SELF, emailEntity.getProfile().getId().equals(getCurrentUserOrcid()));
        return map;
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 23 with EmailEntity

use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.

the class OrcidProfileManagerImpl method retrieveOrcidProfileByEmail.

@Override
@Transactional
public OrcidProfile retrieveOrcidProfileByEmail(String email, LoadOptions loadOptions) {
    EmailEntity emailEntity = emailDao.findCaseInsensitive(email);
    if (emailEntity != null) {
        ProfileEntity profileEntity = emailEntity.getProfile();
        OrcidProfile orcidProfile = adapter.toOrcidProfile(profileEntity, loadOptions);
        String verificationCode = profileEntity.getEncryptedVerificationCode();
        String securityAnswer = profileEntity.getEncryptedSecurityAnswer();
        orcidProfile.setVerificationCode(decrypt(verificationCode));
        orcidProfile.setSecurityQuestionAnswer(decrypt(securityAnswer));
        return orcidProfile;
    } else {
        return null;
    }
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with EmailEntity

use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.

the class Jpa2JaxbAdapterImpl method toOrcidClientGroup.

@Override
public OrcidClientGroup toOrcidClientGroup(ProfileEntity profileEntity) {
    OrcidClientGroup group = new OrcidClientGroup();
    group.setGroupOrcid(profileEntity.getId());
    if (profileEntity.getRecordNameEntity() != null) {
        group.setGroupName(profileEntity.getRecordNameEntity().getCreditName());
    }
    group.setType(profileEntity.getGroupType());
    Set<EmailEntity> emailEntities = profileEntity.getEmails();
    for (EmailEntity emailEntity : emailEntities) {
        group.setEmail(emailEntity.getId());
    }
    for (ClientDetailsEntity clientDetailsEntity : profileEntity.getClients()) {
        OrcidClient client = toOrcidClient(clientDetailsEntity);
        group.getOrcidClient().add(client);
    }
    return group;
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) OrcidClientGroup(org.orcid.jaxb.model.clientgroup.OrcidClientGroup) OrcidClient(org.orcid.jaxb.model.clientgroup.OrcidClient) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity)

Example 25 with EmailEntity

use of org.orcid.persistence.jpa.entities.EmailEntity in project ORCID-Source by ORCID.

the class RegistrationController method verifyEmail.

@RequestMapping(value = "/verify-email/{encryptedEmail}", method = RequestMethod.GET)
public ModelAndView verifyEmail(HttpServletRequest request, @PathVariable("encryptedEmail") String encryptedEmail, RedirectAttributes redirectAttributes) throws UnsupportedEncodingException {
    try {
        String decryptedEmail = encryptionManager.decryptForExternalUse(new String(Base64.decodeBase64(encryptedEmail), "UTF-8"));
        EmailEntity emailEntity = emailManager.find(decryptedEmail);
        String emailOrcid = emailEntity.getProfile().getId();
        if (!getCurrentUserOrcid().equals(emailOrcid)) {
            return new ModelAndView("wrong_user");
        }
        emailEntity.setVerified(true);
        emailEntity.setCurrent(true);
        emailManager.update(emailEntity);
        profileEntityManager.updateLocale(emailOrcid, org.orcid.jaxb.model.common_v2.Locale.fromValue(RequestContextUtils.getLocale(request).toString()));
        redirectAttributes.addFlashAttribute("emailVerified", true);
    } catch (EncryptionOperationNotPossibleException eonpe) {
        LOGGER.warn("Error decypting verify email from the verify email link");
        redirectAttributes.addFlashAttribute("invalidVerifyUrl", true);
    }
    return new ModelAndView("redirect:/my-orcid");
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) EncryptionOperationNotPossibleException(org.jasypt.exceptions.EncryptionOperationNotPossibleException) EmailEntity(org.orcid.persistence.jpa.entities.EmailEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)45 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)21 Date (java.util.Date)14 Test (org.junit.Test)14 HashSet (java.util.HashSet)11 RecordNameEntity (org.orcid.persistence.jpa.entities.RecordNameEntity)10 DBUnitTest (org.orcid.test.DBUnitTest)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 Email (org.orcid.jaxb.model.v3.dev1.record.Email)6 Transactional (org.springframework.transaction.annotation.Transactional)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 Set (java.util.Set)4 Email (org.orcid.jaxb.model.record_v2.Email)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2