KEYCLOAK-185 Added cancel button to login form

This commit is contained in:
Stian Thorgersen 2013-12-03 15:11:18 +00:00
parent 389809b457
commit a7b653de28
6 changed files with 38 additions and 8 deletions

View file

@ -129,10 +129,10 @@ body {
margin-bottom: 0.54545454545455em; margin-bottom: 0.54545454545455em;
/* 6px */ /* 6px */
} }
.rcue-login-register form > input[type="button"], .rcue-login-register div.form-buttons {
.rcue-login-register form > input[type="submit"]{ display: inline;
float: right; float: right;
margin-top: 0.76923076923077em; margin-top: 0.76923076923077em;
/* 10px */ /* 10px */
} }

View file

@ -22,7 +22,10 @@
</div> </div>
</#list> </#list>
<input class="btn-primary" type="submit" value="Log In"/> <div class="form-buttons">
<input class="btn-primary" name="login" type="submit" value="Log In"/>
<input class="btn-secondary" name="cancel" type="submit" value="Cancel"/>
</div>
<div class="aside-btn"> <div class="aside-btn">
<p>Forgot <a href="${url.loginPasswordResetUrl}">Password</a>?</p> <p>Forgot <a href="${url.loginPasswordResetUrl}">Password</a>?</p>

View file

@ -199,6 +199,10 @@ public class TokenService {
return oauth.forwardToSecurityFailure("Login requester not enabled."); return oauth.forwardToSecurityFailure("Login requester not enabled.");
} }
if (formData.containsKey("cancel")) {
return oauth.redirectError(client, "access_denied", state, redirect);
}
String username = formData.getFirst("username"); String username = formData.getFirst("username");
UserModel user = realm.getUser(username); UserModel user = realm.getUser(username);

View file

@ -93,7 +93,7 @@ public class OAuthClient {
driver.findElement(By.id("username")).sendKeys(username); driver.findElement(By.id("username")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password); driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.cssSelector("input[type=\"submit\"]")).click(); driver.findElement(By.name("login")).click();
return new AuthorizationCodeResponse(this); return new AuthorizationCodeResponse(this);
} }
@ -103,7 +103,7 @@ public class OAuthClient {
driver.findElement(By.id("username")).sendKeys(username); driver.findElement(By.id("username")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password); driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.cssSelector("input[type=\"submit\"]")).click(); driver.findElement(By.name("login")).click();
} }
public AccessTokenResponse doAccessTokenRequest(String code, String password) { public AccessTokenResponse doAccessTokenRequest(String code, String password) {

View file

@ -25,6 +25,7 @@ import org.junit.Assert;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.keycloak.testsuite.OAuthClient;
import org.keycloak.testsuite.pages.AppPage; import org.keycloak.testsuite.pages.AppPage;
import org.keycloak.testsuite.pages.AppPage.RequestType; import org.keycloak.testsuite.pages.AppPage.RequestType;
import org.keycloak.testsuite.pages.LoginPage; import org.keycloak.testsuite.pages.LoginPage;
@ -44,6 +45,10 @@ public class LoginTest {
@Rule @Rule
public WebRule webRule = new WebRule(this); public WebRule webRule = new WebRule(this);
@WebResource
protected OAuthClient oauth;
@WebResource @WebResource
protected WebDriver driver; protected WebDriver driver;
@ -79,6 +84,17 @@ public class LoginTest {
loginPage.login("test-user@localhost", "password"); loginPage.login("test-user@localhost", "password");
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType()); Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
Assert.assertNotNull(oauth.getCurrentQuery().get("code"));
}
@Test
public void loginCancel() {
loginPage.open();
loginPage.cancel();
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
Assert.assertEquals("access_denied", oauth.getCurrentQuery().get("error"));
} }
} }

View file

@ -44,9 +44,12 @@ public class LoginPage extends AbstractPage {
@FindBy(id = "totp") @FindBy(id = "totp")
private WebElement totp; private WebElement totp;
@FindBy(css = "input[type=\"submit\"]") @FindBy(name = "login")
private WebElement submitButton; private WebElement submitButton;
@FindBy(name = "cancel")
private WebElement cancelButton;
@FindBy(linkText = "Register") @FindBy(linkText = "Register")
private WebElement registerLink; private WebElement registerLink;
@ -66,6 +69,10 @@ public class LoginPage extends AbstractPage {
submitButton.click(); submitButton.click();
} }
public void cancel() {
cancelButton.click();
}
public void loginTotp(String username, String password, String code) { public void loginTotp(String username, String password, String code) {
usernameInput.clear(); usernameInput.clear();
usernameInput.sendKeys(username); usernameInput.sendKeys(username);