KEYCLOAK-1113 - user registration form input boxes and labels are red on
error (css class is configurable in theme, has-error used for patternfly)
This commit is contained in:
parent
8727aef647
commit
31a80a973c
4 changed files with 88 additions and 15 deletions
|
@ -7,7 +7,7 @@
|
||||||
<#elseif section = "form">
|
<#elseif section = "form">
|
||||||
<form id="kc-register-form" class="${properties.kcFormClass!}" action="${url.registrationAction}" method="post">
|
<form id="kc-register-form" class="${properties.kcFormClass!}" action="${url.registrationAction}" method="post">
|
||||||
<#if !realm.registrationEmailAsUsername>
|
<#if !realm.registrationEmailAsUsername>
|
||||||
<div class="${properties.kcFormGroupClass!}">
|
<div class="${properties.kcFormGroupClass!} ${messagesPerField.printIfExists('username',properties.kcFormGroupErrorClass!)}">
|
||||||
<div class="${properties.kcLabelWrapperClass!}">
|
<div class="${properties.kcLabelWrapperClass!}">
|
||||||
<label for="username" class="${properties.kcLabelClass!}">${msg("username")}</label>
|
<label for="username" class="${properties.kcLabelClass!}">${msg("username")}</label>
|
||||||
</div>
|
</div>
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</#if>
|
</#if>
|
||||||
<div class="${properties.kcFormGroupClass!}">
|
<div class="${properties.kcFormGroupClass!} ${messagesPerField.printIfExists('firstName',properties.kcFormGroupErrorClass!)}">
|
||||||
<div class="${properties.kcLabelWrapperClass!}">
|
<div class="${properties.kcLabelWrapperClass!}">
|
||||||
<label for="firstName" class="${properties.kcLabelClass!}">${msg("firstName")}</label>
|
<label for="firstName" class="${properties.kcLabelClass!}">${msg("firstName")}</label>
|
||||||
</div>
|
</div>
|
||||||
|
@ -25,7 +25,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="${properties.kcFormGroupClass!}">
|
<div class="${properties.kcFormGroupClass!} ${messagesPerField.printIfExists('lastName',properties.kcFormGroupErrorClass!)}">
|
||||||
<div class="${properties.kcLabelWrapperClass!}">
|
<div class="${properties.kcLabelWrapperClass!}">
|
||||||
<label for="lastName" class="${properties.kcLabelClass!}">${msg("lastName")}</label>
|
<label for="lastName" class="${properties.kcLabelClass!}">${msg("lastName")}</label>
|
||||||
</div>
|
</div>
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="${properties.kcFormGroupClass!}">
|
<div class="${properties.kcFormGroupClass!} ${messagesPerField.printIfExists('email',properties.kcFormGroupErrorClass!)}">
|
||||||
<div class="${properties.kcLabelWrapperClass!}">
|
<div class="${properties.kcLabelWrapperClass!}">
|
||||||
<label for="email" class="${properties.kcLabelClass!}">${msg("email")}</label>
|
<label for="email" class="${properties.kcLabelClass!}">${msg("email")}</label>
|
||||||
</div>
|
</div>
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="${properties.kcFormGroupClass!}">
|
<div class="${properties.kcFormGroupClass!} ${messagesPerField.printIfExists('password',properties.kcFormGroupErrorClass!)}">
|
||||||
<div class="${properties.kcLabelWrapperClass!}">
|
<div class="${properties.kcLabelWrapperClass!}">
|
||||||
<label for="password" class="${properties.kcLabelClass!}">${msg("password")}</label>
|
<label for="password" class="${properties.kcLabelClass!}">${msg("password")}</label>
|
||||||
</div>
|
</div>
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="${properties.kcFormGroupClass!}">
|
<div class="${properties.kcFormGroupClass!} ${messagesPerField.printIfExists('password-confirm',properties.kcFormGroupErrorClass!)}">
|
||||||
<div class="${properties.kcLabelWrapperClass!}">
|
<div class="${properties.kcLabelWrapperClass!}">
|
||||||
<label for="password-confirm" class="${properties.kcLabelClass!}">${msg("passwordConfirm")}</label>
|
<label for="password-confirm" class="${properties.kcLabelClass!}">${msg("passwordConfirm")}</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -18,6 +18,7 @@ kcFormAreaClass=col-xs-12 col-sm-8 col-md-8 col-lg-6 login
|
||||||
|
|
||||||
kcFormClass=form-horizontal
|
kcFormClass=form-horizontal
|
||||||
kcFormGroupClass=form-group
|
kcFormGroupClass=form-group
|
||||||
|
kcFormGroupErrorClass=has-error
|
||||||
kcLabelClass=control-label
|
kcLabelClass=control-label
|
||||||
kcLabelWrapperClass=col-xs-12 col-sm-12 col-md-4 col-lg-3
|
kcLabelWrapperClass=col-xs-12 col-sm-12 col-md-4 col-lg-3
|
||||||
kcInputClass=form-control
|
kcInputClass=form-control
|
||||||
|
|
|
@ -16,6 +16,7 @@ import org.keycloak.login.freemarker.model.CodeBean;
|
||||||
import org.keycloak.freemarker.beans.LocaleBean;
|
import org.keycloak.freemarker.beans.LocaleBean;
|
||||||
import org.keycloak.login.freemarker.model.LoginBean;
|
import org.keycloak.login.freemarker.model.LoginBean;
|
||||||
import org.keycloak.login.freemarker.model.MessageBean;
|
import org.keycloak.login.freemarker.model.MessageBean;
|
||||||
|
import org.keycloak.login.freemarker.model.MessagesPerFieldBean;
|
||||||
import org.keycloak.login.freemarker.model.OAuthGrantBean;
|
import org.keycloak.login.freemarker.model.OAuthGrantBean;
|
||||||
import org.keycloak.login.freemarker.model.ProfileBean;
|
import org.keycloak.login.freemarker.model.ProfileBean;
|
||||||
import org.keycloak.login.freemarker.model.RealmBean;
|
import org.keycloak.login.freemarker.model.RealmBean;
|
||||||
|
@ -186,25 +187,20 @@ import java.util.concurrent.TimeUnit;
|
||||||
messagesBundle = new Properties();
|
messagesBundle = new Properties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MessagesPerFieldBean messagesPerField = new MessagesPerFieldBean();
|
||||||
if (messages != null) {
|
if (messages != null) {
|
||||||
Map<String, MessageBean> messagesPerField = new HashMap<String, MessageBean>();
|
|
||||||
MessageBean wholeMessage = new MessageBean(null, messageType);
|
MessageBean wholeMessage = new MessageBean(null, messageType);
|
||||||
for (FormMessage message : this.messages) {
|
for (FormMessage message : this.messages) {
|
||||||
String formattedMessageText = formatMessageMessage(message, messagesBundle, locale);
|
String formattedMessageText = formatMessageMessage(message, messagesBundle, locale);
|
||||||
if (formattedMessageText != null) {
|
if (formattedMessageText != null) {
|
||||||
wholeMessage.appendSummaryLine(formattedMessageText);
|
wholeMessage.appendSummaryLine(formattedMessageText);
|
||||||
MessageBean fm = messagesPerField.get(message.getField());
|
messagesPerField.addMessage(message.getField(), formattedMessageText, messageType);
|
||||||
if (fm == null) {
|
|
||||||
messagesPerField.put(message.getField(), new MessageBean(formattedMessageText, messageType));
|
|
||||||
} else {
|
|
||||||
fm.appendSummaryLine(formattedMessageText);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes.put("message", wholeMessage);
|
attributes.put("message", wholeMessage);
|
||||||
attributes.put("messagePerField", messagesPerField);
|
|
||||||
}
|
}
|
||||||
|
attributes.put("messagesPerField", messagesPerField);
|
||||||
|
|
||||||
if (page == LoginFormsPages.OAUTH_GRANT) {
|
if (page == LoginFormsPages.OAUTH_GRANT) {
|
||||||
// for some reason Resteasy 2.3.7 doesn't like query params and form params with the same name and will null out the code form param
|
// for some reason Resteasy 2.3.7 doesn't like query params and form params with the same name and will null out the code form param
|
||||||
uriBuilder.replaceQuery(null);
|
uriBuilder.replaceQuery(null);
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* JBoss, Home of Professional Open Source
|
||||||
|
* Copyright 2015 Red Hat Inc. and/or its affiliates and other contributors
|
||||||
|
* as indicated by the @authors tag. All rights reserved.
|
||||||
|
*/
|
||||||
|
package org.keycloak.login.freemarker.model;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.keycloak.login.FormMessage;
|
||||||
|
import org.keycloak.login.freemarker.FreeMarkerLoginFormsProvider.MessageType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bean used to hold form messages per field. Stored under <code>messagesPerField</code> key in Freemarker context.
|
||||||
|
*
|
||||||
|
* @author Vlastimil Elias (velias at redhat dot com)
|
||||||
|
*/
|
||||||
|
public class MessagesPerFieldBean {
|
||||||
|
|
||||||
|
private Map<String, MessageBean> messagesPerField = new HashMap<String, MessageBean>();
|
||||||
|
|
||||||
|
public void addMessage(String field, String messageText, MessageType messageType) {
|
||||||
|
if (messageText == null || messageText.trim().isEmpty())
|
||||||
|
return;
|
||||||
|
if (field == null)
|
||||||
|
field = FormMessage.GLOBAL;
|
||||||
|
|
||||||
|
MessageBean fm = messagesPerField.get(field);
|
||||||
|
if (fm == null) {
|
||||||
|
messagesPerField.put(field, new MessageBean(messageText, messageType));
|
||||||
|
} else {
|
||||||
|
fm.appendSummaryLine(messageText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if message for given field exists
|
||||||
|
*
|
||||||
|
* @param field
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean exists(String field) {
|
||||||
|
return messagesPerField.containsKey(field);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get message for given field.
|
||||||
|
*
|
||||||
|
* @param fieldName
|
||||||
|
* @return message text or empty string
|
||||||
|
*/
|
||||||
|
public String get(String fieldName) {
|
||||||
|
MessageBean mb = messagesPerField.get(fieldName);
|
||||||
|
if (mb != null) {
|
||||||
|
return mb.getSummary();
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print text if message for given field exists. Useful eg. to add css styles for fields with message.
|
||||||
|
*
|
||||||
|
* @param fieldName to check for
|
||||||
|
* @param text to print
|
||||||
|
* @return text if message exists for given field, else empty string
|
||||||
|
*/
|
||||||
|
public String printIfExists(String fieldName, String text) {
|
||||||
|
if (exists(fieldName))
|
||||||
|
return text;
|
||||||
|
else
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue