mirror of
https://github.com/luoye663/e5.git
synced 2024-12-26 03:38:53 +00:00
1、登录返回用户名
2、getGithubUrl 返回值修改为json 3、修改 未知错误,请联系管理员 为具体的错误信息
This commit is contained in:
parent
31efe5feff
commit
6aa704f5c0
@ -34,6 +34,7 @@ public class SecurityAuthenticationHandler implements AuthenticationSuccessHandl
|
|||||||
PrintWriter writer = httpServletResponse.getWriter();
|
PrintWriter writer = httpServletResponse.getWriter();
|
||||||
Map<String, String> token = new HashMap<>();
|
Map<String, String> token = new HashMap<>();
|
||||||
token.put("token", at.getToken());
|
token.put("token", at.getToken());
|
||||||
|
token.put("username", at.getName());
|
||||||
writer.write(gson.toJson(ResultUtil.success(token)) );
|
writer.write(gson.toJson(ResultUtil.success(token)) );
|
||||||
writer.flush();
|
writer.flush();
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package io.qyi.e5.controller.auth2;
|
package io.qyi.e5.controller.auth2;
|
||||||
|
|
||||||
|
import io.qyi.e5.bean.result.Result;
|
||||||
import io.qyi.e5.github.mapper.GithubMapper;
|
import io.qyi.e5.github.mapper.GithubMapper;
|
||||||
import io.qyi.e5.github.service.IGithubService;
|
import io.qyi.e5.github.service.IGithubService;
|
||||||
import io.qyi.e5.user.mapper.UserMapper;
|
import io.qyi.e5.user.mapper.UserMapper;
|
||||||
import io.qyi.e5.util.EncryptUtil;
|
import io.qyi.e5.util.EncryptUtil;
|
||||||
|
import io.qyi.e5.util.ResultUtil;
|
||||||
import io.qyi.e5.util.redis.RedisUtil;
|
import io.qyi.e5.util.redis.RedisUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
@ -36,11 +38,10 @@ public class Auth {
|
|||||||
|
|
||||||
|
|
||||||
@RequestMapping("/getGithubUrl")
|
@RequestMapping("/getGithubUrl")
|
||||||
public void getGithubUrl(HttpServletResponse response) {
|
public Result getGithubUrl() {
|
||||||
String state = EncryptUtil.getInstance().SHA1Hex(UUID.randomUUID().toString());
|
String state = EncryptUtil.getInstance().SHA1Hex(UUID.randomUUID().toString());
|
||||||
redisUtil.set(states + state, true, 600);
|
redisUtil.set(states + state, true, 600);
|
||||||
response.setStatus(302);
|
return ResultUtil.success("https://github.com/login/oauth/authorize?client_id=" + client_id + "&redirect_uri=https://e5.qyi.io/auth2/receive&state=" + state);
|
||||||
response.setHeader("Location", "https://github.com/login/oauth/authorize?client_id=" + client_id + "&redirect_uri=https://e5.qyi.io/auth2/receive&state=" + state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @RequestMapping("/receive")
|
/* @RequestMapping("/receive")
|
||||||
|
@ -60,7 +60,7 @@ public class AuthController {
|
|||||||
boolean authorization_code = outlookService.getTokenAndSave(code, outlook.getClientId(), outlook.getClientSecret(), "https://e5.qyi.io/outlook/auth2/receive"
|
boolean authorization_code = outlookService.getTokenAndSave(code, outlook.getClientId(), outlook.getClientSecret(), "https://e5.qyi.io/outlook/auth2/receive"
|
||||||
, "authorization_code");
|
, "authorization_code");
|
||||||
if (!authorization_code) {
|
if (!authorization_code) {
|
||||||
return ResultUtil.error(-3, "未知错误,请联系管理员~");
|
return ResultUtil.error(-3, "clientId 或 clientSecret 填写错误!授权失败!");
|
||||||
}
|
}
|
||||||
return ResultUtil.success();
|
return ResultUtil.success();
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,8 @@ public class OutlookController {
|
|||||||
int cron_time_random_start;
|
int cron_time_random_start;
|
||||||
int cron_time_random_end;
|
int cron_time_random_end;
|
||||||
try {
|
try {
|
||||||
cron_time_random_start = Integer.valueOf(split[0]);
|
cron_time_random_start = Integer.valueOf(split[0]);
|
||||||
cron_time_random_end = Integer.valueOf(split[1]);
|
cron_time_random_end = Integer.valueOf(split[1]);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return ResultUtil.error(ResultEnum.INVALID_format);
|
return ResultUtil.error(ResultEnum.INVALID_format);
|
||||||
@ -60,17 +60,17 @@ public class OutlookController {
|
|||||||
}
|
}
|
||||||
return ResultUtil.error(ResultEnum.UNKNOWN_ERROR);
|
return ResultUtil.error(ResultEnum.UNKNOWN_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/getOutlookInfo")
|
@GetMapping("/getOutlookInfo")
|
||||||
public Result getOutlookInfo(){
|
public Result getOutlookInfo() {
|
||||||
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||||
int github_id = authentication.getGithub_id();
|
int github_id = authentication.getGithub_id();
|
||||||
QueryWrapper<Outlook> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<Outlook> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("github_id", github_id);
|
queryWrapper.eq("github_id", github_id);
|
||||||
Outlook one = outlookService.getOne(queryWrapper);
|
Outlook one = outlookService.getOne(queryWrapper);
|
||||||
OutlookVo vo = new OutlookVo();
|
OutlookVo vo = new OutlookVo();
|
||||||
System.out.println(one);
|
|
||||||
if (one != null) {
|
if (one != null) {
|
||||||
BeanUtils.copyProperties(one,vo);
|
BeanUtils.copyProperties(one, vo);
|
||||||
}
|
}
|
||||||
return ResultUtil.success(vo);
|
return ResultUtil.success(vo);
|
||||||
}
|
}
|
||||||
|
@ -164,12 +164,27 @@ public class OutlookServiceImpl extends ServiceImpl<OutlookMapper, Outlook> impl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 读取邮件内容
|
||||||
|
* @Description:
|
||||||
|
* @param: count 读取数量,0 则读取当前页所有
|
||||||
|
* @return: void
|
||||||
|
* @Author: 落叶随风
|
||||||
|
* @Date: 2020/4/15
|
||||||
|
*/
|
||||||
|
public void getMailBody(int count,String MailBody ,String access_token) throws Exception {
|
||||||
|
Map<String, Object> head = new HashMap<>();
|
||||||
|
head.put("Content-Type", "application/json");
|
||||||
|
head.put("Authorization", access_token);
|
||||||
|
String s = OkHttpRequestUtils.doGet("https://graph.microsoft.com/v1.0/me/messages/", head, null);
|
||||||
|
}
|
||||||
|
|
||||||
public String MailList(String access_token) throws Exception {
|
public String MailList(String access_token) throws Exception {
|
||||||
Map<String, Object> head = new HashMap<>();
|
Map<String, Object> head = new HashMap<>();
|
||||||
head.put("Content-Type", "application/json");
|
head.put("Content-Type", "application/json");
|
||||||
head.put("Authorization", access_token);
|
head.put("Authorization", access_token);
|
||||||
String s = OkHttpRequestUtils.doGet("https://graph.microsoft.com/v1.0/me/messages?$select=sender,subject", head, null);
|
String s = OkHttpRequestUtils.doGet("https://graph.microsoft.com/v1.0/me/messages?$select=sender,subject", head, null);
|
||||||
logger.info("请求邮件列表返回数据:" + s);
|
logger.debug("请求邮件列表返回数据:" + s);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user