mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-16 05:20:42 +08:00
主题切换支持
主题切换支持 黑色经典 薄荷清新 激情紫荆
This commit is contained in:
@@ -199,6 +199,7 @@ public class UserInfo extends JpaBaseDomain {
|
||||
protected String defineIm;
|
||||
protected int weixinFollow;
|
||||
|
||||
protected String theme;
|
||||
/*
|
||||
* for extended Attribute from userType extraAttribute for database
|
||||
* extraAttributeName & extraAttributeValue for page submit
|
||||
@@ -1238,4 +1239,12 @@ public class UserInfo extends JpaBaseDomain {
|
||||
this.modifiedDate = modifiedDate;
|
||||
}
|
||||
|
||||
public String getTheme() {
|
||||
return theme;
|
||||
}
|
||||
|
||||
public void setTheme(String theme) {
|
||||
this.theme = theme;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -112,7 +112,11 @@ public class UserInfoRowMapper implements RowMapper<UserInfo> {
|
||||
userInfo.setStatus(rs.getInt("STATUS"));
|
||||
userInfo.setGridList(rs.getInt("GRIDLIST"));
|
||||
userInfo.setDescription(rs.getString("DESCRIPTION"));
|
||||
|
||||
userInfo.setTheme(rs.getString("THEME"));
|
||||
if (userInfo.getTheme() == null || userInfo.getTheme().equalsIgnoreCase("")) {
|
||||
userInfo.setTheme("default");
|
||||
}
|
||||
|
||||
return userInfo;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,51 +8,54 @@ package org.maxkey.web;
|
||||
*/
|
||||
public class WebConstants {
|
||||
|
||||
public static final String USERNAME = "username";
|
||||
public static final String USERNAME = "username";
|
||||
|
||||
public static final String REMOTE_USERNAME = "remote_username";
|
||||
public static final String REMOTE_USERNAME = "remote_username";
|
||||
|
||||
public final static String CURRENT_USER = "current_user";
|
||||
public static final String CURRENT_USER = "current_user";
|
||||
|
||||
public final static String CURRENT_USER_SESSION_ID = "current_user_session_id";
|
||||
public static final String CURRENT_USER_SESSION_ID = "current_user_session_id";
|
||||
|
||||
public final static String CURRENT_COMPANY = "current_user_company";
|
||||
public static final String CURRENT_COMPANY = "current_user_company";
|
||||
|
||||
public final static String CURRENT_DEPARTMENT = "current_user_department";
|
||||
public static final String CURRENT_DEPARTMENT = "current_user_department";
|
||||
|
||||
public final static String CURRENT_USER_NAVIGATIONS = "current_user_navigations";
|
||||
public static final String CURRENT_USER_NAVIGATIONS = "current_user_navigations";
|
||||
|
||||
public final static String CURRENT_USER_ROLES = "current_user_roles";
|
||||
public static final String CURRENT_USER_ROLES = "current_user_roles";
|
||||
|
||||
public final static String CURRENT_USER_SYSTEM_ROLES = "current_user_system_roles";
|
||||
|
||||
public final static String CURRENT_LOGIN_USER_PASSWORD_SET_TYPE = "current_login_user_password_set_type";
|
||||
public static final String CURRENT_USER_SYSTEM_ROLES = "current_user_system_roles";
|
||||
|
||||
public final static String CURRENT_MESSAGE = "current_message";
|
||||
public static final String CURRENT_LOGIN_USER_PASSWORD_SET_TYPE
|
||||
= "current_login_user_password_set_type";
|
||||
|
||||
//SPRING_SECURITY_SAVED_REQUEST
|
||||
public final static String SPRING_PROCESS_SAVED_REQUEST = "SPRING_SECURITY_SAVED_REQUEST";
|
||||
public static final String CURRENT_MESSAGE = "current_message";
|
||||
|
||||
public final static String FIRST_SAVED_REQUEST_PARAMETER = "first_saved_request_parameter";
|
||||
// SPRING_SECURITY_SAVED_REQUEST
|
||||
public static final String SPRING_PROCESS_SAVED_REQUEST = "SPRING_SECURITY_SAVED_REQUEST";
|
||||
|
||||
public static final String FIRST_SAVED_REQUEST_PARAMETER = "first_saved_request_parameter";
|
||||
|
||||
public static final String KAPTCHA_SESSION_KEY = "kaptcha_session_key";
|
||||
|
||||
public static final String SINGLE_SIGN_ON_APP_ID = "single_sign_on_app_id";
|
||||
|
||||
public static final String REMEBER_ME_SESSION = "remeber_me_session";
|
||||
|
||||
public static final String KERBEROS_TOKEN_PARAMETER = "kerberosToken";
|
||||
|
||||
public static final String CAS_SERVICE_PARAMETER = "service";
|
||||
|
||||
public static final String KERBEROS_USERDOMAIN_PARAMETER = "kerberosUserDomain";
|
||||
|
||||
public static final String REMEBER_ME_COOKIE = "sign_in_remeber_me";
|
||||
|
||||
public static final String JWT_TOKEN_PARAMETER = "jwt";
|
||||
|
||||
public static final String CURRENT_SINGLESIGNON_URI = "current_singlesignon_uri";
|
||||
|
||||
public static final String AUTHENTICATION = "current_authentication";
|
||||
|
||||
public static final String THEME_COOKIE_NAME = "maxkey_theme";
|
||||
|
||||
public final static String KAPTCHA_SESSION_KEY = "kaptcha_session_key";
|
||||
|
||||
public static final String SINGLE_SIGN_ON_APP_ID = "single_sign_on_app_id";
|
||||
|
||||
public static final String REMEBER_ME_SESSION = "remeber_me_session";
|
||||
|
||||
public static final String KERBEROS_TOKEN_PARAMETER = "kerberosToken";
|
||||
|
||||
public static final String CAS_SERVICE_PARAMETER = "service";
|
||||
|
||||
public static final String KERBEROS_USERDOMAIN_PARAMETER = "kerberosUserDomain";
|
||||
|
||||
public static final String REMEBER_ME_COOKIE = "sign_in_remeber_me";
|
||||
|
||||
public static final String JWT_TOKEN_PARAMETER = "jwt";
|
||||
|
||||
public static final String CURRENT_SINGLESIGNON_URI = "current_singlesignon_uri";
|
||||
|
||||
public static final String AUTHENTICATION = "current_authentication";
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package org.maxkey.web;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.maxkey.authn.BasicAuthentication;
|
||||
@@ -289,6 +295,67 @@ public final class WebContext {
|
||||
return locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据名字获取cookie.
|
||||
*
|
||||
* @param request HttpServletRequest
|
||||
* @param name cookie名字
|
||||
* @return Cookie
|
||||
*/
|
||||
public static Cookie readCookieByName(HttpServletRequest request, String name) {
|
||||
Map<String, Cookie> cookieMap = readCookieAll(request);
|
||||
if (cookieMap.containsKey(name)) {
|
||||
Cookie cookie = (Cookie) cookieMap.get(name);
|
||||
return cookie;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将cookie封装到Map里面.
|
||||
*
|
||||
* @param request HttpServletRequest
|
||||
* @return Map
|
||||
*/
|
||||
private static Map<String, Cookie> readCookieAll(HttpServletRequest request) {
|
||||
Map<String, Cookie> cookieMap = new HashMap<String, Cookie>();
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (null != cookies) {
|
||||
for (Cookie cookie : cookies) {
|
||||
cookieMap.put(cookie.getName(), cookie);
|
||||
}
|
||||
}
|
||||
return cookieMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存Cookies.
|
||||
*
|
||||
* @param response response响应
|
||||
* @param name cookie的名字
|
||||
* @param value cookie的值
|
||||
* @param time cookie的存在时间
|
||||
*/
|
||||
public static HttpServletResponse setCookie(
|
||||
HttpServletResponse response, String name, String value, int time) {
|
||||
// new一个Cookie对象,键值对为参数
|
||||
Cookie cookie = new Cookie(name, value);
|
||||
// tomcat下多应用共享
|
||||
cookie.setPath("/");
|
||||
// 如果cookie的值中含有中文时,需要对cookie进行编码,不然会产生乱码
|
||||
try {
|
||||
URLEncoder.encode(value, "utf-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 单位:秒
|
||||
cookie.setMaxAge(time);
|
||||
// 将Cookie添加到Response中,使之生效
|
||||
response.addCookie(cookie); // addCookie后,如果已经存在相同名字的cookie,则最新的覆盖旧的cookie
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
* get Current Date,eg 2012-07-10.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.maxkey.web.tag;
|
||||
|
||||
import freemarker.core.Environment;
|
||||
import freemarker.template.TemplateDirectiveBody;
|
||||
import freemarker.template.TemplateDirectiveModel;
|
||||
import freemarker.template.TemplateException;
|
||||
import freemarker.template.TemplateModel;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.Cookie;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import org.maxkey.web.WebConstants;
|
||||
import org.maxkey.web.WebContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取主题标签 .<@theme/>
|
||||
*
|
||||
* @author Crystal.Sea
|
||||
*
|
||||
*/
|
||||
|
||||
@FreemarkerTag("theme")
|
||||
public class ThemeTagDirective implements TemplateDirectiveModel {
|
||||
private static final Logger _logger = LoggerFactory.getLogger(ThemeTagDirective.class);
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public void execute(Environment env,
|
||||
Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
|
||||
throws TemplateException, IOException {
|
||||
String theme = null;
|
||||
if (null != WebContext.getUserInfo()) {
|
||||
theme = WebContext.getUserInfo().getTheme();
|
||||
_logger.trace("read theme form login user session , theme is " + theme);
|
||||
}
|
||||
|
||||
if (null == theme) {
|
||||
Cookie themeCookie =
|
||||
WebContext.readCookieByName(request, WebConstants.THEME_COOKIE_NAME);
|
||||
if (themeCookie != null) {
|
||||
theme = themeCookie.getValue();
|
||||
_logger.trace("read theme form cookie , theme is " + theme);
|
||||
}
|
||||
}
|
||||
env.getOut().append(theme == null ? "default" : theme);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user