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

KEYCLOAK-74 email verification fixes
This commit is contained in:
stianst 2013-10-01 07:06:31 -07:00
commit 02d5d709ed
6 changed files with 116 additions and 15 deletions

View file

@ -330,6 +330,12 @@ a.zocial:before {
text-align: right;
}
.rcue-login-register .background-area p.instruction {
font-size: 1.3em;
line-height: 1.3em;
margin-bottom: 1.53846em;
}
.rcue-login-register .background-area p.instruction.instruction.second {
color: #999999;
}

View file

@ -1,24 +1,25 @@
<#import "template-login-action.ftl" as layout>
<@layout.registrationLayout bodyClass=""; section>
<@layout.registrationLayout bodyClass="reset"; section>
<#if section = "title">
Verify email
Email verification
<#elseif section = "header">
Verify email
Email verification
<#elseif section = "form">
<div id="form">
An email with instructions to verify your email address has been sent to you. If you don't receive this email,
<a href="${url.emailVerificationUrl}">click here</a> to re-send the email.
<div class="app-form">
<p class="instruction">
Your account is not enabled. An email with instructions to verify your email address has been sent to you.
</p>
<p class="instruction">Haven't received a verification code in your email?
<a href="${url.emailVerificationUrl}">Click here</a> to re-send the email.
</p>
</div>
<#elseif section = "info" >
<div id="info">
</div>
</#if>
</@layout.registrationLayout>

View file

@ -85,9 +85,15 @@ public class EmailSender {
URI uri = builder.build(realm.getId());
StringBuilder sb = new StringBuilder();
sb.append("Hi ").append(user.getFirstName()).append(",\n\n");
sb.append("Someone has created a Keycloak account with this email address. ");
sb.append("If this was you, click the link below to verify your email address:\n");
sb.append(uri.toString());
sb.append("\n");
sb.append("Expires in " + TimeUnit.SECONDS.toMinutes(realm.getAccessCodeLifespanUserAction()));
sb.append("\n\nThis link will expire within ").append(TimeUnit.SECONDS.toMinutes(realm.getAccessCodeLifespanUserAction()));
sb.append(" minutes.\n\n");
sb.append("If you didn't create this account, just ignore this message.\n\n");
sb.append("Thanks,\n");
sb.append("The Keycloak Team");
try {
send(user.getEmail(), "Verify email", sb.toString());

View file

@ -281,8 +281,6 @@ public class AccountService {
return Response.status(Status.FORBIDDEN).build();
}
new EmailSender().sendEmailVerification(user, realm, accessCode, uriInfo);
return Flows.forms(realm, request, uriInfo).setAccessCode(accessCode).setUser(user)
.forwardToAction(RequiredAction.VERIFY_EMAIL);
}

View file

@ -40,6 +40,7 @@ import org.keycloak.testsuite.pages.AppPage;
import org.keycloak.testsuite.pages.AppPage.RequestType;
import org.keycloak.testsuite.pages.LoginPage;
import org.keycloak.testsuite.pages.RegisterPage;
import org.keycloak.testsuite.pages.VerifyEmailPage;
import org.keycloak.testsuite.rule.GreenMailRule;
import org.keycloak.testsuite.rule.KeycloakRule;
import org.keycloak.testsuite.rule.KeycloakRule.KeycloakSetup;
@ -80,6 +81,9 @@ public class RequiredActionEmailVerificationTest {
@WebResource
protected LoginPage loginPage;
@WebResource
protected VerifyEmailPage verifyEmailPage;
@WebResource
protected RegisterPage registerPage;
@ -88,7 +92,9 @@ public class RequiredActionEmailVerificationTest {
loginPage.open();
loginPage.login("test-user@localhost", "password");
Assert.assertTrue(driver.getPageSource().contains("Verify email"));
Assert.assertTrue(verifyEmailPage.isCurrent());
Assert.assertEquals(1, greenMail.getReceivedMessages().length);
MimeMessage message = greenMail.getReceivedMessages()[0];
@ -111,7 +117,9 @@ public class RequiredActionEmailVerificationTest {
loginPage.clickRegister();
registerPage.register("firstName", "lastName", "email", "verifyEmail", "password", "password");
Assert.assertTrue(driver.getPageSource().contains("Verify email"));
Assert.assertTrue(verifyEmailPage.isCurrent());
Assert.assertEquals(1, greenMail.getReceivedMessages().length);
MimeMessage message = greenMail.getReceivedMessages()[0];
@ -128,4 +136,33 @@ public class RequiredActionEmailVerificationTest {
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
}
@Test
public void verifyEmailResend() throws IOException, MessagingException {
loginPage.open();
loginPage.clickRegister();
registerPage.register("firstName2", "lastName2", "email2", "verifyEmail2", "password2", "password2");
Assert.assertTrue(verifyEmailPage.isCurrent());
Assert.assertEquals(1, greenMail.getReceivedMessages().length);
verifyEmailPage.clickResendEmail();
Assert.assertEquals(2, greenMail.getReceivedMessages().length);
MimeMessage message = greenMail.getReceivedMessages()[1];
String body = (String) message.getContent();
Pattern p = Pattern.compile("(?s).*(http://[^\\s]*).*");
Matcher m = p.matcher(body);
m.matches();
String verificationUrl = m.group(1);
driver.navigate().to(verificationUrl.trim());
Assert.assertEquals(RequestType.AUTH_RESPONSE, appPage.getRequestType());
}
}

View file

@ -0,0 +1,53 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.keycloak.testsuite.pages;
import org.keycloak.testsuite.OAuthClient;
import org.keycloak.testsuite.rule.WebResource;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
/**
* @author <a href="mailto:vrockai@redhat.com">Viliam Rockai</a>
*/
public class VerifyEmailPage extends Page {
@WebResource
protected OAuthClient oauth;
@FindBy(linkText = "Click here")
private WebElement resendEmailLink;
@Override
public void open() {
}
public boolean isCurrent() {
return driver.getTitle().equals("Email verification");
}
public void clickResendEmail() {
resendEmailLink.click();
}
}