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"> <form action="${url.registrationAction}" method="post">
<p class="subtitle">${rb.getString('allRequired')}</p> <p class="subtitle">${rb.getString('allRequired')}</p>
<div> <div>
<label for="name">${rb.getString('fullName')}</label> <label for="firstName">${rb.getString('firstName')}</label>
<input type="text" id="name" name="name" value="${register.formData.name!''}" /> <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>
<div> <div>
<label for="email">${rb.getString('email')}</label> <label for="email">${rb.getString('email')}</label>

View file

@ -25,7 +25,8 @@ invalidUser=Invalid username or password
invalidPassword=Invalid username or password invalidPassword=Invalid username or password
accountDisabled=Account is disabled, contact admin 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 missingEmail=Please specify email
missingUsername=Please specify username missingUsername=Please specify username
missingPassword=Please specify password missingPassword=Please specify password
@ -37,4 +38,4 @@ invalidTotp=Invalid authenticator code
usernameExists=Username already exists usernameExists=Username already exists
error=A system error has occured, contact admin error=A system error has occured, contact admin

View file

@ -38,7 +38,9 @@ public class Messages {
public static final String MISSING_EMAIL = "missingEmail"; 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"; public static final String MISSING_PASSWORD = "missingPassword";

View file

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

View file

@ -286,30 +286,8 @@ public class TokenService {
} }
user = realm.addUser(username); user = realm.addUser(username);
user.setFirstName(formData.getFirst("firstName"));
String fullname = formData.getFirst("name"); user.setLastName(formData.getFirst("lastName"));
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.setEmail(formData.getFirst("email")); user.setEmail(formData.getFirst("email"));

View file

@ -9,8 +9,12 @@ import java.util.List;
public class Validation { public class Validation {
public static String validateRegistrationForm(MultivaluedMap<String, String> formData, List<String> requiredCredentialTypes) { public static String validateRegistrationForm(MultivaluedMap<String, String> formData, List<String> requiredCredentialTypes) {
if (isEmpty(formData.getFirst("name"))) { if (isEmpty(formData.getFirst("firstName"))) {
return Messages.MISSING_NAME; return Messages.MISSING_FIRST_NAME;
}
if (isEmpty(formData.getFirst("lastName"))) {
return Messages.MISSING_LAST_NAME;
} }
if (isEmpty(formData.getFirst("email"))) { if (isEmpty(formData.getFirst("email"))) {

View file

@ -109,7 +109,7 @@ public class RequiredActionEmailVerificationTest {
public void verifyEmailRegister() throws IOException, MessagingException { public void verifyEmailRegister() throws IOException, MessagingException {
loginPage.open(); loginPage.open();
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.register("name", "email", "verifyEmail", "password", "password"); registerPage.register("firstName", "lastName", "email", "verifyEmail", "password", "password");
Assert.assertTrue(driver.getPageSource().contains("Verify email")); Assert.assertTrue(driver.getPageSource().contains("Verify email"));

View file

@ -85,7 +85,7 @@ public class RequiredActionTotpSetupTest {
public void setupTotpRegister() { public void setupTotpRegister() {
loginPage.open(); loginPage.open();
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.register("name", "email", "setupTotp", "password", "password"); registerPage.register("firstName", "lastName", "email", "setupTotp", "password", "password");
totpPage.assertCurrent(); totpPage.assertCurrent();

View file

@ -63,7 +63,7 @@ public class RegisterTest {
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.assertCurrent(); registerPage.assertCurrent();
registerPage.register("name", "email", "test-user@localhost", "password", "password"); registerPage.register("firstName", "lastName", "email", "test-user@localhost", "password", "password");
registerPage.assertCurrent(); registerPage.assertCurrent();
Assert.assertEquals("Username already exists", registerPage.getError()); Assert.assertEquals("Username already exists", registerPage.getError());
@ -75,7 +75,7 @@ public class RegisterTest {
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.assertCurrent(); registerPage.assertCurrent();
registerPage.register("name", "email", "registerUserInvalidPasswordConfirm", "password", "invalid"); registerPage.register("firstName", "lastName", "email", "registerUserInvalidPasswordConfirm", "password", "invalid");
registerPage.assertCurrent(); registerPage.assertCurrent();
Assert.assertEquals("Password confirmation doesn't match", registerPage.getError()); Assert.assertEquals("Password confirmation doesn't match", registerPage.getError());
@ -87,7 +87,7 @@ public class RegisterTest {
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.assertCurrent(); registerPage.assertCurrent();
registerPage.register("name", "email", "registerUserMissingPassword", null, null); registerPage.register("firstName", "lastName", "email", "registerUserMissingPassword", null, null);
registerPage.assertCurrent(); registerPage.assertCurrent();
Assert.assertEquals("Please specify password", registerPage.getError()); Assert.assertEquals("Please specify password", registerPage.getError());
@ -99,7 +99,7 @@ public class RegisterTest {
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.assertCurrent(); registerPage.assertCurrent();
registerPage.register("name", "email", null, "password", "password"); registerPage.register("firstName", "lastName", "email", null, "password", "password");
registerPage.assertCurrent(); registerPage.assertCurrent();
Assert.assertEquals("Please specify username", registerPage.getError()); Assert.assertEquals("Please specify username", registerPage.getError());
@ -111,7 +111,7 @@ public class RegisterTest {
loginPage.clickRegister(); loginPage.clickRegister();
registerPage.assertCurrent(); registerPage.assertCurrent();
registerPage.register("name", "email", "registerUserSuccess", "password", "password"); registerPage.register("firstName", "lastName", "email", "registerUserSuccess", "password", "password");
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType()); Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
} }

View file

@ -29,8 +29,11 @@ import org.openqa.selenium.support.FindBy;
*/ */
public class RegisterPage extends Page { public class RegisterPage extends Page {
@FindBy(id = "name") @FindBy(id = "firstName")
private WebElement nameInput; private WebElement firstNameInput;
@FindBy(id = "lastName")
private WebElement lastNameInput;
@FindBy(id = "email") @FindBy(id = "email")
private WebElement emailInput; private WebElement emailInput;
@ -50,9 +53,13 @@ public class RegisterPage extends Page {
@FindBy(id = "loginError") @FindBy(id = "loginError")
private WebElement loginErrorMessage; private WebElement loginErrorMessage;
public void register(String name, String email, String username, String password, String passwordConfirm) { public void register(String firstName, String lastName, String email, String username, String password, String passwordConfirm) {
if (name != null) { if (firstName != null) {
nameInput.sendKeys(name); firstNameInput.sendKeys(firstName);
}
if (lastName != null) {
lastNameInput.sendKeys(lastName);
} }
if (email != null) { if (email != null) {