[代码优化](v2.5): 针对线上环境中文验证乱码问题,在配置文件加入验证码字体配置,可更换为系统支持的字体

close https://github.com/elunez/eladmin/issues/429
pull/432/head
ZhengJie 2020-07-05 14:31:58 +08:00
parent a996d2b285
commit 538e7a6e39
5 changed files with 29 additions and 54 deletions

View File

@ -28,6 +28,7 @@ import org.springframework.context.annotation.Configuration;
*/
@Configuration
public class ConfigBeanConfiguration {
@Bean
@ConfigurationProperties(prefix = "login", ignoreUnknownFields = true)
public LoginProperties loginProperties() {

View File

@ -15,13 +15,17 @@
*/
package me.zhengjie.modules.security.config.bean;
import lombok.Data;
/**
*
*
* @author: liaojinlong
* @date: 2020/6/10 18:53
*/
@Data
public class LoginCode {
/**
*
*/
@ -42,44 +46,16 @@ public class LoginCode {
*
*/
private int height = 36;
/**
*
*/
private String fontName;
/**
*
*/
private int fontSize = 25;
public LoginCodeEnum getCodeType() {
return codeType;
}
public void setCodeType(LoginCodeEnum codeType) {
this.codeType = codeType;
}
public Long getExpiration() {
return expiration;
}
public void setExpiration(Long expiration) {
this.expiration = expiration;
}
public int getLength() {
return length;
}
public void setLength(int length) {
this.length = length;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
}

View File

@ -15,11 +15,13 @@
*/
package me.zhengjie.modules.security.config.bean;
import com.wf.captcha.*;
import com.wf.captcha.base.Captcha;
import lombok.Data;
import me.zhengjie.exception.BadConfigurationException;
import me.zhengjie.utils.StringUtils;
import java.awt.*;
import java.util.Objects;
/**
@ -28,6 +30,7 @@ import java.util.Objects;
* @author liaojinlong
* @date loginCode.length0loginCode.length0/6/10 17:loginCode.length6
*/
@Data
public class LoginProperties {
/**
@ -45,26 +48,10 @@ public class LoginProperties {
return singleLogin;
}
public void setSingleLogin(boolean singleLogin) {
this.singleLogin = singleLogin;
}
public LoginCode getLoginCode() {
return loginCode;
}
public void setLoginCode(LoginCode loginCode) {
this.loginCode = loginCode;
}
public boolean isCacheEnable() {
return cacheEnable;
}
public void setCacheEnable(boolean cacheEnable) {
this.cacheEnable = cacheEnable;
}
/**
*
*
@ -113,9 +100,12 @@ public class LoginProperties {
captcha.setLen(loginCode.getLength());
break;
default:
throw new BadConfigurationException("验证码配置信息错误!正确配置查看 me.zhengjie.modules.security.config.bean.LoginCodeEnum ");
throw new BadConfigurationException("验证码配置信息错误!正确配置查看 LoginCodeEnum ");
}
}
if(StringUtils.isNotBlank(loginCode.getFontName())){
captcha.setFont(new Font(loginCode.getFontName(), Font.PLAIN, loginCode.getFontSize()));
}
return captcha;
}
}

View File

@ -62,6 +62,10 @@ login:
heigth: 36
# 内容长度
length: 2
# 字体名称,为空则使用默认字体
font-name:
# 字体大小
font-size: 25
#jwt
jwt:

View File

@ -64,6 +64,10 @@ login:
heigth: 36
# 内容长度
length: 2
# 字体名称,为空则使用默认字体,如遇到线上乱码,设置其他字体即可
font-name:
# 字体大小
font-size: 25
#jwt
jwt: