Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ public Response executeActionsEmail(@QueryParam(OIDCLoginProtocol.REDIRECT_URI_P
throw new WebApplicationException(
ErrorResponse.error("Client is not enabled", Status.BAD_REQUEST));
}
this.session.getContext().setClient(client);

String redirect;
if (redirectUri != null) {
Expand All @@ -827,6 +828,7 @@ public Response executeActionsEmail(@QueryParam(OIDCLoginProtocol.REDIRECT_URI_P

this.session.getProvider(EmailTemplateProvider.class)
.setAttribute(Constants.TEMPLATE_ATTR_REQUIRED_ACTIONS, token.getRequiredActions())
.setAttribute(Constants.CLIENT_ID, clientId)
.setRealm(realm)
.setUser(user)
.sendExecuteActions(link, TimeUnit.SECONDS.toMinutes(lifespan));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import org.keycloak.common.Version;
import org.keycloak.models.ClientModel;
import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel;

import java.util.function.Function;

public class DefaultThemeSelectorProvider implements ThemeSelectorProvider {

public static final String LOGIN_THEME_KEY = "login_theme";
public static final String EMAIL_THEME_KEY = "email_theme";
private static final boolean isAccount2Enabled = Profile.isFeatureEnabled(Profile.Feature.ACCOUNT2);

private final KeycloakSession session;
Expand All @@ -26,21 +30,13 @@ public String getThemeName(Theme.Type type) {
name = Config.scope("theme").get("welcomeTheme");
break;
case LOGIN:
ClientModel client = session.getContext().getClient();
if (client != null) {
name = client.getAttribute(LOGIN_THEME_KEY);
}

if (name == null || name.isEmpty()) {
name = session.getContext().getRealm().getLoginTheme();
}

name = getThemeName(LOGIN_THEME_KEY, RealmModel::getLoginTheme);
break;
case ACCOUNT:
name = session.getContext().getRealm().getAccountTheme();
break;
case EMAIL:
name = session.getContext().getRealm().getEmailTheme();
name = getThemeName(EMAIL_THEME_KEY, RealmModel::getEmailTheme);
break;
case ADMIN:
name = session.getContext().getRealm().getAdminTheme();
Expand All @@ -57,6 +53,20 @@ public String getThemeName(Theme.Type type) {
return name;
}

private String getThemeName(String themeKey, Function<RealmModel, String> fallback) {
ClientModel client = session.getContext().getClient();
String name = null;
if (client != null) {
name = client.getAttribute(themeKey);
}

if (name != null && !name.trim().isEmpty()) {
return name;
}

return fallback.apply(session.getContext().getRealm());
}

@Override
public void close() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@
</div>
<kc-tooltip>{{:: 'login-theme.tooltip' | translate}}</kc-tooltip>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="emailTheme">{{:: 'email-theme' | translate}}</label>
<div class="col-sm-6">
<select class="form-control" id="emailTheme"
ng-model="clientEdit.attributes['email_theme']"
ng-options="o.name as o.name for o in serverInfo.themes.email">
<option value="" selected></option>
</select>
</div>
<kc-tooltip>{{:: 'select-theme-email' | translate}}</kc-tooltip>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="protocol">{{:: 'client-protocol' | translate}}</label>
<div class="col-sm-6">
Expand Down