From 32779d956aa5a9040532a2789d10c9aed799dd3f Mon Sep 17 00:00:00 2001 From: vrockai Date: Fri, 27 Sep 2013 15:55:13 +0200 Subject: [PATCH] KEYCLOAK-74 name to 1st/last name in registration form --- .../forms/theme/default/register.ftl | 8 ++++-- .../org/keycloak/forms/messages.properties | 5 ++-- .../keycloak/services/messages/Messages.java | 4 ++- .../services/resources/TokenService.java | 26 ++----------------- .../services/validation/Validation.java | 8 ++++-- .../RequiredActionEmailVerificationTest.java | 2 +- .../actions/RequiredActionTotpSetupTest.java | 2 +- .../testsuite/forms/RegisterTest.java | 10 +++---- .../testsuite/pages/RegisterPage.java | 17 ++++++++---- 9 files changed, 39 insertions(+), 43 deletions(-) diff --git a/forms/src/main/resources/META-INF/resources/forms/theme/default/register.ftl b/forms/src/main/resources/META-INF/resources/forms/theme/default/register.ftl index b418da1d3e..c9b5997ce5 100755 --- a/forms/src/main/resources/META-INF/resources/forms/theme/default/register.ftl +++ b/forms/src/main/resources/META-INF/resources/forms/theme/default/register.ftl @@ -14,8 +14,12 @@

${rb.getString('allRequired')}

- - + + +
+
+ +
diff --git a/forms/src/main/resources/org/keycloak/forms/messages.properties b/forms/src/main/resources/org/keycloak/forms/messages.properties index 50e21b60c8..4ce9a69a5d 100644 --- a/forms/src/main/resources/org/keycloak/forms/messages.properties +++ b/forms/src/main/resources/org/keycloak/forms/messages.properties @@ -25,7 +25,8 @@ invalidUser=Invalid username or password invalidPassword=Invalid username or password accountDisabled=Account is disabled, contact admin -missingName=Please specify full name +missingFirstName=Please specify first name +missingLastName=Please specify last name missingEmail=Please specify email missingUsername=Please specify username missingPassword=Please specify password @@ -37,4 +38,4 @@ invalidTotp=Invalid authenticator code usernameExists=Username already exists -error=A system error has occured, contact admin \ No newline at end of file +error=A system error has occured, contact admin diff --git a/services/src/main/java/org/keycloak/services/messages/Messages.java b/services/src/main/java/org/keycloak/services/messages/Messages.java index c6165a9537..3b7a760d0e 100644 --- a/services/src/main/java/org/keycloak/services/messages/Messages.java +++ b/services/src/main/java/org/keycloak/services/messages/Messages.java @@ -38,7 +38,9 @@ public class Messages { public static final String MISSING_EMAIL = "missingEmail"; - public static final String MISSING_NAME = "missingName"; + public static final String MISSING_FIRST_NAME = "missingFirstName"; + + public static final String MISSING_LAST_NAME = "missingLastName"; public static final String MISSING_PASSWORD = "missingPassword"; diff --git a/services/src/main/java/org/keycloak/services/resources/TokenService.java b/services/src/main/java/org/keycloak/services/resources/TokenService.java index 5abebb0d8e..ec7410a576 100755 --- a/services/src/main/java/org/keycloak/services/resources/TokenService.java +++ b/services/src/main/java/org/keycloak/services/resources/TokenService.java @@ -286,30 +286,8 @@ public class TokenService { } user = realm.addUser(username); - - String fullname = formData.getFirst("name"); - if (fullname != null) { - StringTokenizer tokenizer = new StringTokenizer(fullname, " "); - StringBuffer first = null; - String last = ""; - while (tokenizer.hasMoreTokens()) { - String token = tokenizer.nextToken(); - if (tokenizer.hasMoreTokens()) { - if (first == null) { - first = new StringBuffer(); - } else { - first.append(" "); - } - first.append(token); - } else { - last = token; - } - } - if (first == null) - first = new StringBuffer(); - user.setFirstName(first.toString()); - user.setLastName(last); - } + user.setFirstName(formData.getFirst("firstName")); + user.setLastName(formData.getFirst("lastName")); user.setEmail(formData.getFirst("email")); diff --git a/services/src/main/java/org/keycloak/services/validation/Validation.java b/services/src/main/java/org/keycloak/services/validation/Validation.java index 58b0650ab6..5a71f0d9f7 100755 --- a/services/src/main/java/org/keycloak/services/validation/Validation.java +++ b/services/src/main/java/org/keycloak/services/validation/Validation.java @@ -9,8 +9,12 @@ import java.util.List; public class Validation { public static String validateRegistrationForm(MultivaluedMap formData, List requiredCredentialTypes) { - if (isEmpty(formData.getFirst("name"))) { - return Messages.MISSING_NAME; + if (isEmpty(formData.getFirst("firstName"))) { + return Messages.MISSING_FIRST_NAME; + } + + if (isEmpty(formData.getFirst("lastName"))) { + return Messages.MISSING_LAST_NAME; } if (isEmpty(formData.getFirst("email"))) { diff --git a/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionEmailVerificationTest.java b/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionEmailVerificationTest.java index ba9104e4e3..26b9e552e8 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionEmailVerificationTest.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionEmailVerificationTest.java @@ -109,7 +109,7 @@ public class RequiredActionEmailVerificationTest { public void verifyEmailRegister() throws IOException, MessagingException { loginPage.open(); loginPage.clickRegister(); - registerPage.register("name", "email", "verifyEmail", "password", "password"); + registerPage.register("firstName", "lastName", "email", "verifyEmail", "password", "password"); Assert.assertTrue(driver.getPageSource().contains("Verify email")); diff --git a/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionTotpSetupTest.java b/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionTotpSetupTest.java index e89125e33a..cf05276019 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionTotpSetupTest.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/actions/RequiredActionTotpSetupTest.java @@ -85,7 +85,7 @@ public class RequiredActionTotpSetupTest { public void setupTotpRegister() { loginPage.open(); loginPage.clickRegister(); - registerPage.register("name", "email", "setupTotp", "password", "password"); + registerPage.register("firstName", "lastName", "email", "setupTotp", "password", "password"); totpPage.assertCurrent(); diff --git a/testsuite/src/test/java/org/keycloak/testsuite/forms/RegisterTest.java b/testsuite/src/test/java/org/keycloak/testsuite/forms/RegisterTest.java index 4862cf696d..93e773ec1c 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/forms/RegisterTest.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/forms/RegisterTest.java @@ -63,7 +63,7 @@ public class RegisterTest { loginPage.clickRegister(); registerPage.assertCurrent(); - registerPage.register("name", "email", "test-user@localhost", "password", "password"); + registerPage.register("firstName", "lastName", "email", "test-user@localhost", "password", "password"); registerPage.assertCurrent(); Assert.assertEquals("Username already exists", registerPage.getError()); @@ -75,7 +75,7 @@ public class RegisterTest { loginPage.clickRegister(); registerPage.assertCurrent(); - registerPage.register("name", "email", "registerUserInvalidPasswordConfirm", "password", "invalid"); + registerPage.register("firstName", "lastName", "email", "registerUserInvalidPasswordConfirm", "password", "invalid"); registerPage.assertCurrent(); Assert.assertEquals("Password confirmation doesn't match", registerPage.getError()); @@ -87,7 +87,7 @@ public class RegisterTest { loginPage.clickRegister(); registerPage.assertCurrent(); - registerPage.register("name", "email", "registerUserMissingPassword", null, null); + registerPage.register("firstName", "lastName", "email", "registerUserMissingPassword", null, null); registerPage.assertCurrent(); Assert.assertEquals("Please specify password", registerPage.getError()); @@ -99,7 +99,7 @@ public class RegisterTest { loginPage.clickRegister(); registerPage.assertCurrent(); - registerPage.register("name", "email", null, "password", "password"); + registerPage.register("firstName", "lastName", "email", null, "password", "password"); registerPage.assertCurrent(); Assert.assertEquals("Please specify username", registerPage.getError()); @@ -111,7 +111,7 @@ public class RegisterTest { loginPage.clickRegister(); registerPage.assertCurrent(); - registerPage.register("name", "email", "registerUserSuccess", "password", "password"); + registerPage.register("firstName", "lastName", "email", "registerUserSuccess", "password", "password"); Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType()); } diff --git a/testsuite/src/test/java/org/keycloak/testsuite/pages/RegisterPage.java b/testsuite/src/test/java/org/keycloak/testsuite/pages/RegisterPage.java index 8970704075..7ff4d7f97e 100644 --- a/testsuite/src/test/java/org/keycloak/testsuite/pages/RegisterPage.java +++ b/testsuite/src/test/java/org/keycloak/testsuite/pages/RegisterPage.java @@ -29,8 +29,11 @@ import org.openqa.selenium.support.FindBy; */ public class RegisterPage extends Page { - @FindBy(id = "name") - private WebElement nameInput; + @FindBy(id = "firstName") + private WebElement firstNameInput; + + @FindBy(id = "lastName") + private WebElement lastNameInput; @FindBy(id = "email") private WebElement emailInput; @@ -50,9 +53,13 @@ public class RegisterPage extends Page { @FindBy(id = "loginError") private WebElement loginErrorMessage; - public void register(String name, String email, String username, String password, String passwordConfirm) { - if (name != null) { - nameInput.sendKeys(name); + public void register(String firstName, String lastName, String email, String username, String password, String passwordConfirm) { + if (firstName != null) { + firstNameInput.sendKeys(firstName); + } + + if (lastName != null) { + lastNameInput.sendKeys(lastName); } if (email != null) {