Merge branch 'dev'
This commit is contained in:
commit
86997b234f
@ -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";
|
||||||
/**
|
/**
|
||||||
* 类别
|
* 类别
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.fanxb.bookmark.common.controller;
|
||||||
|
|
||||||
|
import com.fanxb.bookmark.common.entity.Result;
|
||||||
|
import com.fanxb.bookmark.common.service.ConfigService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021-09-15-下午9:55
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/common/config")
|
||||||
|
public class ConfigController {
|
||||||
|
|
||||||
|
private final ConfigService configService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public ConfigController(ConfigService configService) {
|
||||||
|
this.configService = configService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取全局配置
|
||||||
|
*
|
||||||
|
* @return com.fanxb.bookmark.common.entity.Result
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/9/15 下午9:56
|
||||||
|
*/
|
||||||
|
@GetMapping("/global")
|
||||||
|
public Result getGlobalConfig() {
|
||||||
|
return Result.success(configService.getGlobalConfig());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.fanxb.bookmark.common.service;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全局配置相关
|
||||||
|
*
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021-09-15-下午9:56
|
||||||
|
*/
|
||||||
|
public interface ConfigService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取全局配置,用户无关,是否登陆都能获取
|
||||||
|
*
|
||||||
|
* @return java.util.Map<java.lang.String, java.lang.String>
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021/9/15 下午9:58
|
||||||
|
*/
|
||||||
|
Map<String, Object> getGlobalConfig();
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.fanxb.bookmark.common.service.impl;
|
||||||
|
|
||||||
|
import com.fanxb.bookmark.common.service.ConfigService;
|
||||||
|
import com.fanxb.bookmark.common.util.HttpUtil;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fanxb
|
||||||
|
* @date 2021-09-15-下午9:59
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ConfigServiceImpl implements ConfigService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getGlobalConfig() {
|
||||||
|
Map<String, Object> res = new HashMap<>(1);
|
||||||
|
res.put("proxyExist", HttpUtil.getProxyExist());
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.fanxb.bookmark.common.exception.CustomException;
|
import com.fanxb.bookmark.common.exception.CustomException;
|
||||||
|
import lombok.Getter;
|
||||||
import okhttp3.*;
|
import okhttp3.*;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
@ -27,15 +28,22 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class HttpUtil {
|
public class HttpUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否存在代理环境
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
private static Boolean proxyExist = false;
|
||||||
|
|
||||||
@Value("${proxy.ip}")
|
@Value("${proxy.ip}")
|
||||||
private String proxyIp;
|
private String proxyIp;
|
||||||
@Value("${proxy.port}")
|
@Value("${proxy.port}")
|
||||||
private int proxyPort;
|
private String proxyPort;
|
||||||
|
|
||||||
private static final int IP_LENGTH = 15;
|
private static final int IP_LENGTH = 15;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 使用代理环境
|
* 使用代理环境(如不存在代理配置,那么此客户端也是非代理)
|
||||||
*/
|
*/
|
||||||
private static OkHttpClient PROXY_CLIENT;
|
private static OkHttpClient PROXY_CLIENT;
|
||||||
/**
|
/**
|
||||||
@ -49,8 +57,9 @@ public class HttpUtil {
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||||
if (StrUtil.isNotBlank(proxyIp)) {
|
if (StrUtil.isNotBlank(proxyIp) && StrUtil.isNotBlank(proxyPort)) {
|
||||||
builder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyIp, proxyPort)));
|
builder.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyIp, Integer.parseInt(proxyPort))));
|
||||||
|
proxyExist = true;
|
||||||
}
|
}
|
||||||
PROXY_CLIENT = builder.connectTimeout(10, TimeUnit.SECONDS)
|
PROXY_CLIENT = builder.connectTimeout(10, TimeUnit.SECONDS)
|
||||||
.readTimeout(60, TimeUnit.SECONDS)
|
.readTimeout(60, TimeUnit.SECONDS)
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
INSERT INTO `bookmark`.`url`(`method`, `url`, `type`)
|
||||||
|
VALUES ('GET', '/common/config/global', 0);
|
1
bookmark_front/.gitignore
vendored
1
bookmark_front/.gitignore
vendored
@ -1,6 +1,7 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
node_modules
|
node_modules
|
||||||
/dist
|
/dist
|
||||||
|
yarn.lock
|
||||||
|
|
||||||
# local env files
|
# local env files
|
||||||
.env.local
|
.env.local
|
||||||
|
@ -7,6 +7,10 @@
|
|||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: "App",
|
name: "App",
|
||||||
|
async created(){
|
||||||
|
//全局初始化
|
||||||
|
await this.$store.dispatch("globalConfig/refreshServerConfig");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import localforage from "localforage";
|
|||||||
import HttpUtil from "../../util/HttpUtil";
|
import HttpUtil from "../../util/HttpUtil";
|
||||||
const USER_INFO = "userInfo";
|
const USER_INFO = "userInfo";
|
||||||
const TOKEN = "token";
|
const TOKEN = "token";
|
||||||
|
const SERVER_CONFIG = "serverConfig";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 存储全局配置
|
* 存储全局配置
|
||||||
@ -22,13 +23,17 @@ const state = {
|
|||||||
/**
|
/**
|
||||||
* 是否移动端
|
* 是否移动端
|
||||||
*/
|
*/
|
||||||
isPhone: false
|
isPhone: false,
|
||||||
|
/**
|
||||||
|
* 服务端全局配置
|
||||||
|
*/
|
||||||
|
[SERVER_CONFIG]: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getters = {};
|
const getters = {};
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
//初始化数据
|
//登陆后的,初始化数据
|
||||||
async init(context) {
|
async init(context) {
|
||||||
if (context.state.isInit) {
|
if (context.state.isInit) {
|
||||||
return;
|
return;
|
||||||
@ -64,6 +69,12 @@ const actions = {
|
|||||||
context.commit(USER_INFO, null);
|
context.commit(USER_INFO, null);
|
||||||
context.commit(TOKEN, null);
|
context.commit(TOKEN, null);
|
||||||
context.commit("isInit", false);
|
context.commit("isInit", false);
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 从服务器读取全局配置
|
||||||
|
*/
|
||||||
|
async refreshServerConfig({ commit }) {
|
||||||
|
commit(SERVER_CONFIG, await HttpUtil.get("/common/config/global"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -79,6 +90,9 @@ const mutations = {
|
|||||||
},
|
},
|
||||||
isPhone(state, status) {
|
isPhone(state, status) {
|
||||||
state.isPhone = status;
|
state.isPhone = status;
|
||||||
|
},
|
||||||
|
[SERVER_CONFIG](state, serverConfig) {
|
||||||
|
state[SERVER_CONFIG] = serverConfig;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ const getters = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const actions = {
|
const actions = {
|
||||||
//从缓存初始化数据
|
//登陆后的,从缓存初始化数据
|
||||||
async init(context) {
|
async init(context) {
|
||||||
if (context.state.isInit || context.state.isIniting) {
|
if (context.state.isInit || context.state.isIniting) {
|
||||||
return;
|
return;
|
||||||
|
@ -22,6 +22,7 @@ async function request(url, method, params, body, isForm, redirect) {
|
|||||||
"jwt-token": vuex.state.globalConfig.token
|
"jwt-token": vuex.state.globalConfig.token
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
//如果是表单类型的请求,添加请求头
|
||||||
if (isForm) {
|
if (isForm) {
|
||||||
options.headers["Content-Type"] = "multipart/form-data";
|
options.headers["Content-Type"] = "multipart/form-data";
|
||||||
}
|
}
|
||||||
@ -40,12 +41,12 @@ async function request(url, method, params, body, isForm, redirect) {
|
|||||||
if (code === 1) {
|
if (code === 1) {
|
||||||
return data;
|
return data;
|
||||||
} else if (code === -1 && redirect) {
|
} else if (code === -1 && redirect) {
|
||||||
// 跳转到登陆页
|
//未登陆,根据redirect参数判断是否需要跳转到登陆页
|
||||||
window.vueInstance.$message.error("您尚未登陆,请先登陆");
|
window.vueInstance.$message.error("您尚未登陆,请先登陆");
|
||||||
router.replace(`/public/login?redirect=${encodeURIComponent(router.currentRoute.fullPath)}`);
|
router.replace(`/public/login?redirect=${encodeURIComponent(router.currentRoute.fullPath)}`);
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
} else if (code === 0) {
|
} else if (code === 0) {
|
||||||
//通用异常,使用
|
//通用异常,使用error提示
|
||||||
window.vueInstance.$notification.error({
|
window.vueInstance.$notification.error({
|
||||||
message: "异常",
|
message: "异常",
|
||||||
description: message
|
description: message
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="thirdPart">
|
<div class="thirdPart">
|
||||||
<span>第三方登陆</span>
|
<span>第三方登陆</span>
|
||||||
<a-tooltip title="github登陆" class="oneIcon" placement="bottom">
|
<a-tooltip v-if="serverConfig.proxyExist" title="github登陆" class="oneIcon" placement="bottom">
|
||||||
<a-icon type="github" @click="toGithub" style="font-size:1.4em" />
|
<a-icon type="github" @click="toGithub" style="font-size:1.4em" />
|
||||||
</a-tooltip>
|
</a-tooltip>
|
||||||
</div>
|
</div>
|
||||||
@ -37,13 +37,16 @@
|
|||||||
<script>
|
<script>
|
||||||
import Header from "@/components/public/Switch.vue";
|
import Header from "@/components/public/Switch.vue";
|
||||||
import httpUtil from "../../../util/HttpUtil.js";
|
import httpUtil from "../../../util/HttpUtil.js";
|
||||||
import { mapMutations } from "vuex";
|
import { mapMutations ,mapState} from "vuex";
|
||||||
import HttpUtil from "../../../util/HttpUtil.js";
|
import HttpUtil from "../../../util/HttpUtil.js";
|
||||||
export default {
|
export default {
|
||||||
name: "Login",
|
name: "Login",
|
||||||
components: {
|
components: {
|
||||||
Header,
|
Header,
|
||||||
},
|
},
|
||||||
|
computed:{
|
||||||
|
...mapState("globalConfig", ["serverConfig"])
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
form: {
|
form: {
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user