Merge pull request #44 from vrockai/KEYCLOAK-74_2

KEYCLOAK-74 name to 1st/last name in registration form
This commit is contained in:
stianst 2013-09-27 07:22:05 -07:00
commit 139412ff45
10 changed files with 41 additions and 66 deletions

View file

@ -14,8 +14,12 @@
<form action="${url.registrationAction}" method="post">
<p class="subtitle">${rb.getString('allRequired')}</p>
<div>
<label for="name">${rb.getString('fullName')}</label>
<input type="text" id="name" name="name" value="${register.formData.name!''}" />
<label for="firstName">${rb.getString('firstName')}</label>
<input type="text" id="firstName" name="firstName" value="${register.formData.firstName!''}" />
</div>
<div>
<label for="lastName">${rb.getString('lastName')}</label>
<input type="text" id="lastName" name="lastName" value="${register.formData.lastName!''}" />
</div>
<div>
<label for="email">${rb.getString('email')}</label>

View file

@ -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

View file

@ -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";

View file

@ -273,29 +273,8 @@ public class SaasService {
newUser.setUsername(formData.getFirst("username"));
newUser.setEmail(formData.getFirst("email"));
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();
newUser.setFirstName(first.toString());
newUser.setLastName(last);
}
newUser.setFirstName(formData.getFirst("firstName"));
newUser.setLastName(formData.getFirst("lastName"));
if (requiredCredentialTypes.contains(CredentialRepresentation.PASSWORD)) {
newUser.credential(CredentialRepresentation.PASSWORD, formData.getFirst("password"));

View file

@ -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"));

View file

@ -9,8 +9,12 @@ import java.util.List;
public class Validation {
public static String validateRegistrationForm(MultivaluedMap<String, String> formData, List<String> 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"))) {

View file

@ -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"));

View file

@ -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();

View file

@ -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());
}

View file

@ -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) {