refactor:常量类重命名
This commit is contained in:
parent
4603b11326
commit
c7b82047ae
@ -1,21 +1,11 @@
|
|||||||
package com.fanxb.bookmark.business.bookmark.service.impl;
|
package com.fanxb.bookmark.business.bookmark.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.ArrayUtil;
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
|
||||||
import com.fanxb.bookmark.business.api.UserApi;
|
import com.fanxb.bookmark.business.api.UserApi;
|
||||||
import com.fanxb.bookmark.business.bookmark.dao.BookmarkDao;
|
import com.fanxb.bookmark.business.bookmark.dao.BookmarkDao;
|
||||||
import com.fanxb.bookmark.business.bookmark.entity.PinYinBody;
|
|
||||||
import com.fanxb.bookmark.business.bookmark.service.PinYinService;
|
import com.fanxb.bookmark.business.bookmark.service.PinYinService;
|
||||||
import com.fanxb.bookmark.common.constant.Constant;
|
|
||||||
import com.fanxb.bookmark.common.constant.RedisConstant;
|
|
||||||
import com.fanxb.bookmark.common.entity.Bookmark;
|
import com.fanxb.bookmark.common.entity.Bookmark;
|
||||||
import com.fanxb.bookmark.common.entity.UserContext;
|
|
||||||
import com.fanxb.bookmark.common.entity.redis.UserBookmarkUpdate;
|
|
||||||
import com.fanxb.bookmark.common.exception.CustomException;
|
import com.fanxb.bookmark.common.exception.CustomException;
|
||||||
import com.fanxb.bookmark.common.util.HttpUtil;
|
|
||||||
import com.fanxb.bookmark.common.util.RedisUtil;
|
|
||||||
import com.fanxb.bookmark.common.util.UserContextHolder;
|
import com.fanxb.bookmark.common.util.UserContextHolder;
|
||||||
import com.github.houbb.pinyin.constant.enums.PinyinStyleEnum;
|
import com.github.houbb.pinyin.constant.enums.PinyinStyleEnum;
|
||||||
import com.github.houbb.pinyin.util.PinyinHelper;
|
import com.github.houbb.pinyin.util.PinyinHelper;
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
package com.fanxb.bookmark.business.user.constant;
|
package com.fanxb.bookmark.business.user.constant;
|
||||||
|
|
||||||
import com.fanxb.bookmark.common.constant.Constant;
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.io.File;
|
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,7 +6,7 @@ import com.fanxb.bookmark.business.user.dao.UserDao;
|
|||||||
import com.fanxb.bookmark.business.user.service.BaseInfoService;
|
import com.fanxb.bookmark.business.user.service.BaseInfoService;
|
||||||
import com.fanxb.bookmark.business.user.vo.EmailUpdateBody;
|
import com.fanxb.bookmark.business.user.vo.EmailUpdateBody;
|
||||||
import com.fanxb.bookmark.business.user.vo.UpdatePasswordBody;
|
import com.fanxb.bookmark.business.user.vo.UpdatePasswordBody;
|
||||||
import com.fanxb.bookmark.common.constant.Constant;
|
import com.fanxb.bookmark.common.constant.CommonConstant;
|
||||||
import com.fanxb.bookmark.common.entity.MailInfo;
|
import com.fanxb.bookmark.common.entity.MailInfo;
|
||||||
import com.fanxb.bookmark.common.entity.User;
|
import com.fanxb.bookmark.common.entity.User;
|
||||||
import com.fanxb.bookmark.common.exception.CustomException;
|
import com.fanxb.bookmark.common.exception.CustomException;
|
||||||
@ -66,7 +66,7 @@ public class BaseInfoServiceImpl implements BaseInfoService {
|
|||||||
throw new CustomException("密码校验失败,无法更新email");
|
throw new CustomException("密码校验失败,无法更新email");
|
||||||
}
|
}
|
||||||
String secret = UUID.randomUUID().toString().replaceAll("-", "");
|
String secret = UUID.randomUUID().toString().replaceAll("-", "");
|
||||||
String url = VERIFY_EMAIL.replaceAll("XXXX", Constant.serviceAddress + VERIFY_EMAIL_PATH + secret);
|
String url = VERIFY_EMAIL.replaceAll("XXXX", CommonConstant.serviceAddress + VERIFY_EMAIL_PATH + secret);
|
||||||
log.debug(url);
|
log.debug(url);
|
||||||
MailInfo info = new MailInfo(body.getEmail(), "验证邮箱", url);
|
MailInfo info = new MailInfo(body.getEmail(), "验证邮箱", url);
|
||||||
MailUtil.sendMail(info, true);
|
MailUtil.sendMail(info, true);
|
||||||
|
@ -6,7 +6,7 @@ import com.fanxb.bookmark.business.user.dao.UserDao;
|
|||||||
import com.fanxb.bookmark.business.user.service.OauthService;
|
import com.fanxb.bookmark.business.user.service.OauthService;
|
||||||
import com.fanxb.bookmark.business.user.service.UserService;
|
import com.fanxb.bookmark.business.user.service.UserService;
|
||||||
import com.fanxb.bookmark.business.user.vo.OauthBody;
|
import com.fanxb.bookmark.business.user.vo.OauthBody;
|
||||||
import com.fanxb.bookmark.common.constant.Constant;
|
import com.fanxb.bookmark.common.constant.CommonConstant;
|
||||||
import com.fanxb.bookmark.common.entity.User;
|
import com.fanxb.bookmark.common.entity.User;
|
||||||
import com.fanxb.bookmark.common.exception.CustomException;
|
import com.fanxb.bookmark.common.exception.CustomException;
|
||||||
import com.fanxb.bookmark.common.util.HttpUtil;
|
import com.fanxb.bookmark.common.util.HttpUtil;
|
||||||
@ -78,7 +78,7 @@ public class OauthServiceImpl implements OauthService {
|
|||||||
throw new CustomException("不支持的登陆方式" + body.getType());
|
throw new CustomException("不支持的登陆方式" + body.getType());
|
||||||
}
|
}
|
||||||
User newest = dealOauth(current, other);
|
User newest = dealOauth(current, other);
|
||||||
return JwtUtil.encode(Collections.singletonMap("userId", String.valueOf(newest.getUserId())), Constant.jwtSecret
|
return JwtUtil.encode(Collections.singletonMap("userId", String.valueOf(newest.getUserId())), CommonConstant.jwtSecret
|
||||||
, body.isRememberMe() ? LONG_EXPIRE_TIME : SHORT_EXPIRE_TIME);
|
, body.isRememberMe() ? LONG_EXPIRE_TIME : SHORT_EXPIRE_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,8 @@ import com.fanxb.bookmark.business.user.constant.FileConstant;
|
|||||||
import com.fanxb.bookmark.business.user.dao.UserDao;
|
import com.fanxb.bookmark.business.user.dao.UserDao;
|
||||||
import com.fanxb.bookmark.business.user.service.UserService;
|
import com.fanxb.bookmark.business.user.service.UserService;
|
||||||
import com.fanxb.bookmark.business.user.vo.LoginBody;
|
import com.fanxb.bookmark.business.user.vo.LoginBody;
|
||||||
import com.fanxb.bookmark.business.user.vo.LoginRes;
|
|
||||||
import com.fanxb.bookmark.business.user.vo.RegisterBody;
|
import com.fanxb.bookmark.business.user.vo.RegisterBody;
|
||||||
import com.fanxb.bookmark.common.constant.Constant;
|
import com.fanxb.bookmark.common.constant.CommonConstant;
|
||||||
import com.fanxb.bookmark.common.constant.NumberConstant;
|
import com.fanxb.bookmark.common.constant.NumberConstant;
|
||||||
import com.fanxb.bookmark.common.constant.RedisConstant;
|
import com.fanxb.bookmark.common.constant.RedisConstant;
|
||||||
import com.fanxb.bookmark.common.entity.MailInfo;
|
import com.fanxb.bookmark.common.entity.MailInfo;
|
||||||
@ -69,12 +68,12 @@ public class UserServiceImpl implements UserService {
|
|||||||
info.setContent("欢迎注册 签签世界 ,本次验证码");
|
info.setContent("欢迎注册 签签世界 ,本次验证码");
|
||||||
info.setContent(code + " 是您的验证码,注意验证码有效期为15分钟哦!");
|
info.setContent(code + " 是您的验证码,注意验证码有效期为15分钟哦!");
|
||||||
info.setReceiver(email);
|
info.setReceiver(email);
|
||||||
if (Constant.isDev) {
|
if (CommonConstant.isDev) {
|
||||||
code = "123456";
|
code = "123456";
|
||||||
} else {
|
} else {
|
||||||
MailUtil.sendTextMail(info);
|
MailUtil.sendTextMail(info);
|
||||||
}
|
}
|
||||||
RedisUtil.set(Constant.authCodeKey(email), code, Constant.AUTH_CODE_EXPIRE);
|
RedisUtil.set(CommonConstant.authCodeKey(email), code, CommonConstant.AUTH_CODE_EXPIRE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -105,7 +104,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
userDao.addOne(user);
|
userDao.addOne(user);
|
||||||
Map<String, String> data = new HashMap<>(1);
|
Map<String, String> data = new HashMap<>(1);
|
||||||
data.put("userId", String.valueOf(user.getUserId()));
|
data.put("userId", String.valueOf(user.getUserId()));
|
||||||
return JwtUtil.encode(data, Constant.jwtSecret, LONG_EXPIRE_TIME);
|
return JwtUtil.encode(data, CommonConstant.jwtSecret, LONG_EXPIRE_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -130,7 +129,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
redisTemplate.delete(key);
|
redisTemplate.delete(key);
|
||||||
userDao.updateLastLoginTime(System.currentTimeMillis(), userInfo.getUserId());
|
userDao.updateLastLoginTime(System.currentTimeMillis(), userInfo.getUserId());
|
||||||
return JwtUtil.encode(Collections.singletonMap("userId", String.valueOf(userInfo.getUserId())), Constant.jwtSecret
|
return JwtUtil.encode(Collections.singletonMap("userId", String.valueOf(userInfo.getUserId())), CommonConstant.jwtSecret
|
||||||
, body.isRememberMe() ? LONG_EXPIRE_TIME : SHORT_EXPIRE_TIME);
|
, body.isRememberMe() ? LONG_EXPIRE_TIME : SHORT_EXPIRE_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +145,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new FormDataException("用户不存在");
|
throw new FormDataException("用户不存在");
|
||||||
}
|
}
|
||||||
String codeKey = Constant.authCodeKey(body.getEmail());
|
String codeKey = CommonConstant.authCodeKey(body.getEmail());
|
||||||
String realCode = RedisUtil.get(codeKey, String.class);
|
String realCode = RedisUtil.get(codeKey, String.class);
|
||||||
if (StringUtil.isEmpty(realCode) || (!realCode.equals(body.getAuthCode()))) {
|
if (StringUtil.isEmpty(realCode) || (!realCode.equals(body.getAuthCode()))) {
|
||||||
throw new FormDataException("验证码错误");
|
throw new FormDataException("验证码错误");
|
||||||
@ -184,7 +183,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
String fileName = file.getOriginalFilename();
|
String fileName = file.getOriginalFilename();
|
||||||
assert fileName != null;
|
assert fileName != null;
|
||||||
String path = Paths.get(FileConstant.iconPath, userId + "." + System.currentTimeMillis() + fileName.substring(fileName.lastIndexOf("."))).toString();
|
String path = Paths.get(FileConstant.iconPath, userId + "." + System.currentTimeMillis() + fileName.substring(fileName.lastIndexOf("."))).toString();
|
||||||
Path realPath = Paths.get(Constant.fileSavePath, path);
|
Path realPath = Paths.get(CommonConstant.fileSavePath, path);
|
||||||
FileUtil.ensurePathExist(realPath.getParent().toString());
|
FileUtil.ensurePathExist(realPath.getParent().toString());
|
||||||
file.transferTo(realPath);
|
file.transferTo(realPath);
|
||||||
path = File.separator + path;
|
path = File.separator + path;
|
||||||
|
@ -1,95 +1,76 @@
|
|||||||
package com.fanxb.bookmark.common.constant;
|
package com.fanxb.bookmark.common.constant;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类功能简述:系统及常量类
|
* 类功能简述:系统及常量类
|
||||||
* 类功能详述:
|
* 类功能详述:
|
||||||
*
|
*
|
||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @date 2019/4/4 16:10
|
*/
|
||||||
*/
|
@Component
|
||||||
@Component
|
public class CommonConstant {
|
||||||
public class Constant {
|
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
* jwt key
|
||||||
* jwt key
|
*/
|
||||||
*/
|
public static final String JWT_KEY = "jwt-token";
|
||||||
public static final String JWT_KEY = "jwt-token";
|
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
* 验证码过期时间
|
||||||
* 验证码过期时间
|
*/
|
||||||
*/
|
public static int AUTH_CODE_EXPIRE = 15 * 60 * 1000;
|
||||||
public static int AUTH_CODE_EXPIRE = 15 * 60 * 1000;
|
|
||||||
|
/**
|
||||||
/**
|
* Description: 生成email存在redis中的key
|
||||||
* Description: 生成email存在redis中的key
|
*
|
||||||
*
|
* @param email 邮箱地址
|
||||||
* @param email 邮箱地址
|
* @return java.lang.String
|
||||||
* @return java.lang.String
|
* @author fanxb
|
||||||
* @author fanxb
|
* @date 2019/7/6 10:56
|
||||||
* @date 2019/7/6 10:56
|
*/
|
||||||
*/
|
public static String authCodeKey(String email) {
|
||||||
public static String authCodeKey(String email) {
|
return email + "_authCode";
|
||||||
return email + "_authCode";
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* 是否为开发环境
|
||||||
* 是否为开发环境
|
*/
|
||||||
*/
|
public static boolean isDev = false;
|
||||||
public static boolean isDev = false;
|
|
||||||
|
@Value("${spring.profiles.active}")
|
||||||
@Value("${spring.profiles.active}")
|
public void setIsDev(String active) {
|
||||||
public void setIsDev(String active) {
|
CommonConstant.isDev = active.contains("dev");
|
||||||
Constant.isDev = active.contains("dev");
|
}
|
||||||
}
|
|
||||||
|
public static String jwtSecret = "";
|
||||||
public static String jwtSecret = "";
|
|
||||||
|
@Value("${jwtSecret}")
|
||||||
@Value("${jwtSecret}")
|
public void setJwtSecret(String jwtSecret) {
|
||||||
public void setJwtSecret(String jwtSecret) {
|
CommonConstant.jwtSecret = jwtSecret;
|
||||||
Constant.jwtSecret = jwtSecret;
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
/**
|
* 文件存储基路径
|
||||||
* 文件存储基路径
|
*/
|
||||||
*/
|
public static String fileSavePath = "./";
|
||||||
public static String fileSavePath = "./";
|
|
||||||
|
@Value("${fileSavePath}")
|
||||||
@Value("${fileSavePath}")
|
public void setFileSavePath(String path) {
|
||||||
public void setFileSavePath(String path) {
|
fileSavePath = path;
|
||||||
fileSavePath = path;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
* 服务部署地址
|
||||||
* 服务部署地址
|
*/
|
||||||
*/
|
public static String serviceAddress = "http://localhost";
|
||||||
public static String serviceAddress = "http://localhost";
|
|
||||||
|
@Value("${serviceAddress}")
|
||||||
@Value("${serviceAddress}")
|
public void setServiceAddress(String address) {
|
||||||
public void setServiceAddress(String address) {
|
serviceAddress = address;
|
||||||
serviceAddress = address;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 拼音服务调用地址
|
|
||||||
*/
|
|
||||||
public static String pinyinBaseUrl;
|
|
||||||
@Value("${pinyin.base-url}")
|
|
||||||
public void setPinyinBaseUrl(String baseUrl){
|
|
||||||
pinyinBaseUrl=baseUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调用拼音服务token
|
|
||||||
*/
|
|
||||||
public static String pinyinToken;
|
|
||||||
@Value("${pinyin.token}")
|
|
||||||
public void setPinyinToken(String pinyinToken) {
|
|
||||||
Constant.pinyinToken = pinyinToken;
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,7 +2,7 @@ package com.fanxb.bookmark.common.filter;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.auth0.jwt.interfaces.Claim;
|
import com.auth0.jwt.interfaces.Claim;
|
||||||
import com.fanxb.bookmark.common.constant.Constant;
|
import com.fanxb.bookmark.common.constant.CommonConstant;
|
||||||
import com.fanxb.bookmark.common.dao.UrlDao;
|
import com.fanxb.bookmark.common.dao.UrlDao;
|
||||||
import com.fanxb.bookmark.common.entity.Result;
|
import com.fanxb.bookmark.common.entity.Result;
|
||||||
import com.fanxb.bookmark.common.entity.Url;
|
import com.fanxb.bookmark.common.entity.Url;
|
||||||
@ -100,7 +100,7 @@ public class LoginFilter implements Filter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//登陆用户
|
//登陆用户
|
||||||
if (this.checkJwt(request.getHeader(Constant.JWT_KEY))) {
|
if (this.checkJwt(request.getHeader(CommonConstant.JWT_KEY))) {
|
||||||
try {
|
try {
|
||||||
filterChain.doFilter(servletRequest, servletResponse);
|
filterChain.doFilter(servletRequest, servletResponse);
|
||||||
} finally {
|
} finally {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user