diff --git a/src/main/java/io/qyi/e5/config/security/SecurityAuthenticationHandler.java b/src/main/java/io/qyi/e5/config/security/SecurityAuthenticationHandler.java index 9ec993d..48cd992 100644 --- a/src/main/java/io/qyi/e5/config/security/SecurityAuthenticationHandler.java +++ b/src/main/java/io/qyi/e5/config/security/SecurityAuthenticationHandler.java @@ -34,6 +34,7 @@ public class SecurityAuthenticationHandler implements AuthenticationSuccessHandl PrintWriter writer = httpServletResponse.getWriter(); Map token = new HashMap<>(); token.put("token", at.getToken()); + token.put("username", at.getName()); writer.write(gson.toJson(ResultUtil.success(token)) ); writer.flush(); } diff --git a/src/main/java/io/qyi/e5/controller/auth2/Auth.java b/src/main/java/io/qyi/e5/controller/auth2/Auth.java index 953934e..0652de1 100644 --- a/src/main/java/io/qyi/e5/controller/auth2/Auth.java +++ b/src/main/java/io/qyi/e5/controller/auth2/Auth.java @@ -1,9 +1,11 @@ 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.service.IGithubService; import io.qyi.e5.user.mapper.UserMapper; import io.qyi.e5.util.EncryptUtil; +import io.qyi.e5.util.ResultUtil; import io.qyi.e5.util.redis.RedisUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -36,11 +38,10 @@ public class Auth { @RequestMapping("/getGithubUrl") - public void getGithubUrl(HttpServletResponse response) { + public Result getGithubUrl() { String state = EncryptUtil.getInstance().SHA1Hex(UUID.randomUUID().toString()); redisUtil.set(states + state, true, 600); - response.setStatus(302); - response.setHeader("Location", "https://github.com/login/oauth/authorize?client_id=" + client_id + "&redirect_uri=https://e5.qyi.io/auth2/receive&state=" + state); + return ResultUtil.success("https://github.com/login/oauth/authorize?client_id=" + client_id + "&redirect_uri=https://e5.qyi.io/auth2/receive&state=" + state); } /* @RequestMapping("/receive") diff --git a/src/main/java/io/qyi/e5/outlook/controller/AuthController.java b/src/main/java/io/qyi/e5/outlook/controller/AuthController.java index 6bd2f39..53463bc 100644 --- a/src/main/java/io/qyi/e5/outlook/controller/AuthController.java +++ b/src/main/java/io/qyi/e5/outlook/controller/AuthController.java @@ -60,7 +60,7 @@ public class AuthController { boolean authorization_code = outlookService.getTokenAndSave(code, outlook.getClientId(), outlook.getClientSecret(), "https://e5.qyi.io/outlook/auth2/receive" , "authorization_code"); if (!authorization_code) { - return ResultUtil.error(-3, "未知错误,请联系管理员~"); + return ResultUtil.error(-3, "clientId 或 clientSecret 填写错误!授权失败!"); } return ResultUtil.success(); } diff --git a/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java b/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java index 6a4ecc3..5c69b2b 100644 --- a/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java +++ b/src/main/java/io/qyi/e5/outlook/controller/OutlookController.java @@ -48,8 +48,8 @@ public class OutlookController { int cron_time_random_start; int cron_time_random_end; try { - cron_time_random_start = Integer.valueOf(split[0]); - cron_time_random_end = Integer.valueOf(split[1]); + cron_time_random_start = Integer.valueOf(split[0]); + cron_time_random_end = Integer.valueOf(split[1]); } catch (NumberFormatException e) { e.printStackTrace(); return ResultUtil.error(ResultEnum.INVALID_format); @@ -60,17 +60,17 @@ public class OutlookController { } return ResultUtil.error(ResultEnum.UNKNOWN_ERROR); } + @GetMapping("/getOutlookInfo") - public Result getOutlookInfo(){ + public Result getOutlookInfo() { UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication(); int github_id = authentication.getGithub_id(); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("github_id", github_id); Outlook one = outlookService.getOne(queryWrapper); OutlookVo vo = new OutlookVo(); - System.out.println(one); if (one != null) { - BeanUtils.copyProperties(one,vo); + BeanUtils.copyProperties(one, vo); } return ResultUtil.success(vo); } diff --git a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java index 786aedb..12101e0 100644 --- a/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java +++ b/src/main/java/io/qyi/e5/outlook/service/impl/OutlookServiceImpl.java @@ -164,12 +164,27 @@ public class OutlookServiceImpl extends ServiceImpl 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 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 { Map 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?$select=sender,subject", head, null); - logger.info("请求邮件列表返回数据:" + s); + logger.debug("请求邮件列表返回数据:" + s); return s; }