Search in sources :

Example 16 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class RegistrationControllerTest method regEmailsAdditonalValidateUnclaimedAccountTest.

@Test
public void regEmailsAdditonalValidateUnclaimedAccountTest() {
    String additionalEmail = "email1@test.orcid.org";
    String orcid = "0000-0000-0000-0000";
    when(emailManager.emailExists(additionalEmail)).thenReturn(true);
    when(emailManager.findOrcidIdByEmail(additionalEmail)).thenReturn(orcid);
    when(profileEntityManager.isProfileClaimedByEmail(additionalEmail)).thenReturn(false);
    when(profileEntityManager.isDeactivated(orcid)).thenReturn(false);
    when(emailManager.isAutoDeprecateEnableForEmail(additionalEmail)).thenReturn(true);
    Registration reg = new Registration();
    List<Text> emailsAdditionalList = new ArrayList<Text>();
    Text emailAdditional = new Text();
    emailAdditional.setValue(additionalEmail);
    emailsAdditionalList.add(emailAdditional);
    reg.setEmailsAdditional(emailsAdditionalList);
    reg = registrationController.regEmailsAdditionalValidate(servletRequest, reg, false, true);
    assertNotNull(reg);
    // No errors, since the account can be auto deprecated
    assertTrue(reg.getEmail().getErrors().isEmpty());
    assertNotNull(reg.getEmailsAdditional());
    for (Text emailAdditionalListItem : reg.getEmailsAdditional()) {
        assertNotNull(emailAdditionalListItem.getErrors());
        assertTrue(emailAdditionalListItem.getErrors().isEmpty());
    }
}
Also used : Registration(org.orcid.pojo.ajaxForm.Registration) ArrayList(java.util.ArrayList) Text(org.orcid.pojo.ajaxForm.Text) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 17 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class RegistrationControllerTest method regEmailValidateDeactivatedAccountTest.

@Test
public void regEmailValidateDeactivatedAccountTest() {
    String email = "email1@test.orcid.org";
    String orcid = "0000-0000-0000-0000";
    when(emailManager.emailExists(email)).thenReturn(true);
    when(emailManager.findOrcidIdByEmail(email)).thenReturn(orcid);
    when(profileEntityManager.isProfileClaimedByEmail(email)).thenReturn(false);
    // Set it as deactivated
    when(profileEntityManager.isDeactivated(orcid)).thenReturn(true);
    Registration reg = new Registration();
    reg.setEmail(Text.valueOf("email1@test.orcid.org"));
    reg.setEmailConfirm(Text.valueOf("email1@test.orcid.org"));
    reg = registrationController.regEmailValidate(servletRequest, reg, false, true);
    assertNotNull(reg);
    assertNotNull(reg.getEmail());
    assertNotNull(reg.getEmail().getErrors());
    assertEquals(1, reg.getEmail().getErrors().size());
    assertTrue(reg.getEmail().getErrors().get(0).startsWith("orcid.frontend.verify.deactivated_email"));
}
Also used : Registration(org.orcid.pojo.ajaxForm.Registration) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 18 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class RegistrationControllerTest method regEmailValidateUnclaimedAccountTest.

@Test
public void regEmailValidateUnclaimedAccountTest() {
    String email = "email1@test.orcid.org";
    String orcid = "0000-0000-0000-0000";
    when(emailManager.emailExists(email)).thenReturn(true);
    when(emailManager.findOrcidIdByEmail(email)).thenReturn(orcid);
    when(profileEntityManager.isProfileClaimedByEmail(email)).thenReturn(false);
    when(profileEntityManager.isDeactivated(orcid)).thenReturn(false);
    when(emailManager.isAutoDeprecateEnableForEmail(email)).thenReturn(true);
    Registration reg = new Registration();
    reg.setEmail(Text.valueOf("email1@test.orcid.org"));
    reg.setEmailConfirm(Text.valueOf("email1@test.orcid.org"));
    reg = registrationController.regEmailValidate(servletRequest, reg, false, true);
    assertNotNull(reg);
    assertNotNull(reg.getEmail());
    assertNotNull(reg.getEmail().getErrors());
    // No errors, since the account can be auto deprecated
    assertTrue(reg.getEmail().getErrors().isEmpty());
}
Also used : Registration(org.orcid.pojo.ajaxForm.Registration) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 19 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class RegistrationController method getRegister.

@RequestMapping(value = "/register.json", method = RequestMethod.GET)
@ResponseBody
public Registration getRegister(HttpServletRequest request, HttpServletResponse response) {
    // Remove the session hash if needed
    if (request.getSession().getAttribute(GRECAPTCHA_SESSION_ATTRIBUTE_NAME) != null) {
        request.getSession().removeAttribute(GRECAPTCHA_SESSION_ATTRIBUTE_NAME);
    }
    Registration reg = new Registration();
    reg.getEmail().setRequired(true);
    reg.getEmailConfirm().setRequired(true);
    reg.getEmailsAdditional().get(0).setRequired(false);
    reg.getFamilyNames().setRequired(false);
    reg.getGivenNames().setRequired(true);
    reg.getSendChangeNotifications().setValue(true);
    reg.getSendOrcidNews().setValue(true);
    reg.getSendMemberUpdateRequests().setValue(true);
    reg.getSendEmailFrequencyDays().setValue(SendEmailFrequency.WEEKLY.value());
    reg.getTermsOfUse().setValue(false);
    Boolean isOauth2ScreensRequest = (Boolean) request.getSession().getAttribute(OrcidOauth2Constants.OAUTH_2SCREENS);
    if (isOauth2ScreensRequest != null) {
        reg.setCreationType(Text.valueOf(CreationMethod.MEMBER_REFERRED.value()));
    } else {
        reg.setCreationType(Text.valueOf(CreationMethod.DIRECT.value()));
    }
    setError(reg.getTermsOfUse(), "validations.acceptTermsAndConditions");
    RequestInfoForm requestInfoForm = (RequestInfoForm) request.getSession().getAttribute(OauthControllerBase.REQUEST_INFO_FORM);
    if (requestInfoForm != null) {
        if (!PojoUtil.isEmpty(requestInfoForm.getUserEmail())) {
            reg.getEmail().setValue(requestInfoForm.getUserEmail());
        }
        if (!PojoUtil.isEmpty(requestInfoForm.getUserGivenNames())) {
            reg.getGivenNames().setValue(requestInfoForm.getUserGivenNames());
        }
        if (!PojoUtil.isEmpty(requestInfoForm.getUserFamilyNames())) {
            reg.getFamilyNames().setValue(requestInfoForm.getUserFamilyNames());
        }
    }
    long numVal = generateRandomNumForValidation();
    reg.setValNumServer(numVal);
    reg.setValNumClient(0);
    return reg;
}
Also used : Registration(org.orcid.pojo.ajaxForm.Registration) RequestInfoForm(org.orcid.pojo.ajaxForm.RequestInfoForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 20 with Registration

use of org.orcid.pojo.ajaxForm.Registration in project ORCID-Source by ORCID.

the class RegistrationManagerImplTest method testCreateMinimalRegistrationWithExistingUnclaimedEmailAdditionalNotAutoDeprecatable.

@Test
public void testCreateMinimalRegistrationWithExistingUnclaimedEmailAdditionalNotAutoDeprecatable() {
    // Create the user, but set it as unclaimed
    String email = "new_user_" + System.currentTimeMillis() + "@test.orcid.org";
    // Create a record by a member
    OrcidProfile orcidProfile = createBasicProfile(email, false, CLIENT_ID_AUTODEPRECATE_DISABLED);
    orcidProfile = orcidProfileManager.createOrcidProfile(orcidProfile, true, true);
    assertNotNull(orcidProfile);
    assertNotNull(orcidProfile.getOrcidIdentifier());
    assertNotNull(orcidProfile.getOrcidIdentifier().getPath());
    try {
        String email2 = "new_user2_" + System.currentTimeMillis() + "@test.orcid.org";
        List<Text> emailsAdditionalList = new ArrayList<Text>();
        Text emailAdditional = new Text();
        emailAdditional.setValue(email);
        emailsAdditionalList.add(emailAdditional);
        Registration form = createRegistrationFormMultipleEmails(email2, emailsAdditionalList, true);
        registrationManager.createMinimalRegistration(form, true, java.util.Locale.ENGLISH, "0.0.0.0");
        fail();
    } catch (InvalidRequestException e) {
        assertEquals("Unable to register user due: Autodeprecate is not enabled for " + email, e.getMessage());
    } catch (Exception e) {
        fail();
    }
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) Registration(org.orcid.pojo.ajaxForm.Registration) ArrayList(java.util.ArrayList) Text(org.orcid.pojo.ajaxForm.Text) InvalidRequestException(org.springframework.security.oauth2.common.exceptions.InvalidRequestException) InvalidRequestException(org.springframework.security.oauth2.common.exceptions.InvalidRequestException) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

Registration (org.orcid.pojo.ajaxForm.Registration)26 Test (org.junit.Test)23 DBUnitTest (org.orcid.test.DBUnitTest)23 Text (org.orcid.pojo.ajaxForm.Text)13 ArrayList (java.util.ArrayList)11 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)5 InvalidRequestException (org.springframework.security.oauth2.common.exceptions.InvalidRequestException)5 Locale (java.util.Locale)2 HttpSession (javax.servlet.http.HttpSession)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Checkbox (org.orcid.pojo.ajaxForm.Checkbox)2 RequestInfoForm (org.orcid.pojo.ajaxForm.RequestInfoForm)2 Principal (java.security.Principal)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 OrcidOAuth2Authentication (org.orcid.core.oauth.OrcidOAuth2Authentication)1 Visibility (org.orcid.jaxb.model.v3.dev1.common.Visibility)1 OauthRegistrationForm (org.orcid.pojo.ajaxForm.OauthRegistrationForm)1 Authentication (org.springframework.security.core.Authentication)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1