MyException rename to BlogResponseException
This commit is contained in:
@@ -6,7 +6,7 @@ import cn.celess.common.entity.*;
|
|||||||
import cn.celess.common.entity.dto.ArticleReq;
|
import cn.celess.common.entity.dto.ArticleReq;
|
||||||
import cn.celess.common.entity.vo.ArticleModel;
|
import cn.celess.common.entity.vo.ArticleModel;
|
||||||
import cn.celess.common.entity.vo.PageData;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import cn.celess.common.exception.MyException;
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
import cn.celess.common.mapper.*;
|
import cn.celess.common.mapper.*;
|
||||||
import cn.celess.common.service.ArticleService;
|
import cn.celess.common.service.ArticleService;
|
||||||
import cn.celess.common.service.UserService;
|
import cn.celess.common.service.UserService;
|
||||||
@@ -61,35 +61,35 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ArticleModel create(ArticleReq reqBody) {
|
public ArticleModel create(ArticleReq reqBody) {
|
||||||
if (reqBody == null) {
|
if (reqBody == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
//数据判断
|
//数据判断
|
||||||
if (reqBody.getTitle() == null || reqBody.getTitle().replaceAll(" ", "").isEmpty()) {
|
if (reqBody.getTitle() == null || reqBody.getTitle().replaceAll(" ", "").isEmpty()) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
} else if (reqBody.getMdContent() == null || reqBody.getMdContent().replaceAll(" ", "").isEmpty()) {
|
} else if (reqBody.getMdContent() == null || reqBody.getMdContent().replaceAll(" ", "").isEmpty()) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
//转载 判断链接
|
//转载 判断链接
|
||||||
if (!reqBody.getType()) {
|
if (!reqBody.getType()) {
|
||||||
if (reqBody.getUrl() == null || reqBody.getUrl().replaceAll(" ", "").isEmpty()) {
|
if (reqBody.getUrl() == null || reqBody.getUrl().replaceAll(" ", "").isEmpty()) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
} else if (!RegexUtil.urlMatch(reqBody.getUrl())) {
|
} else if (!RegexUtil.urlMatch(reqBody.getUrl())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (reqBody.getCategory() == null || reqBody.getCategory().replaceAll(" ", "").isEmpty()) {
|
if (reqBody.getCategory() == null || reqBody.getCategory().replaceAll(" ", "").isEmpty()) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
if (reqBody.getTags() == null || reqBody.getTags().length == 0) {
|
if (reqBody.getTags() == null || reqBody.getTags().length == 0) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
if (articleMapper.existsByTitle(reqBody.getTitle())) {
|
if (articleMapper.existsByTitle(reqBody.getTitle())) {
|
||||||
throw new MyException(ResponseEnum.ARTICLE_HAS_EXIST);
|
throw new BlogResponseException(ResponseEnum.ARTICLE_HAS_EXIST);
|
||||||
}
|
}
|
||||||
// 查看是否存在已有的分类
|
// 查看是否存在已有的分类
|
||||||
Category category = categoryMapper.findCategoryByName(reqBody.getCategory());
|
Category category = categoryMapper.findCategoryByName(reqBody.getCategory());
|
||||||
if (category == null) {
|
if (category == null) {
|
||||||
throw new MyException(ResponseEnum.CATEGORY_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建 需要写入数据库的对象数据
|
// 构建 需要写入数据库的对象数据
|
||||||
@@ -137,13 +137,13 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
|
|
||||||
if (articleForDel == null) {
|
if (articleForDel == null) {
|
||||||
//文章不存在
|
//文章不存在
|
||||||
throw new MyException(ResponseEnum.ARTICLE_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.ARTICLE_NOT_EXIST);
|
||||||
}
|
}
|
||||||
|
|
||||||
//对访问情况进行判断 非admin 权限不可删除文章
|
//对访问情况进行判断 非admin 权限不可删除文章
|
||||||
User user = redisUserUtil.get();
|
User user = redisUserUtil.get();
|
||||||
if (!RoleEnum.ADMIN_ROLE.getRoleName().equals(user.getRole())) {
|
if (!RoleEnum.ADMIN_ROLE.getRoleName().equals(user.getRole())) {
|
||||||
throw new MyException(ResponseEnum.PERMISSION_ERROR);
|
throw new BlogResponseException(ResponseEnum.PERMISSION_ERROR);
|
||||||
}
|
}
|
||||||
//删除指定文章
|
//删除指定文章
|
||||||
articleMapper.delete(articleId);
|
articleMapper.delete(articleId);
|
||||||
@@ -157,7 +157,7 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
@Override
|
@Override
|
||||||
public ArticleModel update(ArticleReq reqBody) {
|
public ArticleModel update(ArticleReq reqBody) {
|
||||||
if (reqBody == null || reqBody.getId() == null) {
|
if (reqBody == null || reqBody.getId() == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
// 查找数据
|
// 查找数据
|
||||||
Article article = articleMapper.findArticleById(reqBody.getId());
|
Article article = articleMapper.findArticleById(reqBody.getId());
|
||||||
@@ -165,7 +165,7 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
//数据判断
|
//数据判断
|
||||||
if (reqBody.getTitle() != null && !reqBody.getTitle().replaceAll(" ", "").isEmpty()) {
|
if (reqBody.getTitle() != null && !reqBody.getTitle().replaceAll(" ", "").isEmpty()) {
|
||||||
if (!article.getTitle().equals(reqBody.getTitle()) && articleMapper.existsByTitle(reqBody.getTitle())) {
|
if (!article.getTitle().equals(reqBody.getTitle()) && articleMapper.existsByTitle(reqBody.getTitle())) {
|
||||||
throw new MyException(ResponseEnum.ARTICLE_HAS_EXIST);
|
throw new BlogResponseException(ResponseEnum.ARTICLE_HAS_EXIST);
|
||||||
}
|
}
|
||||||
article.setTitle(reqBody.getTitle());
|
article.setTitle(reqBody.getTitle());
|
||||||
}
|
}
|
||||||
@@ -176,11 +176,11 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
//转载 判断链接
|
//转载 判断链接
|
||||||
if (reqBody.getType() != null) {
|
if (reqBody.getType() != null) {
|
||||||
if (!reqBody.getType() && reqBody.getUrl() == null) {
|
if (!reqBody.getType() && reqBody.getUrl() == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reqBody.getType() && !RegexUtil.urlMatch(reqBody.getUrl())) {
|
if (!reqBody.getType() && !RegexUtil.urlMatch(reqBody.getUrl())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||||
}
|
}
|
||||||
article.setType(reqBody.getType());
|
article.setType(reqBody.getType());
|
||||||
article.setUrl(reqBody.getUrl());
|
article.setUrl(reqBody.getUrl());
|
||||||
@@ -255,12 +255,12 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
public ArticleModel retrieveOneById(long articleId, boolean is4update) {
|
public ArticleModel retrieveOneById(long articleId, boolean is4update) {
|
||||||
Article article = articleMapper.findArticleById(articleId);
|
Article article = articleMapper.findArticleById(articleId);
|
||||||
if (article == null) {
|
if (article == null) {
|
||||||
throw new MyException(ResponseEnum.ARTICLE_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.ARTICLE_NOT_EXIST);
|
||||||
}
|
}
|
||||||
if (!article.getOpen()) {
|
if (!article.getOpen()) {
|
||||||
User user = redisUserUtil.getWithOutExc();
|
User user = redisUserUtil.getWithOutExc();
|
||||||
if (user == null || "user".equals(user.getRole())) {
|
if (user == null || "user".equals(user.getRole())) {
|
||||||
throw new MyException(ResponseEnum.ARTICLE_NOT_PUBLIC);
|
throw new BlogResponseException(ResponseEnum.ARTICLE_NOT_PUBLIC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArticleModel articleModel = ModalTrans.article(article);
|
ArticleModel articleModel = ModalTrans.article(article);
|
||||||
@@ -322,7 +322,7 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
public PageData<ArticleModel> findByCategory(String name, int page, int count) {
|
public PageData<ArticleModel> findByCategory(String name, int page, int count) {
|
||||||
Category category = categoryMapper.findCategoryByName(name);
|
Category category = categoryMapper.findCategoryByName(name);
|
||||||
if (category == null) {
|
if (category == null) {
|
||||||
throw new MyException(ResponseEnum.CATEGORY_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||||
}
|
}
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<Article> open = articleMapper.findAllByCategoryIdAndOpen(category.getId());
|
List<Article> open = articleMapper.findAllByCategoryIdAndOpen(category.getId());
|
||||||
@@ -342,7 +342,7 @@ public class ArticleServiceImpl implements ArticleService {
|
|||||||
public PageData<ArticleModel> findByTag(String name, int page, int count) {
|
public PageData<ArticleModel> findByTag(String name, int page, int count) {
|
||||||
Tag tag = tagMapper.findTagByName(name);
|
Tag tag = tagMapper.findTagByName(name);
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
throw new MyException(ResponseEnum.TAG_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.TAG_NOT_EXIST);
|
||||||
}
|
}
|
||||||
PageHelper.startPage(page, count);
|
PageHelper.startPage(page, count);
|
||||||
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTagAndOpen(tag.getId());
|
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTagAndOpen(tag.getId());
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import cn.celess.common.entity.Category;
|
|||||||
import cn.celess.common.entity.vo.ArticleModel;
|
import cn.celess.common.entity.vo.ArticleModel;
|
||||||
import cn.celess.common.entity.vo.CategoryModel;
|
import cn.celess.common.entity.vo.CategoryModel;
|
||||||
import cn.celess.common.entity.vo.PageData;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import cn.celess.common.exception.MyException;
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
import cn.celess.common.mapper.ArticleMapper;
|
import cn.celess.common.mapper.ArticleMapper;
|
||||||
import cn.celess.common.mapper.CategoryMapper;
|
import cn.celess.common.mapper.CategoryMapper;
|
||||||
import cn.celess.common.service.CategoryService;
|
import cn.celess.common.service.CategoryService;
|
||||||
@@ -36,7 +36,7 @@ public class CategoryServiceImpl implements CategoryService {
|
|||||||
@Override
|
@Override
|
||||||
public CategoryModel create(String name) {
|
public CategoryModel create(String name) {
|
||||||
if (categoryMapper.existsByName(name)) {
|
if (categoryMapper.existsByName(name)) {
|
||||||
throw new MyException(ResponseEnum.CATEGORY_HAS_EXIST);
|
throw new BlogResponseException(ResponseEnum.CATEGORY_HAS_EXIST);
|
||||||
}
|
}
|
||||||
Category category = new Category();
|
Category category = new Category();
|
||||||
category.setName(name);
|
category.setName(name);
|
||||||
@@ -48,7 +48,7 @@ public class CategoryServiceImpl implements CategoryService {
|
|||||||
public boolean delete(long id) {
|
public boolean delete(long id) {
|
||||||
Category category = categoryMapper.findCategoryById(id);
|
Category category = categoryMapper.findCategoryById(id);
|
||||||
if (category == null) {
|
if (category == null) {
|
||||||
throw new MyException(ResponseEnum.CATEGORY_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.CATEGORY_NOT_EXIST);
|
||||||
}
|
}
|
||||||
return categoryMapper.delete(id) == 1;
|
return categoryMapper.delete(id) == 1;
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ public class CategoryServiceImpl implements CategoryService {
|
|||||||
@Override
|
@Override
|
||||||
public CategoryModel update(Long id, String name) {
|
public CategoryModel update(Long id, String name) {
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR.getCode(), "id不可为空");
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR.getCode(), "id不可为空");
|
||||||
}
|
}
|
||||||
Category category = categoryMapper.findCategoryById(id);
|
Category category = categoryMapper.findCategoryById(id);
|
||||||
category.setName(name);
|
category.setName(name);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import cn.celess.common.entity.ArticleTag;
|
|||||||
import cn.celess.common.entity.Tag;
|
import cn.celess.common.entity.Tag;
|
||||||
import cn.celess.common.entity.vo.PageData;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import cn.celess.common.entity.vo.TagModel;
|
import cn.celess.common.entity.vo.TagModel;
|
||||||
import cn.celess.common.exception.MyException;
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
import cn.celess.common.mapper.ArticleMapper;
|
import cn.celess.common.mapper.ArticleMapper;
|
||||||
import cn.celess.common.mapper.ArticleTagMapper;
|
import cn.celess.common.mapper.ArticleTagMapper;
|
||||||
import cn.celess.common.mapper.TagMapper;
|
import cn.celess.common.mapper.TagMapper;
|
||||||
@@ -42,7 +42,7 @@ public class TagServiceImpl implements TagService {
|
|||||||
public TagModel create(String name) {
|
public TagModel create(String name) {
|
||||||
boolean b = tagMapper.existsByName(name);
|
boolean b = tagMapper.existsByName(name);
|
||||||
if (b) {
|
if (b) {
|
||||||
throw new MyException(ResponseEnum.TAG_HAS_EXIST);
|
throw new BlogResponseException(ResponseEnum.TAG_HAS_EXIST);
|
||||||
}
|
}
|
||||||
Tag tag = new Tag();
|
Tag tag = new Tag();
|
||||||
tag.setName(name);
|
tag.setName(name);
|
||||||
@@ -55,7 +55,7 @@ public class TagServiceImpl implements TagService {
|
|||||||
public boolean delete(long tagId) {
|
public boolean delete(long tagId) {
|
||||||
Tag tag = tagMapper.findTagById(tagId);
|
Tag tag = tagMapper.findTagById(tagId);
|
||||||
if (tag == null) {
|
if (tag == null) {
|
||||||
throw new MyException(ResponseEnum.TAG_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.TAG_NOT_EXIST);
|
||||||
}
|
}
|
||||||
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTag(tagId);
|
List<ArticleTag> articleByTag = articleTagMapper.findArticleByTag(tagId);
|
||||||
// 删除文章
|
// 删除文章
|
||||||
@@ -67,7 +67,7 @@ public class TagServiceImpl implements TagService {
|
|||||||
@Override
|
@Override
|
||||||
public TagModel update(Long id, String name) {
|
public TagModel update(Long id, String name) {
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR.getCode(), "缺少ID");
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR.getCode(), "缺少ID");
|
||||||
}
|
}
|
||||||
Tag tag = tagMapper.findTagById(id);
|
Tag tag = tagMapper.findTagById(id);
|
||||||
tag.setName(name);
|
tag.setName(name);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import cn.celess.common.entity.User;
|
|||||||
import cn.celess.common.entity.dto.CommentReq;
|
import cn.celess.common.entity.dto.CommentReq;
|
||||||
import cn.celess.common.entity.vo.CommentModel;
|
import cn.celess.common.entity.vo.CommentModel;
|
||||||
import cn.celess.common.entity.vo.PageData;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import cn.celess.common.exception.MyException;
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
import cn.celess.common.mapper.ArticleMapper;
|
import cn.celess.common.mapper.ArticleMapper;
|
||||||
import cn.celess.common.mapper.CommentMapper;
|
import cn.celess.common.mapper.CommentMapper;
|
||||||
import cn.celess.common.mapper.UserMapper;
|
import cn.celess.common.mapper.UserMapper;
|
||||||
@@ -44,7 +44,7 @@ public class CommentServiceImpl implements CommentService {
|
|||||||
@Override
|
@Override
|
||||||
public CommentModel create(CommentReq reqBody) {
|
public CommentModel create(CommentReq reqBody) {
|
||||||
if (reqBody == null) {
|
if (reqBody == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
User user = redisUserUtil.get();
|
User user = redisUserUtil.get();
|
||||||
Comment pComment = null;
|
Comment pComment = null;
|
||||||
@@ -54,7 +54,7 @@ public class CommentServiceImpl implements CommentService {
|
|||||||
//不是一级评论
|
//不是一级评论
|
||||||
if (reqBody.getPid() != -1 && pComment == null) {
|
if (reqBody.getPid() != -1 && pComment == null) {
|
||||||
//父评论不存在
|
//父评论不存在
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
Comment comment = new Comment();
|
Comment comment = new Comment();
|
||||||
comment.setFromUser(user);
|
comment.setFromUser(user);
|
||||||
@@ -75,10 +75,10 @@ public class CommentServiceImpl implements CommentService {
|
|||||||
public boolean delete(long id) {
|
public boolean delete(long id) {
|
||||||
Comment b = commentMapper.findCommentById(id);
|
Comment b = commentMapper.findCommentById(id);
|
||||||
if (b == null) {
|
if (b == null) {
|
||||||
throw new MyException(ResponseEnum.COMMENT_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.COMMENT_NOT_EXIST);
|
||||||
}
|
}
|
||||||
if (b.getStatus() == CommentStatusEnum.DELETED.getCode()) {
|
if (b.getStatus() == CommentStatusEnum.DELETED.getCode()) {
|
||||||
throw new MyException(ResponseEnum.DATA_IS_DELETED);
|
throw new BlogResponseException(ResponseEnum.DATA_IS_DELETED);
|
||||||
}
|
}
|
||||||
commentMapper.delete(id);
|
commentMapper.delete(id);
|
||||||
return true;
|
return true;
|
||||||
@@ -87,7 +87,7 @@ public class CommentServiceImpl implements CommentService {
|
|||||||
@Override
|
@Override
|
||||||
public CommentModel update(CommentReq reqBody) {
|
public CommentModel update(CommentReq reqBody) {
|
||||||
if (reqBody.getId() == null) {
|
if (reqBody.getId() == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR.getCode(), "id不可为空");
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR.getCode(), "id不可为空");
|
||||||
}
|
}
|
||||||
Comment comment = commentMapper.findCommentById(reqBody.getId());
|
Comment comment = commentMapper.findCommentById(reqBody.getId());
|
||||||
if (!comment.getContent().equals(reqBody.getContent())) {
|
if (!comment.getContent().equals(reqBody.getContent())) {
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
package cn.celess.common;
|
package cn.celess.common;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.FilterType;
|
import org.springframework.context.annotation.FilterType;
|
||||||
|
|
||||||
|
|
||||||
@SpringBootApplication(
|
@SpringBootApplication(
|
||||||
scanBasePackageClasses = {
|
scanBasePackageClasses = {
|
||||||
CommonApplication.class
|
CommonApplication.class
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "cn.celess.common.test.BaseRedisTest")})
|
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "cn.celess.common.test.BaseRedisTest")})
|
||||||
|
@MapperScan("cn.celess.common.mapper")
|
||||||
public class CommonApplication {
|
public class CommonApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(CommonApplication.class, args);
|
SpringApplication.run(CommonApplication.class, args);
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
package cn.celess.common.config;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@MapperScan("cn.celess.common.mapper")
|
|
||||||
@Slf4j
|
|
||||||
public class MybatisConfig {
|
|
||||||
|
|
||||||
// @Bean
|
|
||||||
// public SqlSessionFactory sqlSessionFactory() throws Exception {
|
|
||||||
// log.info("配置Mybatis的配置项");
|
|
||||||
// PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
|
|
||||||
// SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
|
|
||||||
// // 此处省略部分代码
|
|
||||||
// bean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
|
|
||||||
// bean.setTypeAliasesPackage("cn.celess.common.entity");
|
|
||||||
// return bean.getObject();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
@@ -8,32 +8,32 @@ import lombok.Data;
|
|||||||
* @date : 2019/03/28 16:56
|
* @date : 2019/03/28 16:56
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class MyException extends RuntimeException {
|
public class BlogResponseException extends RuntimeException {
|
||||||
private int code;
|
private int code;
|
||||||
private Object result;
|
private Object result;
|
||||||
|
|
||||||
public MyException(int code, String msg) {
|
public BlogResponseException(int code, String msg) {
|
||||||
super(msg);
|
super(msg);
|
||||||
this.code = code;
|
this.code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyException(ResponseEnum e) {
|
public BlogResponseException(ResponseEnum e) {
|
||||||
super(e.getMsg());
|
super(e.getMsg());
|
||||||
this.code = e.getCode();
|
this.code = e.getCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyException(ResponseEnum e, Object result) {
|
public BlogResponseException(ResponseEnum e, Object result) {
|
||||||
super(e.getMsg());
|
super(e.getMsg());
|
||||||
this.code = e.getCode();
|
this.code = e.getCode();
|
||||||
this.result = result;
|
this.result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyException(ResponseEnum e, String msg) {
|
public BlogResponseException(ResponseEnum e, String msg) {
|
||||||
super(msg + e.getMsg());
|
super(msg + e.getMsg());
|
||||||
this.code = e.getCode();
|
this.code = e.getCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyException(ResponseEnum e, String msg, Object result) {
|
public BlogResponseException(ResponseEnum e, String msg, Object result) {
|
||||||
super(e.getMsg());
|
super(e.getMsg());
|
||||||
this.code = e.getCode();
|
this.code = e.getCode();
|
||||||
this.result = result;
|
this.result = result;
|
||||||
@@ -38,8 +38,8 @@ public class ExceptionHandle {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
public Response handle(Exception e) {
|
public Response handle(Exception e) {
|
||||||
//自定义错误
|
//自定义错误
|
||||||
if (e instanceof MyException) {
|
if (e instanceof BlogResponseException) {
|
||||||
MyException exception = (MyException) e;
|
BlogResponseException exception = (BlogResponseException) e;
|
||||||
logger.debug("返回了自定义的exception,[code={},msg={},result={}]", exception.getCode(), e.getMessage(), exception.getResult());
|
logger.debug("返回了自定义的exception,[code={},msg={},result={}]", exception.getCode(), e.getMessage(), exception.getResult());
|
||||||
return new Response(exception.getCode(), e.getMessage(), exception.getResult());
|
return new Response(exception.getCode(), e.getMessage(), exception.getResult());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package cn.celess.extension.controller;
|
|||||||
import cn.celess.common.enmu.ResponseEnum;
|
import cn.celess.common.enmu.ResponseEnum;
|
||||||
import cn.celess.common.entity.Response;
|
import cn.celess.common.entity.Response;
|
||||||
import cn.celess.common.entity.vo.QiniuResponse;
|
import cn.celess.common.entity.vo.QiniuResponse;
|
||||||
import cn.celess.common.exception.MyException;
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
import cn.celess.common.service.CountService;
|
import cn.celess.common.service.CountService;
|
||||||
import cn.celess.common.service.QiniuService;
|
import cn.celess.common.service.QiniuService;
|
||||||
import cn.celess.common.util.HttpUtil;
|
import cn.celess.common.util.HttpUtil;
|
||||||
@@ -112,10 +112,10 @@ public class ExtensionController {
|
|||||||
request.getSession().setAttribute("verImgCodeStatus", false);
|
request.getSession().setAttribute("verImgCodeStatus", false);
|
||||||
String codeStr = (String) request.getSession().getAttribute("code");
|
String codeStr = (String) request.getSession().getAttribute("code");
|
||||||
if (code == null) {
|
if (code == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
if (codeStr == null) {
|
if (codeStr == null) {
|
||||||
throw new MyException(ResponseEnum.IMG_CODE_TIMEOUT);
|
throw new BlogResponseException(ResponseEnum.IMG_CODE_TIMEOUT);
|
||||||
}
|
}
|
||||||
code = code.toLowerCase();
|
code = code.toLowerCase();
|
||||||
codeStr = codeStr.toLowerCase();
|
codeStr = codeStr.toLowerCase();
|
||||||
@@ -147,7 +147,7 @@ public class ExtensionController {
|
|||||||
uploadTimes = Integer.parseInt(uploadTimesStr);
|
uploadTimes = Integer.parseInt(uploadTimesStr);
|
||||||
}
|
}
|
||||||
if (uploadTimes == 10) {
|
if (uploadTimes == 10) {
|
||||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
throw new BlogResponseException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
||||||
}
|
}
|
||||||
request.setCharacterEncoding("utf-8");
|
request.setCharacterEncoding("utf-8");
|
||||||
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
|
response.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
|
||||||
@@ -197,10 +197,10 @@ public class ExtensionController {
|
|||||||
uploadTimes = Integer.parseInt(uploadTimesStr);
|
uploadTimes = Integer.parseInt(uploadTimesStr);
|
||||||
}
|
}
|
||||||
if (uploadTimes == 10) {
|
if (uploadTimes == 10) {
|
||||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
throw new BlogResponseException(ResponseEnum.FAILURE.getCode(), "上传次数已达10次,请2小时后在上传");
|
||||||
}
|
}
|
||||||
if (files.length == 0) {
|
if (files.length == 0) {
|
||||||
throw new MyException(ResponseEnum.NO_FILE);
|
throw new BlogResponseException(ResponseEnum.NO_FILE);
|
||||||
}
|
}
|
||||||
for (MultipartFile file : files) {
|
for (MultipartFile file : files) {
|
||||||
Map<String, Object> resp = new HashMap<>(4);
|
Map<String, Object> resp = new HashMap<>(4);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import cn.celess.common.entity.PartnerSite;
|
|||||||
import cn.celess.common.entity.dto.LinkApplyReq;
|
import cn.celess.common.entity.dto.LinkApplyReq;
|
||||||
import cn.celess.common.entity.dto.LinkReq;
|
import cn.celess.common.entity.dto.LinkReq;
|
||||||
import cn.celess.common.entity.vo.PageData;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import cn.celess.common.exception.MyException;
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
import cn.celess.common.mapper.PartnerMapper;
|
import cn.celess.common.mapper.PartnerMapper;
|
||||||
import cn.celess.common.service.MailService;
|
import cn.celess.common.service.MailService;
|
||||||
import cn.celess.common.service.PartnerSiteService;
|
import cn.celess.common.service.PartnerSiteService;
|
||||||
@@ -46,23 +46,23 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
@Override
|
@Override
|
||||||
public PartnerSite create(LinkReq reqBody) {
|
public PartnerSite create(LinkReq reqBody) {
|
||||||
if (reqBody == null) {
|
if (reqBody == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
//判空
|
//判空
|
||||||
if (reqBody.getName() == null || reqBody.getUrl() == null) {
|
if (reqBody.getName() == null || reqBody.getUrl() == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
//判空
|
//判空
|
||||||
if (reqBody.getName().replaceAll(" ", "").isEmpty() || reqBody.getUrl().replaceAll(" ", "").isEmpty()) {
|
if (reqBody.getName().replaceAll(" ", "").isEmpty() || reqBody.getUrl().replaceAll(" ", "").isEmpty()) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
//是否存在 同名
|
//是否存在 同名
|
||||||
if (partnerMapper.existsByName(reqBody.getName())) {
|
if (partnerMapper.existsByName(reqBody.getName())) {
|
||||||
throw new MyException(ResponseEnum.DATA_HAS_EXIST);
|
throw new BlogResponseException(ResponseEnum.DATA_HAS_EXIST);
|
||||||
}
|
}
|
||||||
//url是否合法
|
//url是否合法
|
||||||
if (!RegexUtil.urlMatch(reqBody.getUrl())) {
|
if (!RegexUtil.urlMatch(reqBody.getUrl())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||||
}
|
}
|
||||||
PartnerSite partnerSite = new PartnerSite();
|
PartnerSite partnerSite = new PartnerSite();
|
||||||
reqBody.setId(0);
|
reqBody.setId(0);
|
||||||
@@ -84,7 +84,7 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
public Boolean del(long id) {
|
public Boolean del(long id) {
|
||||||
//判断数据是否存在
|
//判断数据是否存在
|
||||||
if (!partnerMapper.existsById(id)) {
|
if (!partnerMapper.existsById(id)) {
|
||||||
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.DATA_NOT_EXIST);
|
||||||
}
|
}
|
||||||
return partnerMapper.delete(id) == 1;
|
return partnerMapper.delete(id) == 1;
|
||||||
}
|
}
|
||||||
@@ -93,13 +93,13 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
public PartnerSite update(LinkReq reqBody) {
|
public PartnerSite update(LinkReq reqBody) {
|
||||||
PartnerSite partnerSite = partnerMapper.findById(reqBody.getId());
|
PartnerSite partnerSite = partnerMapper.findById(reqBody.getId());
|
||||||
if (partnerSite == null) {
|
if (partnerSite == null) {
|
||||||
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.DATA_NOT_EXIST);
|
||||||
}
|
}
|
||||||
if (partnerMapper.existsByName(reqBody.getName()) && !reqBody.getName().equals(partnerSite.getName())) {
|
if (partnerMapper.existsByName(reqBody.getName()) && !reqBody.getName().equals(partnerSite.getName())) {
|
||||||
throw new MyException(ResponseEnum.DATA_HAS_EXIST);
|
throw new BlogResponseException(ResponseEnum.DATA_HAS_EXIST);
|
||||||
}
|
}
|
||||||
if (!RegexUtil.urlMatch(reqBody.getUrl())) {
|
if (!RegexUtil.urlMatch(reqBody.getUrl())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||||
}
|
}
|
||||||
if (!reqBody.getUrl().contains("http://") && !reqBody.getUrl().contains("https://")) {
|
if (!reqBody.getUrl().contains("http://") && !reqBody.getUrl().contains("https://")) {
|
||||||
reqBody.setUrl("http://" + reqBody.getUrl());
|
reqBody.setUrl("http://" + reqBody.getUrl());
|
||||||
@@ -145,17 +145,17 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
|| StringUtils.isEmpty(linkApplyReq.getUrl())
|
|| StringUtils.isEmpty(linkApplyReq.getUrl())
|
||||||
|| StringUtils.isEmpty(linkApplyReq.getEmail())
|
|| StringUtils.isEmpty(linkApplyReq.getEmail())
|
||||||
|| StringUtils.isEmpty(linkApplyReq.getLinkUrl())) {
|
|| StringUtils.isEmpty(linkApplyReq.getLinkUrl())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
// 链接不合法
|
// 链接不合法
|
||||||
if (!RegexUtil.emailMatch(linkApplyReq.getEmail())) {
|
if (!RegexUtil.emailMatch(linkApplyReq.getEmail())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
||||||
}
|
}
|
||||||
if (!RegexUtil.urlMatch(linkApplyReq.getLinkUrl()) || !RegexUtil.urlMatch(linkApplyReq.getUrl())) {
|
if (!RegexUtil.urlMatch(linkApplyReq.getLinkUrl()) || !RegexUtil.urlMatch(linkApplyReq.getUrl())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||||
}
|
}
|
||||||
if (!StringUtils.isEmpty(linkApplyReq.getIconPath()) && !RegexUtil.urlMatch(linkApplyReq.getIconPath())) {
|
if (!StringUtils.isEmpty(linkApplyReq.getIconPath()) && !RegexUtil.urlMatch(linkApplyReq.getIconPath())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_URL_ERROR);
|
||||||
}
|
}
|
||||||
// 非强制字段 设置空
|
// 非强制字段 设置空
|
||||||
if (StringUtils.isEmpty(linkApplyReq.getIconPath())) {
|
if (StringUtils.isEmpty(linkApplyReq.getIconPath())) {
|
||||||
@@ -164,7 +164,7 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
// 抓取页面
|
// 抓取页面
|
||||||
String resp = HttpUtil.getAfterRendering(linkApplyReq.getLinkUrl());
|
String resp = HttpUtil.getAfterRendering(linkApplyReq.getLinkUrl());
|
||||||
if (resp == null) {
|
if (resp == null) {
|
||||||
throw new MyException(ResponseEnum.CANNOT_GET_DATA);
|
throw new BlogResponseException(ResponseEnum.CANNOT_GET_DATA);
|
||||||
}
|
}
|
||||||
PartnerSite ps = new PartnerSite();
|
PartnerSite ps = new PartnerSite();
|
||||||
if (resp.contains(SITE_URL)) {
|
if (resp.contains(SITE_URL)) {
|
||||||
@@ -198,7 +198,7 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
redisUtil.setEx(uuid, mapper.writeValueAsString(linkApplyReq), 10, TimeUnit.MINUTES);
|
redisUtil.setEx(uuid, mapper.writeValueAsString(linkApplyReq), 10, TimeUnit.MINUTES);
|
||||||
redisUtil.setEx(linkApplyReq.getUrl(), uuid, 10, TimeUnit.MINUTES);
|
redisUtil.setEx(linkApplyReq.getUrl(), uuid, 10, TimeUnit.MINUTES);
|
||||||
}
|
}
|
||||||
throw new MyException(ResponseEnum.APPLY_LINK_NO_ADD_THIS_SITE, null, uuid);
|
throw new BlogResponseException(ResponseEnum.APPLY_LINK_NO_ADD_THIS_SITE, null, uuid);
|
||||||
}
|
}
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
@@ -207,13 +207,13 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|
|||||||
@Override
|
@Override
|
||||||
public String reapply(String key) {
|
public String reapply(String key) {
|
||||||
if (!redisUtil.hasKey(key)) {
|
if (!redisUtil.hasKey(key)) {
|
||||||
throw new MyException(ResponseEnum.DATA_EXPIRED);
|
throw new BlogResponseException(ResponseEnum.DATA_EXPIRED);
|
||||||
}
|
}
|
||||||
String s = redisUtil.get(key);
|
String s = redisUtil.get(key);
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
LinkApplyReq linkApplyReq = mapper.readValue(s, LinkApplyReq.class);
|
LinkApplyReq linkApplyReq = mapper.readValue(s, LinkApplyReq.class);
|
||||||
if (linkApplyReq == null) {
|
if (linkApplyReq == null) {
|
||||||
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.DATA_NOT_EXIST);
|
||||||
}
|
}
|
||||||
SimpleMailMessage smm = new SimpleMailMessage();
|
SimpleMailMessage smm = new SimpleMailMessage();
|
||||||
smm.setSubject("友链申请");
|
smm.setSubject("友链申请");
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import cn.celess.common.entity.Response;
|
|||||||
import cn.celess.common.entity.dto.LinkApplyReq;
|
import cn.celess.common.entity.dto.LinkApplyReq;
|
||||||
import cn.celess.common.entity.dto.LinkReq;
|
import cn.celess.common.entity.dto.LinkReq;
|
||||||
import cn.celess.common.entity.vo.PageData;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import cn.celess.common.exception.MyException;
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
import cn.celess.common.mapper.PartnerMapper;
|
import cn.celess.common.mapper.PartnerMapper;
|
||||||
import cn.celess.common.service.PartnerSiteService;
|
import cn.celess.common.service.PartnerSiteService;
|
||||||
import cn.celess.partnersite.PartnerSiteBaseTest;
|
import cn.celess.partnersite.PartnerSiteBaseTest;
|
||||||
@@ -172,7 +172,7 @@ public class PartnerSiteControllerTest extends PartnerSiteBaseTest {
|
|||||||
try {
|
try {
|
||||||
// 抓取不到数据的链接
|
// 抓取不到数据的链接
|
||||||
partnerSiteService.apply(req);
|
partnerSiteService.apply(req);
|
||||||
} catch (MyException e) {
|
} catch (BlogResponseException e) {
|
||||||
log.debug("测试抓取不到数据");
|
log.debug("测试抓取不到数据");
|
||||||
assertEquals(CANNOT_GET_DATA.getCode(), e.getCode());
|
assertEquals(CANNOT_GET_DATA.getCode(), e.getCode());
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,7 @@ public class PartnerSiteControllerTest extends PartnerSiteBaseTest {
|
|||||||
req.setUrl(req.getLinkUrl());
|
req.setUrl(req.getLinkUrl());
|
||||||
try {
|
try {
|
||||||
partnerSiteService.apply(req);
|
partnerSiteService.apply(req);
|
||||||
} catch (MyException e) {
|
} catch (BlogResponseException e) {
|
||||||
log.debug("测试未添加本站链接的友链申请");
|
log.debug("测试未添加本站链接的友链申请");
|
||||||
assertEquals(APPLY_LINK_NO_ADD_THIS_SITE.getCode(), e.getCode());
|
assertEquals(APPLY_LINK_NO_ADD_THIS_SITE.getCode(), e.getCode());
|
||||||
assertNotNull(e.getResult());
|
assertNotNull(e.getResult());
|
||||||
@@ -189,7 +189,7 @@ public class PartnerSiteControllerTest extends PartnerSiteBaseTest {
|
|||||||
// 测试uuid一致性
|
// 测试uuid一致性
|
||||||
log.debug("测试uuid一致性");
|
log.debug("测试uuid一致性");
|
||||||
partnerSiteService.apply(req);
|
partnerSiteService.apply(req);
|
||||||
} catch (MyException e2) {
|
} catch (BlogResponseException e2) {
|
||||||
assertEquals(e.getResult(), e2.getResult());
|
assertEquals(e.getResult(), e2.getResult());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -207,7 +207,7 @@ public class PartnerSiteControllerTest extends PartnerSiteBaseTest {
|
|||||||
try {
|
try {
|
||||||
partnerSiteService.reapply(randomStr());
|
partnerSiteService.reapply(randomStr());
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
} catch (MyException e) {
|
} catch (BlogResponseException e) {
|
||||||
assertEquals(DATA_EXPIRED.getCode(), e.getCode());
|
assertEquals(DATA_EXPIRED.getCode(), e.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +223,7 @@ public class PartnerSiteControllerTest extends PartnerSiteBaseTest {
|
|||||||
partnerSiteService.apply(req);
|
partnerSiteService.apply(req);
|
||||||
// err here
|
// err here
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
} catch (MyException e) {
|
} catch (BlogResponseException e) {
|
||||||
uuid = (String) e.getResult();
|
uuid = (String) e.getResult();
|
||||||
String reapply = partnerSiteService.reapply(uuid);
|
String reapply = partnerSiteService.reapply(uuid);
|
||||||
assertEquals(reapply, "success");
|
assertEquals(reapply, "success");
|
||||||
@@ -232,7 +232,7 @@ public class PartnerSiteControllerTest extends PartnerSiteBaseTest {
|
|||||||
try {
|
try {
|
||||||
partnerSiteService.reapply(uuid);
|
partnerSiteService.reapply(uuid);
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
} catch (MyException e) {
|
} catch (BlogResponseException e) {
|
||||||
assertEquals(DATA_EXPIRED.getCode(), e.getCode());
|
assertEquals(DATA_EXPIRED.getCode(), e.getCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import cn.celess.common.enmu.ResponseEnum;
|
|||||||
import cn.celess.common.entity.WebUpdate;
|
import cn.celess.common.entity.WebUpdate;
|
||||||
import cn.celess.common.entity.vo.PageData;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import cn.celess.common.entity.vo.WebUpdateModel;
|
import cn.celess.common.entity.vo.WebUpdateModel;
|
||||||
import cn.celess.common.exception.MyException;
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
import cn.celess.common.mapper.WebUpdateInfoMapper;
|
import cn.celess.common.mapper.WebUpdateInfoMapper;
|
||||||
import cn.celess.common.service.WebUpdateInfoService;
|
import cn.celess.common.service.WebUpdateInfoService;
|
||||||
import cn.celess.common.util.DateFormatUtil;
|
import cn.celess.common.util.DateFormatUtil;
|
||||||
@@ -38,11 +38,11 @@ public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
|||||||
@Override
|
@Override
|
||||||
public WebUpdateModel create(String info) {
|
public WebUpdateModel create(String info) {
|
||||||
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
WebUpdate webUpdate = new WebUpdate(info);
|
WebUpdate webUpdate = new WebUpdate(info);
|
||||||
if (webUpdateInfoMapper.insert(webUpdate) == 0) {
|
if (webUpdateInfoMapper.insert(webUpdate) == 0) {
|
||||||
throw new MyException(ResponseEnum.FAILURE);
|
throw new BlogResponseException(ResponseEnum.FAILURE);
|
||||||
}
|
}
|
||||||
return ModalTrans.webUpdate(webUpdateInfoMapper.findById(webUpdate.getId()));
|
return ModalTrans.webUpdate(webUpdateInfoMapper.findById(webUpdate.getId()));
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
|||||||
@Override
|
@Override
|
||||||
public Boolean del(long id) {
|
public Boolean del(long id) {
|
||||||
if (!webUpdateInfoMapper.existsById(id)) {
|
if (!webUpdateInfoMapper.existsById(id)) {
|
||||||
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.DATA_NOT_EXIST);
|
||||||
}
|
}
|
||||||
return webUpdateInfoMapper.delete(id) == 1;
|
return webUpdateInfoMapper.delete(id) == 1;
|
||||||
}
|
}
|
||||||
@@ -59,10 +59,10 @@ public class WebUpdateInfoServiceImpl implements WebUpdateInfoService {
|
|||||||
public WebUpdateModel update(long id, String info) {
|
public WebUpdateModel update(long id, String info) {
|
||||||
WebUpdate webUpdate = webUpdateInfoMapper.findById(id);
|
WebUpdate webUpdate = webUpdateInfoMapper.findById(id);
|
||||||
if (webUpdate == null) {
|
if (webUpdate == null) {
|
||||||
throw new MyException(ResponseEnum.DATA_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.DATA_NOT_EXIST);
|
||||||
}
|
}
|
||||||
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
if (info == null || info.replaceAll(" ", "").isEmpty()) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
webUpdate.setUpdateInfo(info);
|
webUpdate.setUpdateInfo(info);
|
||||||
webUpdateInfoMapper.update(id, info);
|
webUpdateInfoMapper.update(id, info);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import cn.celess.common.entity.dto.UserReq;
|
|||||||
import cn.celess.common.entity.vo.PageData;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import cn.celess.common.entity.vo.QiniuResponse;
|
import cn.celess.common.entity.vo.QiniuResponse;
|
||||||
import cn.celess.common.entity.vo.UserModel;
|
import cn.celess.common.entity.vo.UserModel;
|
||||||
import cn.celess.common.exception.MyException;
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
import cn.celess.common.mapper.UserMapper;
|
import cn.celess.common.mapper.UserMapper;
|
||||||
import cn.celess.common.service.MailService;
|
import cn.celess.common.service.MailService;
|
||||||
import cn.celess.common.service.QiniuService;
|
import cn.celess.common.service.QiniuService;
|
||||||
@@ -63,21 +63,21 @@ public class UserServiceImpl implements UserService {
|
|||||||
@Transient
|
@Transient
|
||||||
public Boolean registration(String email, String password) {
|
public Boolean registration(String email, String password) {
|
||||||
if (password.length() < 6 || password.length() > 16) {
|
if (password.length() < 6 || password.length() > 16) {
|
||||||
throw new MyException(ResponseEnum.PASSWORD_TOO_SHORT_OR_LONG);
|
throw new BlogResponseException(ResponseEnum.PASSWORD_TOO_SHORT_OR_LONG);
|
||||||
}
|
}
|
||||||
if (!RegexUtil.emailMatch(email)) {
|
if (!RegexUtil.emailMatch(email)) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
||||||
}
|
}
|
||||||
if (!RegexUtil.pwdMatch(password)) {
|
if (!RegexUtil.pwdMatch(password)) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_PWD_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_PWD_ERROR);
|
||||||
}
|
}
|
||||||
//验证码验证状态
|
//验证码验证状态
|
||||||
Boolean verifyStatus = (Boolean) request.getSession().getAttribute("verImgCodeStatus");
|
Boolean verifyStatus = (Boolean) request.getSession().getAttribute("verImgCodeStatus");
|
||||||
if (verifyStatus == null || !verifyStatus) {
|
if (verifyStatus == null || !verifyStatus) {
|
||||||
throw new MyException(ResponseEnum.IMG_CODE_DIDNOTVERIFY);
|
throw new BlogResponseException(ResponseEnum.IMG_CODE_DIDNOTVERIFY);
|
||||||
}
|
}
|
||||||
if (userMapper.existsByEmail(email)) {
|
if (userMapper.existsByEmail(email)) {
|
||||||
throw new MyException(ResponseEnum.USERNAME_HAS_EXIST);
|
throw new BlogResponseException(ResponseEnum.USERNAME_HAS_EXIST);
|
||||||
}
|
}
|
||||||
User user = new User(email, MD5Util.getMD5(password));
|
User user = new User(email, MD5Util.getMD5(password));
|
||||||
boolean b = userMapper.addUser(user) == 1;
|
boolean b = userMapper.addUser(user) == 1;
|
||||||
@@ -97,29 +97,29 @@ public class UserServiceImpl implements UserService {
|
|||||||
@Override
|
@Override
|
||||||
public UserModel login(LoginReq loginReq) {
|
public UserModel login(LoginReq loginReq) {
|
||||||
if (loginReq == null) {
|
if (loginReq == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
if (!RegexUtil.emailMatch(loginReq.getEmail())) {
|
if (!RegexUtil.emailMatch(loginReq.getEmail())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
||||||
}
|
}
|
||||||
if (!RegexUtil.pwdMatch(loginReq.getPassword())) {
|
if (!RegexUtil.pwdMatch(loginReq.getPassword())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_PWD_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_PWD_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = userMapper.findByEmail(loginReq.getEmail());
|
User user = userMapper.findByEmail(loginReq.getEmail());
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
// 用户不存在
|
// 用户不存在
|
||||||
throw new MyException(ResponseEnum.USER_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.USER_NOT_EXIST);
|
||||||
}
|
}
|
||||||
if (user.getStatus() != UserAccountStatusEnum.NORMAL.getCode()) {
|
if (user.getStatus() != UserAccountStatusEnum.NORMAL.getCode()) {
|
||||||
throw new MyException(ResponseEnum.CAN_NOT_USE, UserAccountStatusEnum.get(user.getStatus()));
|
throw new BlogResponseException(ResponseEnum.CAN_NOT_USE, UserAccountStatusEnum.get(user.getStatus()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取redis缓存中登录失败次数
|
//获取redis缓存中登录失败次数
|
||||||
String s = redisUtil.get(loginReq.getEmail() + "-passwordWrongTime");
|
String s = redisUtil.get(loginReq.getEmail() + "-passwordWrongTime");
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
if (Integer.parseInt(s) == 5) {
|
if (Integer.parseInt(s) == 5) {
|
||||||
throw new MyException(ResponseEnum.LOGIN_LATER, loginReq.getEmail());
|
throw new BlogResponseException(ResponseEnum.LOGIN_LATER, loginReq.getEmail());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
count++;
|
count++;
|
||||||
//更新登录失败的次数
|
//更新登录失败的次数
|
||||||
redisUtil.setEx(loginReq.getEmail() + "-passwordWrongTime", count + "", 2, TimeUnit.HOURS);
|
redisUtil.setEx(loginReq.getEmail() + "-passwordWrongTime", count + "", 2, TimeUnit.HOURS);
|
||||||
throw new MyException(ResponseEnum.LOGIN_FAILURE);
|
throw new BlogResponseException(ResponseEnum.LOGIN_FAILURE);
|
||||||
}
|
}
|
||||||
UserModel trans = ModalTrans.userFullInfo(user);
|
UserModel trans = ModalTrans.userFullInfo(user);
|
||||||
trans.setToken(token);
|
trans.setToken(token);
|
||||||
@@ -182,7 +182,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
public String getUserRoleByEmail(String email) {
|
public String getUserRoleByEmail(String email) {
|
||||||
String role = userMapper.getRoleByEmail(email);
|
String role = userMapper.getRoleByEmail(email);
|
||||||
if (role == null) {
|
if (role == null) {
|
||||||
throw new MyException(ResponseEnum.USER_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.USER_NOT_EXIST);
|
||||||
}
|
}
|
||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
@@ -214,7 +214,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
@Override
|
@Override
|
||||||
public Object sendResetPwdEmail(String email) {
|
public Object sendResetPwdEmail(String email) {
|
||||||
if (!RegexUtil.emailMatch(email)) {
|
if (!RegexUtil.emailMatch(email)) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = userMapper.findByEmail(email);
|
User user = userMapper.findByEmail(email);
|
||||||
@@ -223,7 +223,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!user.getEmailStatus()) {
|
if (!user.getEmailStatus()) {
|
||||||
throw new MyException(ResponseEnum.USEREMAIL_NOT_VERIFY);
|
throw new BlogResponseException(ResponseEnum.USEREMAIL_NOT_VERIFY);
|
||||||
}
|
}
|
||||||
|
|
||||||
String verifyId = UUID.randomUUID().toString().replaceAll("-", "");
|
String verifyId = UUID.randomUUID().toString().replaceAll("-", "");
|
||||||
@@ -242,7 +242,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
@Override
|
@Override
|
||||||
public Object sendVerifyEmail(String email) {
|
public Object sendVerifyEmail(String email) {
|
||||||
if (!RegexUtil.emailMatch(email)) {
|
if (!RegexUtil.emailMatch(email)) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = userMapper.findByEmail(email);
|
User user = userMapper.findByEmail(email);
|
||||||
@@ -270,14 +270,14 @@ public class UserServiceImpl implements UserService {
|
|||||||
public Object verifyEmail(String verifyId, String email) {
|
public Object verifyEmail(String verifyId, String email) {
|
||||||
User user = userMapper.findByEmail(email);
|
User user = userMapper.findByEmail(email);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new MyException(ResponseEnum.FAILURE);
|
throw new BlogResponseException(ResponseEnum.FAILURE);
|
||||||
}
|
}
|
||||||
if (user.getEmailStatus()) {
|
if (user.getEmailStatus()) {
|
||||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "邮箱已验证过了");
|
throw new BlogResponseException(ResponseEnum.FAILURE.getCode(), "邮箱已验证过了");
|
||||||
}
|
}
|
||||||
String verifyIdFromCache = redisUtil.get(user.getEmail() + "-verify");
|
String verifyIdFromCache = redisUtil.get(user.getEmail() + "-verify");
|
||||||
if (verifyIdFromCache == null) {
|
if (verifyIdFromCache == null) {
|
||||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "验证链接无效");
|
throw new BlogResponseException(ResponseEnum.FAILURE.getCode(), "验证链接无效");
|
||||||
}
|
}
|
||||||
if (verifyIdFromCache.equals(verifyId)) {
|
if (verifyIdFromCache.equals(verifyId)) {
|
||||||
userMapper.updateEmailStatus(email, true);
|
userMapper.updateEmailStatus(email, true);
|
||||||
@@ -286,7 +286,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
redisUserUtil.set(user);
|
redisUserUtil.set(user);
|
||||||
return "验证成功";
|
return "验证成功";
|
||||||
} else {
|
} else {
|
||||||
throw new MyException(ResponseEnum.FAILURE);
|
throw new BlogResponseException(ResponseEnum.FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,27 +294,27 @@ public class UserServiceImpl implements UserService {
|
|||||||
public Object reSetPwd(String verifyId, String email, String pwd) {
|
public Object reSetPwd(String verifyId, String email, String pwd) {
|
||||||
User user = userMapper.findByEmail(email);
|
User user = userMapper.findByEmail(email);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new MyException(ResponseEnum.USER_NOT_EXIST);
|
throw new BlogResponseException(ResponseEnum.USER_NOT_EXIST);
|
||||||
}
|
}
|
||||||
if (!RegexUtil.pwdMatch(pwd)) {
|
if (!RegexUtil.pwdMatch(pwd)) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_PWD_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_PWD_ERROR);
|
||||||
}
|
}
|
||||||
if (!user.getEmailStatus()) {
|
if (!user.getEmailStatus()) {
|
||||||
throw new MyException(ResponseEnum.USEREMAIL_NOT_VERIFY);
|
throw new BlogResponseException(ResponseEnum.USEREMAIL_NOT_VERIFY);
|
||||||
}
|
}
|
||||||
String resetPwdIdFromCache = redisUtil.get(user.getEmail() + "-resetPwd");
|
String resetPwdIdFromCache = redisUtil.get(user.getEmail() + "-resetPwd");
|
||||||
if (resetPwdIdFromCache == null) {
|
if (resetPwdIdFromCache == null) {
|
||||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "请先获取重置密码的邮件");
|
throw new BlogResponseException(ResponseEnum.FAILURE.getCode(), "请先获取重置密码的邮件");
|
||||||
}
|
}
|
||||||
if (resetPwdIdFromCache.equals(verifyId)) {
|
if (resetPwdIdFromCache.equals(verifyId)) {
|
||||||
if (MD5Util.getMD5(pwd).equals(user.getPwd())) {
|
if (MD5Util.getMD5(pwd).equals(user.getPwd())) {
|
||||||
throw new MyException(ResponseEnum.PWD_SAME);
|
throw new BlogResponseException(ResponseEnum.PWD_SAME);
|
||||||
}
|
}
|
||||||
userMapper.updatePwd(email, MD5Util.getMD5(pwd));
|
userMapper.updatePwd(email, MD5Util.getMD5(pwd));
|
||||||
redisUtil.delete(user.getEmail() + "-resetPwd");
|
redisUtil.delete(user.getEmail() + "-resetPwd");
|
||||||
return "验证成功";
|
return "验证成功";
|
||||||
} else {
|
} else {
|
||||||
throw new MyException(ResponseEnum.FAILURE.getCode(), "标识码不一致");
|
throw new BlogResponseException(ResponseEnum.FAILURE.getCode(), "标识码不一致");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,7 +360,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
@Override
|
@Override
|
||||||
public UserModel adminUpdate(UserReq userReq) {
|
public UserModel adminUpdate(UserReq userReq) {
|
||||||
if (userReq == null || userReq.getId() == null) {
|
if (userReq == null || userReq.getId() == null) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
User user = userMapper.findById(userReq.getId());
|
User user = userMapper.findById(userReq.getId());
|
||||||
// 设置数据
|
// 设置数据
|
||||||
@@ -375,10 +375,10 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
if (userReq.getPwd() != null) {
|
if (userReq.getPwd() != null) {
|
||||||
if (userReq.getPwd().length() < 6 || userReq.getPwd().length() > 16) {
|
if (userReq.getPwd().length() < 6 || userReq.getPwd().length() > 16) {
|
||||||
throw new MyException(ResponseEnum.PASSWORD_TOO_SHORT_OR_LONG);
|
throw new BlogResponseException(ResponseEnum.PASSWORD_TOO_SHORT_OR_LONG);
|
||||||
}
|
}
|
||||||
if (!RegexUtil.pwdMatch(userReq.getPwd())) {
|
if (!RegexUtil.pwdMatch(userReq.getPwd())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_PWD_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_PWD_ERROR);
|
||||||
}
|
}
|
||||||
user.setPwd(MD5Util.getMD5(userReq.getPwd()));
|
user.setPwd(MD5Util.getMD5(userReq.getPwd()));
|
||||||
}
|
}
|
||||||
@@ -386,19 +386,19 @@ public class UserServiceImpl implements UserService {
|
|||||||
if (RoleEnum.USER_ROLE.getRoleName().equals(userReq.getRole()) || RoleEnum.ADMIN_ROLE.getRoleName().equals(userReq.getRole())) {
|
if (RoleEnum.USER_ROLE.getRoleName().equals(userReq.getRole()) || RoleEnum.ADMIN_ROLE.getRoleName().equals(userReq.getRole())) {
|
||||||
user.setRole(userReq.getRole());
|
user.setRole(userReq.getRole());
|
||||||
} else {
|
} else {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (userReq.getEmail() != null) {
|
if (userReq.getEmail() != null) {
|
||||||
if (!RegexUtil.emailMatch(userReq.getEmail())) {
|
if (!RegexUtil.emailMatch(userReq.getEmail())) {
|
||||||
throw new MyException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
throw new BlogResponseException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
|
||||||
}
|
}
|
||||||
user.setEmail(userReq.getEmail());
|
user.setEmail(userReq.getEmail());
|
||||||
}
|
}
|
||||||
// 数据写入
|
// 数据写入
|
||||||
int updateResult = userMapper.update(user);
|
int updateResult = userMapper.update(user);
|
||||||
if (updateResult == 0) {
|
if (updateResult == 0) {
|
||||||
throw new MyException(ResponseEnum.FAILURE);
|
throw new BlogResponseException(ResponseEnum.FAILURE);
|
||||||
}
|
}
|
||||||
if (redisUserUtil.get().getId().equals(userReq.getId())) {
|
if (redisUserUtil.get().getId().equals(userReq.getId())) {
|
||||||
redisUserUtil.set(user);
|
redisUserUtil.set(user);
|
||||||
@@ -417,10 +417,10 @@ public class UserServiceImpl implements UserService {
|
|||||||
User user = redisUserUtil.get();
|
User user = redisUserUtil.get();
|
||||||
String pwd1 = userMapper.getPwd(user.getEmail());
|
String pwd1 = userMapper.getPwd(user.getEmail());
|
||||||
if (!MD5Util.getMD5(pwd).equals(pwd1)) {
|
if (!MD5Util.getMD5(pwd).equals(pwd1)) {
|
||||||
throw new MyException(ResponseEnum.PWD_WRONG);
|
throw new BlogResponseException(ResponseEnum.PWD_WRONG);
|
||||||
}
|
}
|
||||||
if (!newPwd.equals(confirmPwd)) {
|
if (!newPwd.equals(confirmPwd)) {
|
||||||
throw new MyException(ResponseEnum.PWD_NOT_SAME);
|
throw new BlogResponseException(ResponseEnum.PWD_NOT_SAME);
|
||||||
}
|
}
|
||||||
userMapper.updatePwd(user.getEmail(), MD5Util.getMD5(newPwd));
|
userMapper.updatePwd(user.getEmail(), MD5Util.getMD5(newPwd));
|
||||||
return ModalTrans.userFullInfo(userMapper.findByEmail(user.getEmail()));
|
return ModalTrans.userFullInfo(userMapper.findByEmail(user.getEmail()));
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package cn.celess.user.util;
|
|||||||
|
|
||||||
import cn.celess.common.enmu.ResponseEnum;
|
import cn.celess.common.enmu.ResponseEnum;
|
||||||
import cn.celess.common.entity.User;
|
import cn.celess.common.entity.User;
|
||||||
import cn.celess.common.exception.MyException;
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
import io.jsonwebtoken.*;
|
import io.jsonwebtoken.*;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@@ -96,10 +96,10 @@ public class JwtUtil {
|
|||||||
log.info("JWT令牌过期");
|
log.info("JWT令牌过期");
|
||||||
} catch (UnsupportedJwtException e) {
|
} catch (UnsupportedJwtException e) {
|
||||||
log.info("不支持的JWT令牌");
|
log.info("不支持的JWT令牌");
|
||||||
throw new MyException(ResponseEnum.JWT_NOT_SUPPORT);
|
throw new BlogResponseException(ResponseEnum.JWT_NOT_SUPPORT);
|
||||||
} catch (MalformedJwtException e) {
|
} catch (MalformedJwtException e) {
|
||||||
log.info("JWT令牌格式错误");
|
log.info("JWT令牌格式错误");
|
||||||
throw new MyException(ResponseEnum.JWT_MALFORMED);
|
throw new BlogResponseException(ResponseEnum.JWT_MALFORMED);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
log.debug("JWT非法参数");
|
log.debug("JWT非法参数");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package cn.celess.user.util;
|
|||||||
|
|
||||||
import cn.celess.common.enmu.ResponseEnum;
|
import cn.celess.common.enmu.ResponseEnum;
|
||||||
import cn.celess.common.entity.User;
|
import cn.celess.common.entity.User;
|
||||||
import cn.celess.common.exception.MyException;
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
import cn.celess.common.util.RedisUtil;
|
import cn.celess.common.util.RedisUtil;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
@@ -28,7 +28,7 @@ public class RedisUserUtil {
|
|||||||
public User get() {
|
public User get() {
|
||||||
User user = getWithOutExc();
|
User user = getWithOutExc();
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new MyException(ResponseEnum.HAVE_NOT_LOG_IN);
|
throw new BlogResponseException(ResponseEnum.HAVE_NOT_LOG_IN);
|
||||||
}
|
}
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import cn.celess.common.entity.User;
|
|||||||
import cn.celess.common.entity.dto.LoginReq;
|
import cn.celess.common.entity.dto.LoginReq;
|
||||||
import cn.celess.common.entity.vo.PageData;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import cn.celess.common.entity.vo.UserModel;
|
import cn.celess.common.entity.vo.UserModel;
|
||||||
import cn.celess.common.exception.MyException;
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
import cn.celess.common.mapper.UserMapper;
|
import cn.celess.common.mapper.UserMapper;
|
||||||
import cn.celess.common.service.UserService;
|
import cn.celess.common.service.UserService;
|
||||||
import cn.celess.common.util.MD5Util;
|
import cn.celess.common.util.MD5Util;
|
||||||
@@ -55,7 +55,7 @@ public class UserServiceTest extends UserBaseTest {
|
|||||||
try {
|
try {
|
||||||
userService.login(loginReq);
|
userService.login(loginReq);
|
||||||
fail("测试登录被锁账户 失败!");
|
fail("测试登录被锁账户 失败!");
|
||||||
} catch (MyException e) {
|
} catch (BlogResponseException e) {
|
||||||
assertEquals(ResponseEnum.CAN_NOT_USE.getCode(), e.getCode());
|
assertEquals(ResponseEnum.CAN_NOT_USE.getCode(), e.getCode());
|
||||||
assertEquals(UserAccountStatusEnum.LOCKED, e.getResult());
|
assertEquals(UserAccountStatusEnum.LOCKED, e.getResult());
|
||||||
}
|
}
|
||||||
@@ -64,7 +64,7 @@ public class UserServiceTest extends UserBaseTest {
|
|||||||
try {
|
try {
|
||||||
userService.login(loginReq);
|
userService.login(loginReq);
|
||||||
fail("测试登录被删除账户 失败!");
|
fail("测试登录被删除账户 失败!");
|
||||||
} catch (MyException e) {
|
} catch (BlogResponseException e) {
|
||||||
assertEquals(ResponseEnum.CAN_NOT_USE.getCode(), e.getCode());
|
assertEquals(ResponseEnum.CAN_NOT_USE.getCode(), e.getCode());
|
||||||
assertEquals(UserAccountStatusEnum.DELETED, e.getResult());
|
assertEquals(UserAccountStatusEnum.DELETED, e.getResult());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import cn.celess.common.enmu.ResponseEnum;
|
|||||||
import cn.celess.common.entity.Visitor;
|
import cn.celess.common.entity.Visitor;
|
||||||
import cn.celess.common.entity.vo.PageData;
|
import cn.celess.common.entity.vo.PageData;
|
||||||
import cn.celess.common.entity.vo.VisitorModel;
|
import cn.celess.common.entity.vo.VisitorModel;
|
||||||
import cn.celess.common.exception.MyException;
|
import cn.celess.common.exception.BlogResponseException;
|
||||||
import cn.celess.common.mapper.VisitorMapper;
|
import cn.celess.common.mapper.VisitorMapper;
|
||||||
import cn.celess.common.service.VisitorService;
|
import cn.celess.common.service.VisitorService;
|
||||||
import cn.celess.common.util.DateFormatUtil;
|
import cn.celess.common.util.DateFormatUtil;
|
||||||
@@ -75,7 +75,7 @@ public class VisitorServiceImpl implements VisitorService {
|
|||||||
redisUtil.setEx("dayVisitCount", count + "", secondsLeftToday, TimeUnit.SECONDS);
|
redisUtil.setEx("dayVisitCount", count + "", secondsLeftToday, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
if (visitorMapper.insert(visitor) == 0) {
|
if (visitorMapper.insert(visitor) == 0) {
|
||||||
throw new MyException(ResponseEnum.FAILURE);
|
throw new BlogResponseException(ResponseEnum.FAILURE);
|
||||||
}
|
}
|
||||||
return trans(visitor);
|
return trans(visitor);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user