KEYCLOAK-211 Enable social only login

This commit is contained in:
Stian Thorgersen 2014-04-30 11:57:44 +01:00
parent 84396d0da1
commit 8fa3425886
2 changed files with 66 additions and 45 deletions

View file

@ -5,66 +5,76 @@
<#elseif section = "header"> <#elseif section = "header">
${rb.loginTitle} <strong>${(realm.name)!''}</strong> ${rb.loginTitle} <strong>${(realm.name)!''}</strong>
<#elseif section = "form"> <#elseif section = "form">
<form id="kc-form-login" class="${properties.kcFormClass!}" action="${url.loginAction}" method="post"> <#if realm.password>
<div class="${properties.kcFormGroupClass!}"> <form id="kc-form-login" class="${properties.kcFormClass!}" action="${url.loginAction}" method="post">
<div class="${properties.kcLabelWrapperClass!}"> <div class="${properties.kcFormGroupClass!}">
<label for="username" class="${properties.kcLabelClass!}">${rb.usernameOrEmail}</label> <div class="${properties.kcLabelWrapperClass!}">
<label for="username" class="${properties.kcLabelClass!}">${rb.usernameOrEmail}</label>
</div>
<div class="${properties.kcInputWrapperClass!}">
<input id="username" class="${properties.kcInputClass!}" name="username" value="${login.username!''}" type="text" autofocus />
</div>
</div> </div>
<div class="${properties.kcInputWrapperClass!}"> <div class="${properties.kcFormGroupClass!}">
<input id="username" class="${properties.kcInputClass!}" name="username" value="${login.username!''}" type="text" autofocus /> <div class="${properties.kcLabelWrapperClass!}">
</div> <label for="password" class="${properties.kcLabelClass!}">${rb.password}</label>
</div> </div>
<div class="${properties.kcFormGroupClass!}"> <div class="${properties.kcInputWrapperClass!}">
<div class="${properties.kcLabelWrapperClass!}"> <input id="password" class="${properties.kcInputClass!}" name="password" type="password" />
<label for="password" class="${properties.kcLabelClass!}">${rb.password}</label> </div>
</div> </div>
<div class="${properties.kcInputWrapperClass!}"> <div class="${properties.kcFormGroupClass!}">
<input id="password" class="${properties.kcInputClass!}" name="password" type="password" /> <div id="kc-form-options" class="${properties.kcFormOptionsClass!}">
</div> <#if realm.rememberMe>
</div> <div class="checkbox">
<label>
<div class="${properties.kcFormGroupClass!}"> <input id="rememberMe" name="rememberMe" type="checkbox" tabindex="3"> Remember Me
<div id="kc-form-options" class="${properties.kcFormOptionsClass!}"> </label>
<#if realm.rememberMe> </div>
<div class="checkbox">
<label>
<input id="rememberMe" name="rememberMe" type="checkbox" tabindex="3"> Remember Me
</label>
</div>
</#if>
<div class="${properties.kcFormOptionsWrapperClass!}">
<#if realm.resetPasswordAllowed>
<span>${rb.loginForgot} <a href="${url.loginPasswordResetUrl}">${rb.password}</a>?</span>
</#if> </#if>
<div class="${properties.kcFormOptionsWrapperClass!}">
<#if realm.resetPasswordAllowed>
<span>${rb.loginForgot} <a href="${url.loginPasswordResetUrl}">${rb.password}</a>?</span>
</#if>
</div>
</div> </div>
</div>
<div id="kc-form-buttons" class="${properties.kcFormButtonsClass!}"> <div id="kc-form-buttons" class="${properties.kcFormButtonsClass!}">
<div class="${properties.kcFormButtonsWrapperClass!}"> <div class="${properties.kcFormButtonsWrapperClass!}">
<input class="btn btn-primary btn-lg" name="login" id="kc-login" type="submit" value="${rb.logIn}"/> <input class="btn btn-primary btn-lg" name="login" id="kc-login" type="submit" value="${rb.logIn}"/>
<input class="btn btn-default btn-lg" name="cancel" id="kc-cancel" type="submit" value="${rb.cancel}"/> <input class="btn btn-default btn-lg" name="cancel" id="kc-cancel" type="submit" value="${rb.cancel}"/>
</div> </div>
</div> </div>
</div>
</form>
<#elseif realm.social>
<div id="kc-social-providers">
<ul>
<#list social.providers as p>
<li><a href="${p.loginUrl}" class="zocial ${p.id}"> <span class="text">${p.name}</span></a></li>
</#list>
</ul>
</div> </div>
</form> </#if>
<#elseif section = "info" > <#elseif section = "info" >
<#if realm.registrationAllowed> <#if realm.password && realm.registrationAllowed>
<div id="kc-registration"> <div id="kc-registration">
<span>${rb.noAccount} <a href="${url.registrationUrl}">${rb.register}</a></span> <span>${rb.noAccount} <a href="${url.registrationUrl}">${rb.register}</a></span>
</div> </div>
</#if> </#if>
<#if social.providers??> <#if realm.password && social.providers??>
<div id="kc-social-providers"> <div id="kc-social-providers">
<ul> <ul>
<#list social.providers as p> <#list social.providers as p>
<li><a href="${p.loginUrl}" class="zocial ${p.id}"> <span class="text">${p.name}</span></a></li> <li><a href="${p.loginUrl}" class="zocial ${p.id}"> <span class="text">${p.name}</span></a></li>
</#list> </#list>
</ul> </ul>
</div> </div>
</#if> </#if>
</#if> </#if>
</@layout.registrationLayout> </@layout.registrationLayout>

View file

@ -22,6 +22,8 @@
package org.keycloak.login.freemarker.model; package org.keycloak.login.freemarker.model;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.RequiredCredentialModel;
import org.keycloak.representations.idm.CredentialRepresentation;
/** /**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a> * @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
@ -53,5 +55,14 @@ public class RealmBean {
public boolean isRememberMe() { public boolean isRememberMe() {
return realm.isRememberMe(); return realm.isRememberMe();
} }
public boolean isPassword() {
for (RequiredCredentialModel r : realm.getRequiredCredentials()) {
if (r.getType().equals(CredentialRepresentation.PASSWORD)) {
return true;
}
}
return false;
}
} }