mirror of
https://github.com/luoye663/e5.git
synced 2024-12-26 03:38:53 +00:00
br
This commit is contained in:
parent
9bcc0d83f7
commit
28e60a054b
@ -1,16 +1,11 @@
|
|||||||
package io.qyi.e5.controller.web;
|
package io.qyi.e5.controller.web;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import io.qyi.e5.bean.result.Result;
|
||||||
import io.qyi.e5.config.security.UsernamePasswordAuthenticationToken;
|
|
||||||
import io.qyi.e5.outlook.entity.Outlook;
|
|
||||||
import io.qyi.e5.outlook.service.IOutlookService;
|
import io.qyi.e5.outlook.service.IOutlookService;
|
||||||
|
import io.qyi.e5.util.ResultUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.ui.Model;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @program: e5
|
* @program: e5
|
||||||
@ -18,47 +13,15 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
* @author: 落叶随风
|
* @author: 落叶随风
|
||||||
* @create: 2020-02-27 16:03
|
* @create: 2020-02-27 16:03
|
||||||
**/
|
**/
|
||||||
@Controller
|
@RestController
|
||||||
public class WebController {
|
public class WebController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
IOutlookService outlookService;
|
IOutlookService outlookService;
|
||||||
|
|
||||||
@RequestMapping("/")
|
@RequestMapping("/")
|
||||||
public void index(HttpServletResponse httpServletResponse) {
|
public Result index() {
|
||||||
httpServletResponse.setStatus(302);
|
return ResultUtil.error(-1, "This is api server!");
|
||||||
httpServletResponse.setHeader("Location", "/user/home");
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping("/user/login")
|
|
||||||
public String login(Model model) {
|
|
||||||
model.addAttribute("welcome", "hello fishpro");
|
|
||||||
return "user/login";
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequestMapping("/user/home")
|
|
||||||
public String home(Model model) {
|
|
||||||
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
|
||||||
int github_id = authentication.getGithub_id();
|
|
||||||
QueryWrapper<Outlook> queryWrapper = new QueryWrapper<>();
|
|
||||||
queryWrapper.eq("github_id", github_id);
|
|
||||||
Outlook one = outlookService.getOne(queryWrapper);
|
|
||||||
if (one != null) {
|
|
||||||
model.addAttribute("client_id", one.getClientId());
|
|
||||||
model.addAttribute("client_secret", one.getClientSecret());
|
|
||||||
model.addAttribute("cron_time", one.getCronTime().toString());
|
|
||||||
model.addAttribute("cron_time_random_start", one.getCronTimeRandomStart());
|
|
||||||
model.addAttribute("cron_time_random_end", one.getCronTimeRandomEnd());
|
|
||||||
} else {
|
|
||||||
model.addAttribute("client_id", "");
|
|
||||||
model.addAttribute("client_secret", "");
|
|
||||||
model.addAttribute("cron_time", 0);
|
|
||||||
model.addAttribute("cron_time_random_start", 0);
|
|
||||||
model.addAttribute("cron_time_random_end", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
model.addAttribute("welcome", "hello fishpro");
|
|
||||||
return "user/home";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class AuthController {
|
|||||||
@RequestMapping("/receive")
|
@RequestMapping("/receive")
|
||||||
public Result Receive(String code, String state, String session_state) throws Exception {
|
public Result Receive(String code, String state, String session_state) throws Exception {
|
||||||
if (!redisUtil.hasKey(states + state)) {
|
if (!redisUtil.hasKey(states + state)) {
|
||||||
return ResultUtil.error(-1, "state已过期,重新点击授权!");
|
return ResultUtil.error(-1, "state已过期,请到用户中心重新授权!");
|
||||||
}
|
}
|
||||||
/*这里不应该查询,在进行授权时因该把基础数据丢到redis*/
|
/*这里不应该查询,在进行授权时因该把基础数据丢到redis*/
|
||||||
QueryWrapper<Outlook> outlookQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<Outlook> outlookQueryWrapper = new QueryWrapper<>();
|
||||||
|
@ -54,6 +54,18 @@ public class OutlookController {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return ResultUtil.error(ResultEnum.INVALID_format);
|
return ResultUtil.error(ResultEnum.INVALID_format);
|
||||||
}
|
}
|
||||||
|
if (cron_time_random_start > cron_time_random_end) {
|
||||||
|
return ResultUtil.error(-1, "亲,你的开始时间大于结束时间吗?");
|
||||||
|
}
|
||||||
|
if (cron_time_random_start < 1 || cron_time_random_end < 1) {
|
||||||
|
return ResultUtil.error(-1, "时间为负???");
|
||||||
|
}
|
||||||
|
if (cron_time_random_start < 60) {
|
||||||
|
return ResultUtil.error(-1, "最小间隔时间为 60 秒");
|
||||||
|
}
|
||||||
|
if (cron_time_random_end > 1296000) {
|
||||||
|
return ResultUtil.error(-1, "最大间隔时间为 6 小时");
|
||||||
|
}
|
||||||
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
UsernamePasswordAuthenticationToken authentication = (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
|
||||||
if (outlookService.saveRandomTime(authentication.getGithub_id(), cronTime, cron_time_random_start, cron_time_random_end)) {
|
if (outlookService.saveRandomTime(authentication.getGithub_id(), cronTime, cron_time_random_start, cron_time_random_end)) {
|
||||||
return ResultUtil.success();
|
return ResultUtil.success();
|
||||||
|
Loading…
Reference in New Issue
Block a user