Merge branch 'wx-dev' of https://github.com/rymcu/forest into wx-dev

This commit is contained in:
ronger 2021-12-17 19:59:50 +08:00
commit c2febadf5d
8 changed files with 97 additions and 111 deletions

View File

@ -163,7 +163,7 @@
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId> <artifactId>log4j-to-slf4j</artifactId>
<version>2.15.0</version> <version>2.16.0</version>
<exclusions> <exclusions>
<exclusion> <exclusion>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
@ -174,7 +174,7 @@
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId> <artifactId>log4j-api</artifactId>
<version>2.15.0</version> <version>2.16.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

View File

@ -37,7 +37,7 @@ public class SecurityAspect {
Logger logger = LoggerFactory.getLogger(SecurityAspect.class); Logger logger = LoggerFactory.getLogger(SecurityAspect.class);
@Pointcut("@annotation(com.rymcu.forest.core.service.security.annotation.SecurityInterceptor)") @Pointcut("@annotation(com.rymcu.forest.core.service.security.annotation.SecurityInterceptor)")
public void pointCut() { public void securityPointCut() {
} }
/** /**
@ -47,7 +47,7 @@ public class SecurityAspect {
* @return 方法执行结果 * @return 方法执行结果
* @throws Throwable 调用出错 * @throws Throwable 调用出错
*/ */
@Before(value = "pointCut()") @Before(value = "securityPointCut()")
public void doBefore(JoinPoint joinPoint) throws BaseApiException { public void doBefore(JoinPoint joinPoint) throws BaseApiException {
logger.info("检查用户修改信息权限 start ..."); logger.info("检查用户修改信息权限 start ...");
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();

View File

@ -3,14 +3,16 @@ package com.rymcu.forest.jwt.service;
import com.rymcu.forest.jwt.def.JwtConstants; import com.rymcu.forest.jwt.def.JwtConstants;
import com.rymcu.forest.jwt.model.TokenModel; import com.rymcu.forest.jwt.model.TokenModel;
import com.rymcu.forest.service.UserService;
import io.jsonwebtoken.Jwts; import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm; import io.jsonwebtoken.SignatureAlgorithm;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date; import java.util.Date;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -21,17 +23,20 @@ import java.util.concurrent.TimeUnit;
*/ */
@Component @Component
public class RedisTokenManager implements TokenManager { public class RedisTokenManager implements TokenManager {
@Autowired @Autowired
private StringRedisTemplate redisTemplate; private StringRedisTemplate redisTemplate;
@Resource
private UserService userService;
/** /**
* 生成TOKEN * 生成TOKEN
*/ */
@Override @Override
public String createToken(String id) { public String createToken(String id) {
//使用uuid作为源token //使用 account 作为源 token
String token = Jwts.builder().setId(id).setSubject(id).setIssuedAt(new Date()).signWith(SignatureAlgorithm.HS256, JwtConstants.JWT_SECRET).compact(); String token = Jwts.builder().setId(id).setSubject(id).setIssuedAt(new Date()).signWith(SignatureAlgorithm.HS256, JwtConstants.JWT_SECRET).compact();
//存储到redis并设置过期时间 //存储到 redis 并设置过期时间
redisTemplate.boundValueOps(id).set(token, JwtConstants.TOKEN_EXPIRES_HOUR, TimeUnit.HOURS); redisTemplate.boundValueOps(id).set(token, JwtConstants.TOKEN_EXPIRES_HOUR, TimeUnit.HOURS);
return token; return token;
} }
@ -46,15 +51,20 @@ public class RedisTokenManager implements TokenManager {
if (model == null) { if (model == null) {
return false; return false;
} }
String token = (String) redisTemplate.boundValueOps(model.getUsername()).get(); String token = redisTemplate.boundValueOps(model.getUsername()).get();
if (token == null || !token.equals(model.getToken())) { if (token == null || !token.equals(model.getToken())) {
return false; return false;
} }
//如果验证成功说明此用户进行了一次有效操作延长token的过期时间 // 如果验证成功说明此用户进行了一次有效操作延长 token 的过期时间
redisTemplate.boundValueOps(model.getUsername()).expire(JwtConstants.TOKEN_EXPIRES_HOUR, TimeUnit.HOURS); redisTemplate.boundValueOps(model.getUsername()).expire(JwtConstants.TOKEN_EXPIRES_HOUR, TimeUnit.HOURS);
StringBuilder key = new StringBuilder(); StringBuilder key = new StringBuilder();
key.append(JwtConstants.LAST_ONLINE).append(model.getUsername()); key.append(JwtConstants.LAST_ONLINE).append(model.getUsername());
String result = redisTemplate.boundValueOps(key.toString()).get();
if (StringUtils.isBlank(result)) {
// 更新最后在线时间
userService.updateLastOnlineTimeByEmail(model.getUsername());
redisTemplate.boundValueOps(key.toString()).set(LocalDateTime.now().toString(), JwtConstants.LAST_ONLINE_EXPIRES_MINUTE, TimeUnit.MINUTES); redisTemplate.boundValueOps(key.toString()).set(LocalDateTime.now().toString(), JwtConstants.LAST_ONLINE_EXPIRES_MINUTE, TimeUnit.MINUTES);
}
return true; return true;
} }

View File

@ -15,6 +15,7 @@ import com.rymcu.forest.service.TagService;
import com.rymcu.forest.service.UserService; import com.rymcu.forest.service.UserService;
import com.rymcu.forest.util.*; import com.rymcu.forest.util.*;
import com.rymcu.forest.web.api.exception.BaseApiException; import com.rymcu.forest.web.api.exception.BaseApiException;
import com.rymcu.forest.web.api.exception.ErrorCode;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.text.StringEscapeUtils; import org.apache.commons.text.StringEscapeUtils;
@ -46,24 +47,21 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
@Value("${resource.domain}") @Value("${resource.domain}")
private String domain; private String domain;
@Value("${env}")
private String env;
private static final int MAX_PREVIEW = 200; private static final int MAX_PREVIEW = 200;
private static final String defaultStatus = "0"; private static final String DEFAULT_STATUS = "0";
private static final String defaultTopicUri = "news"; private static final String DEFAULT_TOPIC_URI = "news";
private static final int ADMIN_ROLE_WEIGHTS = 2;
@Override @Override
public List<ArticleDTO> findArticles(ArticleSearchDTO searchDTO) { public List<ArticleDTO> findArticles(ArticleSearchDTO searchDTO) {
List<ArticleDTO> list; List<ArticleDTO> list;
if (StringUtils.isNotBlank(searchDTO.getTopicUri()) && !defaultTopicUri.equals(searchDTO.getTopicUri())) { if (StringUtils.isNotBlank(searchDTO.getTopicUri()) && !DEFAULT_TOPIC_URI.equals(searchDTO.getTopicUri())) {
list = articleMapper.selectArticlesByTopicUri(searchDTO.getTopicUri()); list = articleMapper.selectArticlesByTopicUri(searchDTO.getTopicUri());
} else { } else {
list = articleMapper.selectArticles(searchDTO.getSearchText(), searchDTO.getTag(), searchDTO.getTopicUri()); list = articleMapper.selectArticles(searchDTO.getSearchText(), searchDTO.getTag(), searchDTO.getTopicUri());
} }
list.forEach(article -> { list.forEach(articleDTO -> genArticle(articleDTO, 0));
genArticle(article, 0);
});
return list; return list;
} }
@ -73,31 +71,26 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
if (articleDTO == null) { if (articleDTO == null) {
return null; return null;
} }
articleDTO = genArticle(articleDTO, type); genArticle(articleDTO, type);
return articleDTO; return articleDTO;
} }
@Override @Override
public List<ArticleDTO> findArticlesByTopicUri(String name) { public List<ArticleDTO> findArticlesByTopicUri(String name) {
List<ArticleDTO> articleDTOS = articleMapper.selectArticlesByTopicUri(name); List<ArticleDTO> list = articleMapper.selectArticlesByTopicUri(name);
articleDTOS.forEach(articleDTO -> { list.forEach(articleDTO -> genArticle(articleDTO, 0));
genArticle(articleDTO, 0); return list;
});
return articleDTOS;
} }
@Override @Override
public List<ArticleDTO> findArticlesByTagName(String name) { public List<ArticleDTO> findArticlesByTagName(String name) {
List<ArticleDTO> articleDTOS = articleMapper.selectArticlesByTagName(name); return articleMapper.selectArticlesByTagName(name);
return articleDTOS;
} }
@Override @Override
public List<ArticleDTO> findUserArticlesByIdUser(Integer idUser) { public List<ArticleDTO> findUserArticlesByIdUser(Integer idUser) {
List<ArticleDTO> list = articleMapper.selectUserArticles(idUser); List<ArticleDTO> list = articleMapper.selectUserArticles(idUser);
list.forEach(article -> { list.forEach(articleDTO -> genArticle(articleDTO, 0));
genArticle(article, 0);
});
return list; return list;
} }
@ -119,11 +112,14 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
String articleContent = article.getArticleContent(); String articleContent = article.getArticleContent();
String articleContentHtml = article.getArticleContentHtml(); String articleContentHtml = article.getArticleContentHtml();
User user = UserUtils.getCurrentUserByToken(); User user = UserUtils.getCurrentUserByToken();
if (Objects.isNull(user)) {
throw new BaseApiException(ErrorCode.INVALID_TOKEN);
}
String reservedTag = checkTags(articleTags); String reservedTag = checkTags(articleTags);
boolean notification = false; boolean notification = false;
if (StringUtils.isNotBlank(reservedTag)) { if (StringUtils.isNotBlank(reservedTag)) {
Integer roleWeights = userService.findRoleWeightsByUser(user.getIdUser()); Integer roleWeights = userService.findRoleWeightsByUser(user.getIdUser());
if (roleWeights > 2) { if (roleWeights > ADMIN_ROLE_WEIGHTS) {
map.put("message", StringEscapeUtils.unescapeJava(reservedTag) + "标签为系统保留标签!"); map.put("message", StringEscapeUtils.unescapeJava(reservedTag) + "标签为系统保留标签!");
return map; return map;
} else { } else {
@ -144,10 +140,8 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
} else { } else {
newArticle = articleMapper.selectByPrimaryKey(article.getIdArticle()); newArticle = articleMapper.selectByPrimaryKey(article.getIdArticle());
// 如果文章之前状态为草稿则应视为新发布文章 // 如果文章之前状态为草稿则应视为新发布文章
if (defaultStatus.equals(newArticle.getArticleStatus())) { if (DEFAULT_STATUS.equals(newArticle.getArticleStatus())) {
isUpdate = true; isUpdate = true;
} else {
isUpdate = false;
} }
if (!user.getIdUser().equals(newArticle.getArticleAuthorId())) { if (!user.getIdUser().equals(newArticle.getArticleAuthorId())) {
map.put("message", "非法访问!"); map.put("message", "非法访问!");
@ -161,13 +155,13 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
} }
// 发送相关通知 // 发送相关通知
if (defaultStatus.equals(newArticle.getArticleStatus())) { if (DEFAULT_STATUS.equals(newArticle.getArticleStatus())) {
// 发送系统通知 // 发送系统通知
if (notification) { if (notification) {
NotificationUtils.sendAnnouncement(newArticle.getIdArticle(), NotificationConstant.Article, newArticle.getArticleTitle()); NotificationUtils.sendAnnouncement(newArticle.getIdArticle(), NotificationConstant.Article, newArticle.getArticleTitle());
} else { } else {
// 发送关注通知 // 发送关注通知
StringBuffer dataSummary = new StringBuffer(); StringBuilder dataSummary = new StringBuilder();
if (isUpdate) { if (isUpdate) {
dataSummary.append(user.getNickname()).append("更新了文章: ").append(newArticle.getArticleTitle()); dataSummary.append(user.getNickname()).append("更新了文章: ").append(newArticle.getArticleTitle());
NotificationUtils.sendArticlePush(newArticle.getIdArticle(), NotificationConstant.UpdateArticle, dataSummary.toString(), newArticle.getArticleAuthorId()); NotificationUtils.sendArticlePush(newArticle.getIdArticle(), NotificationConstant.UpdateArticle, dataSummary.toString(), newArticle.getArticleAuthorId());
@ -176,53 +170,33 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
NotificationUtils.sendArticlePush(newArticle.getIdArticle(), NotificationConstant.PostArticle, dataSummary.toString(), newArticle.getArticleAuthorId()); NotificationUtils.sendArticlePush(newArticle.getIdArticle(), NotificationConstant.PostArticle, dataSummary.toString(), newArticle.getArticleAuthorId());
} }
} }
}
// 草稿不更新索引 // 草稿不更新索引
if ("0".equals(article.getArticleStatus())) {
System.out.println("开始增加索引");
if (isUpdate) { if (isUpdate) {
log.info("更新文章索引id={}",newArticle.getIdArticle()); log.info("更新文章索引id={}", newArticle.getIdArticle());
luceneService.updateArticle(newArticle.getIdArticle().toString()); luceneService.updateArticle(newArticle.getIdArticle().toString());
} else { } else {
log.info("写入文章索引id={}",newArticle.getIdArticle()); log.info("写入文章索引id={}", newArticle.getIdArticle());
luceneService.writeArticle(newArticle.getIdArticle().toString()); luceneService.writeArticle(newArticle.getIdArticle().toString());
} }
} // 更新文章链接
tagService.saveTagArticle(newArticle, articleContentHtml);
if (defaultStatus.equals(newArticle.getArticleStatus())) {
newArticle.setArticlePermalink(domain + "/article/" + newArticle.getIdArticle()); newArticle.setArticlePermalink(domain + "/article/" + newArticle.getIdArticle());
newArticle.setArticleLink("/article/" + newArticle.getIdArticle()); newArticle.setArticleLink("/article/" + newArticle.getIdArticle());
} else { } else {
// 更新文章链接
newArticle.setArticlePermalink(domain + "/draft/" + newArticle.getIdArticle()); newArticle.setArticlePermalink(domain + "/draft/" + newArticle.getIdArticle());
newArticle.setArticleLink("/draft/" + newArticle.getIdArticle()); newArticle.setArticleLink("/draft/" + newArticle.getIdArticle());
} }
tagService.saveTagArticle(newArticle, articleContentHtml);
if (StringUtils.isNotBlank(articleContentHtml)) { if (StringUtils.isNotBlank(articleContentHtml)) {
String previewContent; String previewContent = Html2TextUtil.getContent(articleContentHtml);
if (articleContentHtml.length() > MAX_PREVIEW) {
previewContent = BaiDuAipUtils.getNewsSummary(newArticle.getArticleTitle(), articleContentHtml, MAX_PREVIEW);
if (previewContent.length() > MAX_PREVIEW) { if (previewContent.length() > MAX_PREVIEW) {
previewContent = previewContent.substring(0, MAX_PREVIEW); previewContent = previewContent.substring(0, MAX_PREVIEW);
} }
} else {
previewContent = Html2TextUtil.getContent(articleContentHtml);
}
newArticle.setArticlePreviewContent(previewContent); newArticle.setArticlePreviewContent(previewContent);
} }
articleMapper.updateByPrimaryKeySelective(newArticle); articleMapper.updateByPrimaryKeySelective(newArticle);
// 推送百度 SEO
if (!ProjectConstant.ENV.equals(env)
&& defaultStatus.equals(newArticle.getArticleStatus())
&& articleContent.length() >= MAX_PREVIEW) {
if (isUpdate) {
BaiDuUtils.sendUpdateSEOData(newArticle.getArticlePermalink());
} else {
BaiDuUtils.sendSEOData(newArticle.getArticlePermalink());
}
}
map.put("id", newArticle.getIdArticle()); map.put("id", newArticle.getIdArticle());
return map; return map;
} }
@ -265,15 +239,18 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
Map<String, String> map = new HashMap(1); Map<String, String> map = new HashMap(1);
// 鉴权 // 鉴权
User user = UserUtils.getCurrentUserByToken(); User user = UserUtils.getCurrentUserByToken();
if (Objects.isNull(user)) {
throw new BaseApiException(ErrorCode.INVALID_TOKEN);
}
Integer roleWeights = userService.findRoleWeightsByUser(user.getIdUser()); Integer roleWeights = userService.findRoleWeightsByUser(user.getIdUser());
if (roleWeights > 2) { if (roleWeights > ADMIN_ROLE_WEIGHTS) {
Article article = articleMapper.selectByPrimaryKey(id); Article article = articleMapper.selectByPrimaryKey(id);
if (!user.getIdUser().equals(article.getArticleAuthorId())) { if (!user.getIdUser().equals(article.getArticleAuthorId())) {
map.put("message", "非法访问!"); map.put("message", "非法访问!");
return map; return map;
} }
} }
Integer result; int result;
// 判断是否有评论 // 判断是否有评论
boolean isHavComment = articleMapper.existsCommentWithPrimaryKey(id); boolean isHavComment = articleMapper.existsCommentWithPrimaryKey(id);
if (isHavComment) { if (isHavComment) {
@ -312,6 +289,9 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
public Map share(Integer id) throws BaseApiException { public Map share(Integer id) throws BaseApiException {
Article article = articleMapper.selectByPrimaryKey(id); Article article = articleMapper.selectByPrimaryKey(id);
User user = UserUtils.getCurrentUserByToken(); User user = UserUtils.getCurrentUserByToken();
if (Objects.isNull(user)) {
throw new BaseApiException(ErrorCode.INVALID_TOKEN);
}
StringBuilder shareUrl = new StringBuilder(article.getArticlePermalink()); StringBuilder shareUrl = new StringBuilder(article.getArticlePermalink());
shareUrl.append("?s=").append(user.getNickname()); shareUrl.append("?s=").append(user.getNickname());
Map map = new HashMap(1); Map map = new HashMap(1);
@ -322,28 +302,25 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
@Override @Override
public List<ArticleDTO> findDrafts() throws BaseApiException { public List<ArticleDTO> findDrafts() throws BaseApiException {
User user = UserUtils.getCurrentUserByToken(); User user = UserUtils.getCurrentUserByToken();
if (Objects.isNull(user)) {
throw new BaseApiException(ErrorCode.INVALID_TOKEN);
}
List<ArticleDTO> list = articleMapper.selectDrafts(user.getIdUser()); List<ArticleDTO> list = articleMapper.selectDrafts(user.getIdUser());
list.forEach(article -> { list.forEach(articleDTO -> genArticle(articleDTO, 0));
genArticle(article, 0);
});
return list; return list;
} }
@Override @Override
public List<ArticleDTO> findArticlesByIdPortfolio(Integer idPortfolio) { public List<ArticleDTO> findArticlesByIdPortfolio(Integer idPortfolio) {
List<ArticleDTO> list = articleMapper.selectArticlesByIdPortfolio(idPortfolio); List<ArticleDTO> list = articleMapper.selectArticlesByIdPortfolio(idPortfolio);
list.forEach(article -> { list.forEach(articleDTO -> genArticle(articleDTO, 0));
genArticle(article, 0);
});
return list; return list;
} }
@Override @Override
public List<ArticleDTO> selectUnbindArticles(Integer idPortfolio, String searchText, Integer idUser) { public List<ArticleDTO> selectUnbindArticles(Integer idPortfolio, String searchText, Integer idUser) {
List<ArticleDTO> list = articleMapper.selectUnbindArticlesByIdPortfolio(idPortfolio, searchText, idUser); List<ArticleDTO> list = articleMapper.selectUnbindArticlesByIdPortfolio(idPortfolio, searchText, idUser);
list.forEach(article -> { list.forEach(articleDTO -> genArticle(articleDTO, 0));
genArticle(article, 0);
});
return list; return list;
} }
@ -380,9 +357,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
@Override @Override
public List<ArticleDTO> findAnnouncements() { public List<ArticleDTO> findAnnouncements() {
List<ArticleDTO> list = articleMapper.selectAnnouncements(); List<ArticleDTO> list = articleMapper.selectAnnouncements();
list.forEach(article -> { list.forEach(articleDTO -> genArticle(articleDTO, 0));
genArticle(article, 0);
});
return list; return list;
} }
@ -401,7 +376,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
article.setArticleContent(articleContent.getArticleContentHtml()); article.setArticleContent(articleContent.getArticleContentHtml());
// 获取所属作品集列表数据 // 获取所属作品集列表数据
List<PortfolioArticleDTO> portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle()); List<PortfolioArticleDTO> portfolioArticleDTOList = articleMapper.selectPortfolioArticles(article.getIdArticle());
portfolioArticleDTOList.forEach(portfolioArticleDTO -> genPortfolioArticles(portfolioArticleDTO)); portfolioArticleDTOList.forEach(this::genPortfolioArticles);
article.setPortfolios(portfolioArticleDTOList); article.setPortfolios(portfolioArticleDTOList);
} else if (type.equals(articleEdit)) { } else if (type.equals(articleEdit)) {
article.setArticleContent(articleContent.getArticleContent()); article.setArticleContent(articleContent.getArticleContent());

View File

@ -27,7 +27,6 @@ import java.util.*;
/** /**
*
* @author CodeGenerator * @author CodeGenerator
* @date 2018/05/29 * @date 2018/05/29
*/ */
@ -48,7 +47,7 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
private final static String DEFAULT_AVATAR = "https://static.rymcu.com/article/1578475481946.png"; private final static String DEFAULT_AVATAR = "https://static.rymcu.com/article/1578475481946.png";
@Override @Override
public User findByAccount(String account) throws TooManyResultsException{ public User findByAccount(String account) throws TooManyResultsException {
return userMapper.findByAccount(account); return userMapper.findByAccount(account);
} }
@ -56,13 +55,13 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map register(String email, String password, String code) { public Map register(String email, String password, String code) {
Map map = new HashMap(2); Map map = new HashMap(2);
map.put("message","验证码无效!"); map.put("message", "验证码无效!");
String vCode = redisService.get(email); String vCode = redisService.get(email);
if(StringUtils.isNotBlank(vCode)){ if (StringUtils.isNotBlank(vCode)) {
if(vCode.equals(code)){ if (vCode.equals(code)) {
User user = userMapper.findByAccount(email); User user = userMapper.findByAccount(email);
if(user != null){ if (user != null) {
map.put("message","该邮箱已被注册!"); map.put("message", "该邮箱已被注册!");
} else { } else {
user = new User(); user = new User();
String nickname = email.split("@")[0]; String nickname = email.split("@")[0];
@ -83,8 +82,8 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
.nickname(user.getNickname()) .nickname(user.getNickname())
.signature(user.getSignature()) .signature(user.getSignature())
.build()); .build());
map.put("message","注册成功!"); map.put("message", "注册成功!");
map.put("flag",1); map.put("flag", 1);
redisService.delete(email); redisService.delete(email);
} }
} }
@ -106,19 +105,20 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
public Map login(String account, String password) { public Map login(String account, String password) {
Map map = new HashMap(1); Map map = new HashMap(1);
User user = userMapper.findByAccount(account); User user = userMapper.findByAccount(account);
if(user != null){ if (user != null) {
if(Utils.comparePwd(password, user.getPassword())){ if (Utils.comparePwd(password, user.getPassword())) {
userMapper.updateLastLoginTime(user.getIdUser()); userMapper.updateLastLoginTime(user.getIdUser());
userMapper.updateLastOnlineTimeByEmail(user.getEmail());
TokenUser tokenUser = new TokenUser(); TokenUser tokenUser = new TokenUser();
BeanCopierUtil.copy(user, tokenUser); BeanCopierUtil.copy(user, tokenUser);
tokenUser.setToken(tokenManager.createToken(account)); tokenUser.setToken(tokenManager.createToken(account));
tokenUser.setWeights(userMapper.selectRoleWeightsByUser(user.getIdUser())); tokenUser.setWeights(userMapper.selectRoleWeightsByUser(user.getIdUser()));
map.put("user", tokenUser); map.put("user", tokenUser);
} else { } else {
map.put("message","密码错误!"); map.put("message", "密码错误!");
} }
} else { } else {
map.put("message","该账号不存在!"); map.put("message", "该账号不存在!");
} }
return map; return map;
} }
@ -133,12 +133,12 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
public Map forgetPassword(String code, String password) { public Map forgetPassword(String code, String password) {
Map map = new HashMap<>(2); Map map = new HashMap<>(2);
String email = redisService.get(code); String email = redisService.get(code);
if(StringUtils.isBlank(email)){ if (StringUtils.isBlank(email)) {
map.put("message","链接已失效"); map.put("message", "链接已失效");
} else { } else {
userMapper.updatePasswordByEmail(email,Utils.entryptPassword(password)); userMapper.updatePasswordByEmail(email, Utils.entryptPassword(password));
map.put("message","修改成功,正在跳转登录登陆界面!"); map.put("message", "修改成功,正在跳转登录登陆界面!");
map.put("flag",1); map.put("flag", 1);
} }
return map; return map;
} }
@ -147,9 +147,9 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map updateUserRole(Integer idUser, Integer idRole) { public Map updateUserRole(Integer idUser, Integer idRole) {
Map map = new HashMap(1); Map map = new HashMap(1);
Integer result = userMapper.updateUserRole(idUser,idRole); Integer result = userMapper.updateUserRole(idUser, idRole);
if(result == 0) { if (result == 0) {
map.put("message","更新失败!"); map.put("message", "更新失败!");
} }
return map; return map;
} }
@ -158,9 +158,9 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map updateStatus(Integer idUser, String status) { public Map updateStatus(Integer idUser, String status) {
Map map = new HashMap(1); Map map = new HashMap(1);
Integer result = userMapper.updateStatus(idUser,status); Integer result = userMapper.updateStatus(idUser, status);
if(result == 0) { if (result == 0) {
map.put("message","更新失败!"); map.put("message", "更新失败!");
} }
return map; return map;
} }
@ -199,7 +199,7 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
user.setAvatarUrl(avatarUrl); user.setAvatarUrl(avatarUrl);
user.setAvatarType("0"); user.setAvatarType("0");
} }
Integer result = userMapper.updateUserInfo(user.getIdUser(), user.getNickname(), user.getAvatarType(),user.getAvatarUrl(),user.getSignature(), user.getSex()); Integer result = userMapper.updateUserInfo(user.getIdUser(), user.getNickname(), user.getAvatarType(), user.getAvatarUrl(), user.getSignature(), user.getSex());
UserIndexUtil.addIndex(UserLucene.builder() UserIndexUtil.addIndex(UserLucene.builder()
.idUser(user.getIdUser()) .idUser(user.getIdUser())
.nickname(user.getNickname()) .nickname(user.getNickname())
@ -209,7 +209,7 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
map.put("message", "操作失败!"); map.put("message", "操作失败!");
return map; return map;
} }
map.put("user",user); map.put("user", user);
return map; return map;
} }
@ -257,15 +257,15 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
@Override @Override
public Map updateEmail(ChangeEmailDTO changeEmailDTO) { public Map updateEmail(ChangeEmailDTO changeEmailDTO) {
Map map = new HashMap(2); Map map = new HashMap(2);
map.put("message","验证码无效!"); map.put("message", "验证码无效!");
Integer idUser = changeEmailDTO.getIdUser(); Integer idUser = changeEmailDTO.getIdUser();
String email = changeEmailDTO.getEmail(); String email = changeEmailDTO.getEmail();
String code = changeEmailDTO.getCode(); String code = changeEmailDTO.getCode();
String vCode = redisService.get(email); String vCode = redisService.get(email);
if(StringUtils.isNotBlank(vCode) && StringUtils.isNotBlank(code)){ if (StringUtils.isNotBlank(vCode) && StringUtils.isNotBlank(code)) {
if(vCode.equals(code)){ if (vCode.equals(code)) {
userMapper.updateEmail(idUser, email); userMapper.updateEmail(idUser, email);
map.put("message","更新成功!"); map.put("message", "更新成功!");
map.put("email", email); map.put("email", email);
} }
} }

View File

@ -10,7 +10,7 @@ import org.springframework.stereotype.Component;
/** /**
* @author ronger * @author ronger
*/ */
@Component //@Component
@Slf4j @Slf4j
public class BaiDuCronTask { public class BaiDuCronTask {

View File

@ -80,7 +80,7 @@
</update> </update>
<select id="findByAccount" resultMap="BaseResultMap"> <select id="findByAccount" resultMap="BaseResultMap">
select id, nickname, account, password, status, avatar_type, avatar_url from forest_user where (account = #{account} or email = #{account} ) and status = 0 select id, nickname, account, password, status, avatar_type, avatar_url, email from forest_user where (account = #{account} or email = #{account} ) and status = 0
</select> </select>
<select id="findUserInfoByAccount" resultMap="UserInfoResultMapper"> <select id="findUserInfoByAccount" resultMap="UserInfoResultMapper">
select id, nickname, sex, avatar_type, avatar_url, email, phone, account, status, signature, last_login_time, last_online_time from forest_user where account = #{account} select id, nickname, sex, avatar_type, avatar_url, email, phone, account, status, signature, last_login_time, last_online_time from forest_user where account = #{account}

View File

@ -0,0 +1 @@
log4j2.formatMsgNoLookups=True