refactor:代码规范修改
This commit is contained in:
parent
b8baf22387
commit
b8f3d4f3b7
@ -21,6 +21,7 @@ public interface BookmarkApi {
|
|||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @param delete 是否删除问题数据
|
* @param delete 是否删除问题数据
|
||||||
* @param userId userId
|
* @param userId userId
|
||||||
|
* @return 返回删除的数据
|
||||||
* @date 2021/3/17
|
* @date 2021/3/17
|
||||||
**/
|
**/
|
||||||
Set<String> dealBadBookmark(boolean delete, int userId);
|
Set<String> dealBadBookmark(boolean delete, int userId);
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package com.fanxb.bookmark.business.api;
|
package com.fanxb.bookmark.business.api;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/8/20 下午2:12
|
||||||
|
*/
|
||||||
public interface UserApi {
|
public interface UserApi {
|
||||||
/**
|
/**
|
||||||
* 版本自增
|
* 版本自增
|
||||||
|
@ -13,7 +13,8 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA
|
* Created with IntelliJ IDEA
|
||||||
* Created By Fxb
|
*
|
||||||
|
* @author fanxb
|
||||||
* Date: 2020/3/29
|
* Date: 2020/3/29
|
||||||
* Time: 13:08
|
* Time: 13:08
|
||||||
*/
|
*/
|
||||||
|
@ -21,7 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@RequestMapping("/bookmarkBackup")
|
@RequestMapping("/bookmarkBackup")
|
||||||
public class BookmarkBackupController {
|
public class BookmarkBackupController {
|
||||||
|
|
||||||
private BookmarkBackupService backupService;
|
private final BookmarkBackupService backupService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public BookmarkBackupController(BookmarkBackupServiceImpl backupService) {
|
public BookmarkBackupController(BookmarkBackupServiceImpl backupService) {
|
||||||
@ -31,7 +31,7 @@ public class BookmarkBackupController {
|
|||||||
@PostMapping("/mysqlToEs")
|
@PostMapping("/mysqlToEs")
|
||||||
public Result backupToEs() {
|
public Result backupToEs() {
|
||||||
//异步执行同步任务
|
//异步执行同步任务
|
||||||
ThreadPoolUtil.execute(() -> backupService.backupToEs());
|
ThreadPoolUtil.execute(backupService::backupToEs);
|
||||||
return Result.success(null);
|
return Result.success(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,6 +187,7 @@ public interface BookmarkDao extends BaseMapper<Bookmark> {
|
|||||||
/**
|
/**
|
||||||
* 批量更新searchKey
|
* 批量更新searchKey
|
||||||
*
|
*
|
||||||
|
* @param list list
|
||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @date 2020/3/22 22:08
|
* @date 2020/3/22 22:08
|
||||||
*/
|
*/
|
||||||
@ -213,16 +214,28 @@ public interface BookmarkDao extends BaseMapper<Bookmark> {
|
|||||||
@Update("update bookmark set visitNum=visitNum+1 where userId=#{userId} and bookmarkId=#{bookmarkId}")
|
@Update("update bookmark set visitNum=visitNum+1 where userId=#{userId} and bookmarkId=#{bookmarkId}")
|
||||||
void updateVisitNum(VisitNumPlus item);
|
void updateVisitNum(VisitNumPlus item);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询用户最常访问的几个书签
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
* @param num num
|
||||||
|
* @return java.util.List<com.fanxb.bookmark.common.entity.Bookmark>
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/8/20 上午11:52
|
||||||
|
*/
|
||||||
@Select("select bookmarkId,name,url,icon from bookmark where userId=#{userId} and type=0 order by visitNum desc limit 0,#{num}")
|
@Select("select bookmarkId,name,url,icon from bookmark where userId=#{userId} and type=0 order by visitNum desc limit 0,#{num}")
|
||||||
List<Bookmark> selectPopular(@Param("userId") int userId, @Param("num") int num);
|
List<Bookmark> selectPopular(@Param("userId") int userId, @Param("num") int num);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取某用户无icon的条目
|
* 获取某用户无icon的条目
|
||||||
*
|
*
|
||||||
|
* @param userId userId
|
||||||
|
* @param start 开始
|
||||||
|
* @param size 数量
|
||||||
* @return java.util.List<com.fanxb.bookmark.common.entity.Bookmark>
|
* @return java.util.List<com.fanxb.bookmark.common.entity.Bookmark>
|
||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @date 2021/3/11
|
* @date 2021/8/20 下午12:02
|
||||||
**/
|
*/
|
||||||
@Select("select userId,bookmarkId,url,icon from bookmark where userId=#{userId} and icon='' order by bookmarkId asc limit #{start},#{size}")
|
@Select("select userId,bookmarkId,url,icon from bookmark where userId=#{userId} and icon='' order by bookmarkId asc limit #{start},#{size}")
|
||||||
List<Bookmark> selectUserNoIcon(@Param("userId") int userId, @Param("start") int start, @Param("size") int size);
|
List<Bookmark> selectUserNoIcon(@Param("userId") int userId, @Param("start") int start, @Param("size") int size);
|
||||||
|
|
||||||
@ -238,12 +251,13 @@ public interface BookmarkDao extends BaseMapper<Bookmark> {
|
|||||||
void updateIcon(@Param("bookmarkId") int bookmarkId, @Param("icon") String icon);
|
void updateIcon(@Param("bookmarkId") int bookmarkId, @Param("icon") String icon);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取某用户所有的id,bookmark
|
* 查询一个用户全部的书签路径
|
||||||
*
|
*
|
||||||
* @param userId userId
|
* @param userId userId
|
||||||
|
* @return java.util.List<com.fanxb.bookmark.common.entity.Bookmark>
|
||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @date 2021/3/17
|
* @date 2021/8/20 上午11:58
|
||||||
**/
|
*/
|
||||||
@Select("select bookmarkId,path from bookmark where userId=#{userId}")
|
@Select("select bookmarkId,path from bookmark where userId=#{userId}")
|
||||||
List<Bookmark> selectBookmarkIdPathByUserId(int userId);
|
List<Bookmark> selectBookmarkIdPathByUserId(int userId);
|
||||||
|
|
||||||
|
@ -8,7 +8,8 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA
|
* Created with IntelliJ IDEA
|
||||||
* Created By Fxb
|
*
|
||||||
|
* @author fanxb
|
||||||
* Date: 2020/3/19
|
* Date: 2020/3/19
|
||||||
* Time: 0:05
|
* Time: 0:05
|
||||||
*/
|
*/
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
package com.fanxb.bookmark.business.bookmark.service;
|
package com.fanxb.bookmark.business.bookmark.service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA
|
* @author fanxb
|
||||||
* Created By Fxb
|
|
||||||
* Date: 2020/3/29
|
* Date: 2020/3/29
|
||||||
* Time: 12:43
|
* Time: 12:43
|
||||||
*/
|
*/
|
||||||
@ -20,6 +19,7 @@ public interface BookmarkBackupService {
|
|||||||
/**
|
/**
|
||||||
* Description: 将某个用户的书签数据mysql同步到es中
|
* Description: 将某个用户的书签数据mysql同步到es中
|
||||||
*
|
*
|
||||||
|
* @param userId 用户id
|
||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @date 2019/7/26 11:27
|
* @date 2019/7/26 11:27
|
||||||
*/
|
*/
|
||||||
|
@ -11,7 +11,8 @@ import java.util.Set;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA
|
* Created with IntelliJ IDEA
|
||||||
* Created By Fxb
|
*
|
||||||
|
* @author fanxb
|
||||||
* Date: 2020/3/29
|
* Date: 2020/3/29
|
||||||
* Time: 12:25
|
* Time: 12:25
|
||||||
*/
|
*/
|
||||||
@ -48,6 +49,8 @@ public interface BookmarkService {
|
|||||||
*
|
*
|
||||||
* @param stream 输入流
|
* @param stream 输入流
|
||||||
* @param path 存放路径
|
* @param path 存放路径
|
||||||
|
* @param userId userId
|
||||||
|
* @throws Exception 各种异常
|
||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @date 2019/7/9 18:44
|
* @date 2019/7/9 18:44
|
||||||
*/
|
*/
|
||||||
@ -68,6 +71,7 @@ public interface BookmarkService {
|
|||||||
*
|
*
|
||||||
* @param userId userId
|
* @param userId userId
|
||||||
* @param bookmark bookmark
|
* @param bookmark bookmark
|
||||||
|
* @return 更新后的icon
|
||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @date 2019/7/17 14:42
|
* @date 2019/7/17 14:42
|
||||||
*/
|
*/
|
||||||
|
@ -6,7 +6,8 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA
|
* Created with IntelliJ IDEA
|
||||||
* Created By Fxb
|
*
|
||||||
|
* @author fanxb
|
||||||
* Date: 2020/3/18
|
* Date: 2020/3/18
|
||||||
* Time: 23:47
|
* Time: 23:47
|
||||||
*/
|
*/
|
||||||
@ -15,15 +16,15 @@ public interface PinYinService {
|
|||||||
/**
|
/**
|
||||||
* 分隔符
|
* 分隔符
|
||||||
*/
|
*/
|
||||||
static final String PARTITION = "||";
|
String PARTITION = "||";
|
||||||
/**
|
/**
|
||||||
* 拼音接口路径
|
* 拼音接口路径
|
||||||
*/
|
*/
|
||||||
static final String PATH = "/pinyinChange";
|
String PATH = "/pinyinChange";
|
||||||
/**
|
/**
|
||||||
* 分页查询页大小
|
* 分页查询页大小
|
||||||
*/
|
*/
|
||||||
static final int SIZE = 500;
|
int SIZE = 500;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 功能描述: 首次上线用于全量初始化
|
* 功能描述: 首次上线用于全量初始化
|
||||||
|
@ -27,7 +27,8 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA
|
* Created with IntelliJ IDEA
|
||||||
* Created By Fxb
|
*
|
||||||
|
* @author fanxb
|
||||||
* Date: 2020/3/18
|
* Date: 2020/3/18
|
||||||
* Time: 23:48
|
* Time: 23:48
|
||||||
*/
|
*/
|
||||||
|
@ -12,7 +12,8 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA
|
* Created with IntelliJ IDEA
|
||||||
* Created By Fxb
|
*
|
||||||
|
* @author fanxb
|
||||||
* Date: 2020/3/10
|
* Date: 2020/3/10
|
||||||
* Time: 23:16
|
* Time: 23:16
|
||||||
*/
|
*/
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.fanxb.bookmark.business.user.controller;
|
package com.fanxb.bookmark.business.user.controller;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.fanxb.bookmark.business.user.service.OAuthService;
|
import com.fanxb.bookmark.business.user.service.OauthService;
|
||||||
import com.fanxb.bookmark.business.user.service.UserService;
|
import com.fanxb.bookmark.business.user.service.UserService;
|
||||||
import com.fanxb.bookmark.business.user.vo.LoginBody;
|
import com.fanxb.bookmark.business.user.vo.LoginBody;
|
||||||
import com.fanxb.bookmark.business.user.vo.OAuthBody;
|
import com.fanxb.bookmark.business.user.vo.OauthBody;
|
||||||
import com.fanxb.bookmark.business.user.vo.RegisterBody;
|
import com.fanxb.bookmark.business.user.vo.RegisterBody;
|
||||||
import com.fanxb.bookmark.business.user.service.impl.UserServiceImpl;
|
import com.fanxb.bookmark.business.user.service.impl.UserServiceImpl;
|
||||||
import com.fanxb.bookmark.common.entity.Result;
|
import com.fanxb.bookmark.common.entity.Result;
|
||||||
@ -28,11 +28,11 @@ import javax.validation.Valid;
|
|||||||
public class UserController {
|
public class UserController {
|
||||||
|
|
||||||
private final UserServiceImpl userServiceImpl;
|
private final UserServiceImpl userServiceImpl;
|
||||||
private final OAuthService oAuthService;
|
private final OauthService oAuthService;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public UserController(UserServiceImpl userServiceImpl, OAuthService oAuthService, UserService userService) {
|
public UserController(UserServiceImpl userServiceImpl, OauthService oAuthService, UserService userService) {
|
||||||
this.userServiceImpl = userServiceImpl;
|
this.userServiceImpl = userServiceImpl;
|
||||||
this.oAuthService = oAuthService;
|
this.oAuthService = oAuthService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
@ -142,7 +142,7 @@ public class UserController {
|
|||||||
* @date 2021/3/10
|
* @date 2021/3/10
|
||||||
*/
|
*/
|
||||||
@PostMapping("oAuthLogin")
|
@PostMapping("oAuthLogin")
|
||||||
public Result oAuthLogin(@RequestBody OAuthBody body) {
|
public Result oAuthLogin(@RequestBody OauthBody body) {
|
||||||
return Result.success(oAuthService.oAuthCheck(body));
|
return Result.success(oAuthService.oAuthCheck(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,13 +3,16 @@ package com.fanxb.bookmark.business.user.dao;
|
|||||||
import com.fanxb.bookmark.business.user.entity.Feedback;
|
import com.fanxb.bookmark.business.user.entity.Feedback;
|
||||||
import org.apache.ibatis.annotations.Insert;
|
import org.apache.ibatis.annotations.Insert;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA
|
* Created with IntelliJ IDEA
|
||||||
* Created By Fxb
|
*
|
||||||
|
* @author fanxb
|
||||||
* Date: 2020/3/10
|
* Date: 2020/3/10
|
||||||
* Time: 23:14
|
* Time: 23:14
|
||||||
*/
|
*/
|
||||||
|
@Component
|
||||||
public interface FeedbackDao {
|
public interface FeedbackDao {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,7 +62,8 @@ public interface UserDao {
|
|||||||
/**
|
/**
|
||||||
* Description: 根据用户id查询用户信息
|
* Description: 根据用户id查询用户信息
|
||||||
*
|
*
|
||||||
* @param userId userId
|
* @param userId userId
|
||||||
|
* @param githubId githubId
|
||||||
* @return com.fanxb.bookmark.common.entity.User
|
* @return com.fanxb.bookmark.common.entity.User
|
||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @date 2019/7/30 16:08
|
* @date 2019/7/30 16:08
|
||||||
|
@ -6,7 +6,8 @@ import javax.validation.constraints.NotEmpty;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA
|
* Created with IntelliJ IDEA
|
||||||
* Created By Fxb
|
*
|
||||||
|
* @author fanxb
|
||||||
* Date: 2020/3/10
|
* Date: 2020/3/10
|
||||||
* Time: 23:13
|
* Time: 23:13
|
||||||
*/
|
*/
|
||||||
|
@ -4,7 +4,8 @@ import com.fanxb.bookmark.business.user.entity.Feedback;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA
|
* Created with IntelliJ IDEA
|
||||||
* Created By Fxb
|
*
|
||||||
|
* @author fanxb
|
||||||
* Date: 2020/3/10
|
* Date: 2020/3/10
|
||||||
* Time: 23:17
|
* Time: 23:17
|
||||||
*/
|
*/
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
package com.fanxb.bookmark.business.user.service;
|
|
||||||
|
|
||||||
import com.fanxb.bookmark.business.user.vo.OAuthBody;
|
|
||||||
|
|
||||||
public interface OAuthService {
|
|
||||||
|
|
||||||
String oAuthCheck(OAuthBody body);
|
|
||||||
}
|
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.fanxb.bookmark.business.user.service;
|
||||||
|
|
||||||
|
import com.fanxb.bookmark.business.user.vo.OauthBody;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/8/20 下午2:13
|
||||||
|
*/
|
||||||
|
public interface OauthService {
|
||||||
|
/**
|
||||||
|
* oauth登陆校验
|
||||||
|
*
|
||||||
|
* @param body body
|
||||||
|
* @return java.lang.String
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/8/20 下午2:13
|
||||||
|
*/
|
||||||
|
String oAuthCheck(OauthBody body);
|
||||||
|
}
|
@ -38,6 +38,7 @@ public interface UserService {
|
|||||||
/**
|
/**
|
||||||
* 获取当前用户的version
|
* 获取当前用户的version
|
||||||
*
|
*
|
||||||
|
* @param userId userId
|
||||||
* @return int
|
* @return int
|
||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @date 2021/3/11
|
* @date 2021/3/11
|
||||||
@ -56,6 +57,7 @@ public interface UserService {
|
|||||||
* 检查所有用户的问题书签数据
|
* 检查所有用户的问题书签数据
|
||||||
*
|
*
|
||||||
* @param delete 是否删除问题数据
|
* @param delete 是否删除问题数据
|
||||||
|
* @return 返回用户删除的数据
|
||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @date 2021/3/17
|
* @date 2021/3/17
|
||||||
**/
|
**/
|
||||||
|
@ -9,14 +9,19 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Created with IntelliJ IDEA
|
* Created with IntelliJ IDEA
|
||||||
* Created By Fxb
|
*
|
||||||
|
* @author fanxb
|
||||||
* Date: 2020/3/10
|
* Date: 2020/3/10
|
||||||
* Time: 23:17
|
* Time: 23:17
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class FeedbackServiceImpl implements FeedbackService {
|
public class FeedbackServiceImpl implements FeedbackService {
|
||||||
|
private final FeedbackDao feedbackDao;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private FeedbackDao feedbackDao;
|
public FeedbackServiceImpl(FeedbackDao feedbackDao) {
|
||||||
|
this.feedbackDao = feedbackDao;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addOne(Feedback feedback) {
|
public void addOne(Feedback feedback) {
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
package com.fanxb.bookmark.business.user.service.impl;
|
package com.fanxb.bookmark.business.user.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.util.RandomUtil;
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.fanxb.bookmark.business.user.dao.UserDao;
|
import com.fanxb.bookmark.business.user.dao.UserDao;
|
||||||
import com.fanxb.bookmark.business.user.service.OAuthService;
|
import com.fanxb.bookmark.business.user.service.OauthService;
|
||||||
import com.fanxb.bookmark.business.user.service.UserService;
|
import com.fanxb.bookmark.business.user.service.UserService;
|
||||||
import com.fanxb.bookmark.business.user.vo.OAuthBody;
|
import com.fanxb.bookmark.business.user.vo.OauthBody;
|
||||||
import com.fanxb.bookmark.common.constant.Constant;
|
import com.fanxb.bookmark.common.constant.Constant;
|
||||||
import com.fanxb.bookmark.common.entity.User;
|
import com.fanxb.bookmark.common.entity.User;
|
||||||
import com.fanxb.bookmark.common.exception.CustomException;
|
import com.fanxb.bookmark.common.exception.CustomException;
|
||||||
@ -33,7 +32,7 @@ import static com.fanxb.bookmark.business.user.service.UserService.SHORT_EXPIRE_
|
|||||||
**/
|
**/
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class OAuthServiceImpl implements OAuthService {
|
public class OauthServiceImpl implements OauthService {
|
||||||
|
|
||||||
@Value("${OAuth.github.clientId}")
|
@Value("${OAuth.github.clientId}")
|
||||||
private String githubClientId;
|
private String githubClientId;
|
||||||
@ -43,16 +42,16 @@ public class OAuthServiceImpl implements OAuthService {
|
|||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public OAuthServiceImpl(UserDao userDao, UserService userService) {
|
public OauthServiceImpl(UserDao userDao, UserService userService) {
|
||||||
this.userDao = userDao;
|
this.userDao = userDao;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public String oAuthCheck(OAuthBody body) {
|
public String oAuthCheck(OauthBody body) {
|
||||||
User current, other = new User();
|
User current, other = new User();
|
||||||
if (StrUtil.equals(body.getType(), OAuthBody.GITHUB)) {
|
if (StrUtil.equals(body.getType(), OauthBody.GITHUB)) {
|
||||||
Map<String, String> header = new HashMap<>(2);
|
Map<String, String> header = new HashMap<>(2);
|
||||||
header.put("accept", "application/json");
|
header.put("accept", "application/json");
|
||||||
String url = "https://github.com/login/oauth/access_token?client_id=" + githubClientId + "&client_secret=" + githubSecret + "&code=" + body.getCode();
|
String url = "https://github.com/login/oauth/access_token?client_id=" + githubClientId + "&client_secret=" + githubSecret + "&code=" + body.getCode();
|
||||||
@ -65,7 +64,7 @@ public class OAuthServiceImpl implements OAuthService {
|
|||||||
JSONObject userInfo = HttpUtil.getObj("https://api.github.com/user", header, true);
|
JSONObject userInfo = HttpUtil.getObj("https://api.github.com/user", header, true);
|
||||||
other.setGithubId(userInfo.getLong("id"));
|
other.setGithubId(userInfo.getLong("id"));
|
||||||
if (other.getGithubId() == null) {
|
if (other.getGithubId() == null) {
|
||||||
log.error("github返回异常:{}", userInfo.toString());
|
log.error("github返回异常:{}", userInfo);
|
||||||
throw new CustomException("登陆异常,请稍后重试");
|
throw new CustomException("登陆异常,请稍后重试");
|
||||||
}
|
}
|
||||||
other.setEmail(userInfo.getString("email"));
|
other.setEmail(userInfo.getString("email"));
|
||||||
@ -78,7 +77,7 @@ public class OAuthServiceImpl implements OAuthService {
|
|||||||
} else {
|
} else {
|
||||||
throw new CustomException("不支持的登陆方式" + body.getType());
|
throw new CustomException("不支持的登陆方式" + body.getType());
|
||||||
}
|
}
|
||||||
User newest = dealOAuth(current, other);
|
User newest = dealOauth(current, other);
|
||||||
return JwtUtil.encode(Collections.singletonMap("userId", String.valueOf(newest.getUserId())), Constant.jwtSecret
|
return JwtUtil.encode(Collections.singletonMap("userId", String.valueOf(newest.getUserId())), Constant.jwtSecret
|
||||||
, body.isRememberMe() ? LONG_EXPIRE_TIME : SHORT_EXPIRE_TIME);
|
, body.isRememberMe() ? LONG_EXPIRE_TIME : SHORT_EXPIRE_TIME);
|
||||||
}
|
}
|
||||||
@ -92,7 +91,7 @@ public class OAuthServiceImpl implements OAuthService {
|
|||||||
* @author fanxb
|
* @author fanxb
|
||||||
* @date 2021/3/11
|
* @date 2021/3/11
|
||||||
**/
|
**/
|
||||||
private User dealOAuth(User current, User other) {
|
private User dealOauth(User current, User other) {
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
//判断用户名是否可用
|
//判断用户名是否可用
|
||||||
if (userDao.usernameExist(other.getUsername())) {
|
if (userDao.usernameExist(other.getUsername())) {
|
@ -5,6 +5,10 @@ import com.fanxb.bookmark.business.user.dao.UserDao;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/8/20 下午2:15
|
||||||
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class UserApiImpl implements UserApi {
|
public class UserApiImpl implements UserApi {
|
||||||
private final UserDao userDao;
|
private final UserDao userDao;
|
||||||
|
@ -39,6 +39,10 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class UserServiceImpl implements UserService {
|
public class UserServiceImpl implements UserService {
|
||||||
|
/**
|
||||||
|
* 登陆最大重试次数
|
||||||
|
*/
|
||||||
|
private static final int LOGIN_COUNT = 5;
|
||||||
|
|
||||||
private final UserDao userDao;
|
private final UserDao userDao;
|
||||||
private final StringRedisTemplate redisTemplate;
|
private final StringRedisTemplate redisTemplate;
|
||||||
@ -115,7 +119,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
public String login(LoginBody body) {
|
public String login(LoginBody body) {
|
||||||
String key = RedisConstant.getUserFailCountKey(body.getStr());
|
String key = RedisConstant.getUserFailCountKey(body.getStr());
|
||||||
String count = redisTemplate.opsForValue().get(key);
|
String count = redisTemplate.opsForValue().get(key);
|
||||||
if (count != null && Integer.parseInt(count) >= 5) {
|
if (count != null && Integer.parseInt(count) >= LOGIN_COUNT) {
|
||||||
redisTemplate.expire(key, 30, TimeUnit.MINUTES);
|
redisTemplate.expire(key, 30, TimeUnit.MINUTES);
|
||||||
throw new FormDataException("您已连续输错密码5次,请30分钟后再试,或联系管理员处理");
|
throw new FormDataException("您已连续输错密码5次,请30分钟后再试,或联系管理员处理");
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import lombok.Data;
|
|||||||
* @date 2021/3/10
|
* @date 2021/3/10
|
||||||
**/
|
**/
|
||||||
@Data
|
@Data
|
||||||
public class OAuthBody {
|
public class OauthBody {
|
||||||
public static final String GITHUB = "github";
|
public static final String GITHUB = "github";
|
||||||
/**
|
/**
|
||||||
* 类别
|
* 类别
|
Loading…
x
Reference in New Issue
Block a user