|
@@ -1,7 +1,10 @@
|
|
package com.neko.service.impl;
|
|
package com.neko.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.neko.config.GiteeProperties;
|
|
|
|
+import com.neko.config.ThirdlyLoginTypeConstant;
|
|
import com.neko.domain.dto.userDto.PhoneLoginDto;
|
|
import com.neko.domain.dto.userDto.PhoneLoginDto;
|
|
import com.neko.domain.dto.userDto.YanDto;
|
|
import com.neko.domain.dto.userDto.YanDto;
|
|
import com.neko.domain.pojo.User;
|
|
import com.neko.domain.pojo.User;
|
|
@@ -32,15 +35,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User>
|
|
private UserMapper userMapper;
|
|
private UserMapper userMapper;
|
|
@Autowired
|
|
@Autowired
|
|
private RedisTemplate redisTemplate;
|
|
private RedisTemplate redisTemplate;
|
|
|
|
+ @Autowired
|
|
|
|
+ GiteeProperties giteeProperties;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public ResultVo phoenLogin(PhoneLoginDto dto) {
|
|
public ResultVo phoenLogin(PhoneLoginDto dto) {
|
|
- if(dto.getPassword()==null){
|
|
|
|
|
|
+ if(StringUtils.isEmpty(dto.getPhone())){
|
|
return ResultVo.error(ApiServiceExceptionEnum.USER_NOT_NULL);
|
|
return ResultVo.error(ApiServiceExceptionEnum.USER_NOT_NULL);
|
|
}
|
|
}
|
|
if(StringUtils.isEmpty(dto.getPassword())){
|
|
if(StringUtils.isEmpty(dto.getPassword())){
|
|
log.info("验证码登录");
|
|
log.info("验证码登录");
|
|
- if(dto.getSmsCode()==null){
|
|
|
|
|
|
+ if(StringUtils.isEmpty(dto.getSmsCode())){
|
|
//判断验证码是否为空
|
|
//判断验证码是否为空
|
|
return ResultVo.error(ApiServiceExceptionEnum.YAN_NOT_NULL);
|
|
return ResultVo.error(ApiServiceExceptionEnum.YAN_NOT_NULL);
|
|
}
|
|
}
|
|
@@ -148,6 +153,44 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User>
|
|
}
|
|
}
|
|
return ResultVo.success(sixDigitNumber);
|
|
return ResultVo.success(sixDigitNumber);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String choiceLoginType(String loginType) {
|
|
|
|
+ String url = "";
|
|
|
|
+ if (ThirdlyLoginTypeConstant.GITEE.equals(loginType)) {
|
|
|
|
+ url = ThirdlyLoginTypeConstant.GITEE_URL
|
|
|
|
+ .replace("{client_id}", giteeProperties.getClientId())
|
|
|
|
+ .replace("{redirect_uri}", giteeProperties.getRedirectUri());
|
|
|
|
+ }
|
|
|
|
+ return url;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getOauthToken(String loginType, String code) {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
+ String result = "";
|
|
|
|
+ if (ThirdlyLoginTypeConstant.GITEE.equals(loginType)) {
|
|
|
|
+ String url = ThirdlyLoginTypeConstant.GITEE_OAUTH_TOKEN_URL;
|
|
|
|
+ map.put("grant_type", "authorization_code");
|
|
|
|
+ map.put("code", code);
|
|
|
|
+ map.put("client_id", giteeProperties.getClientId());
|
|
|
|
+ map.put("client_secret", giteeProperties.getClientSecret());
|
|
|
|
+ map.put("redirect_uri", giteeProperties.getRedirectUri());
|
|
|
|
+ //发送get请求并接收响应数据
|
|
|
|
+ result = HttpUtil.createPost(url).form(map).execute().body();
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getUserInfo(String loginType, String accessToken) {
|
|
|
|
+ String userInfo = "";
|
|
|
|
+ if (ThirdlyLoginTypeConstant.GITEE.equals(loginType)) {
|
|
|
|
+ String userInfoUrl = "https://gitee.com/api/v5/user?access_token=" + accessToken;
|
|
|
|
+ userInfo = HttpUtil.createGet(userInfoUrl).execute().body();
|
|
|
|
+ }
|
|
|
|
+ return userInfo;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|