¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.controller.all; |
| | | |
| | | import com.lf.server.annotation.SysLog; |
| | | import com.lf.server.config.PropertiesConfig; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.sys.LoginEntity; |
| | | import com.lf.server.entity.sys.TokenEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.*; |
| | | import com.lf.server.service.sys.LoginService; |
| | | import com.lf.server.service.sys.TokenService; |
| | | import com.lf.server.service.sys.UserService; |
| | | import com.lf.server.service.all.SignService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.servlet.ModelAndView; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | /** |
| | | * ç¾åæ§å¶å¨ |
| | | * @author WWW |
| | | * @date 2022-09-21 |
| | | */ |
| | | @Api(tags = "è¿ç»´ç®¡ç\\ç¾å管ç") |
| | | @RestController |
| | | @RequestMapping("/sign") |
| | | public class SignController extends BaseController { |
| | | @Autowired |
| | | UserService userService; |
| | | |
| | | @Autowired |
| | | LoginService loginService; |
| | | |
| | | @Autowired |
| | | TokenService tokenService; |
| | | |
| | | @Autowired |
| | | SignService signService; |
| | | |
| | | @Autowired |
| | | PropertiesConfig propertiesConfig; |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "跳转é¦é¡µ") |
| | | @GetMapping({"/", "/toIndex"}) |
| | | public ModelAndView toIndex(ModelAndView mv, HttpServletRequest req) { |
| | | mv.setViewName("index"); |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | mv.addObject("msg", "Hello " + ue.getUname() + " !"); |
| | | } |
| | | |
| | | return mv; |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "跳转ç»å½é¡µ") |
| | | @GetMapping("/toLogin") |
| | | public ModelAndView toLogin(ModelAndView mv) { |
| | | mv.setViewName("login"); |
| | | |
| | | return mv; |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æ°æ®åºçæ§") |
| | | @GetMapping(value = "/toDruid") |
| | | public ModelAndView toDruid(HttpServletRequest req, HttpServletResponse res) { |
| | | ModelAndView mv = new ModelAndView(); |
| | | mv.setViewName("druid"); |
| | | |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | String sessionId = WebHelper.getCookieByKey(StaticData.DRUID_COOKIE_KEY, req); |
| | | if (StringHelper.isNull(sessionId)) { |
| | | signService.loginDruid(req, res); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | |
| | | return mv; |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "èµæºçæ§") |
| | | @GetMapping(value = "/toMonitor") |
| | | public ModelAndView toMonitor(ModelAndView mv, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | mv.setViewName("redirect:/toLogin"); |
| | | |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | mv.setViewName("monitor"); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | |
| | | return mv; |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "ç»å½") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "user", value = "ç¨æ¶å", dataType = "UsersEntity", paramType = "body", example = "") |
| | | }) |
| | | @PostMapping(value = "/login", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<TokenEntity> login(@RequestBody UserEntity user, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | String str = userService.validateLoginPwd(user); |
| | | if (str != null) { |
| | | return fail(str, null); |
| | | } |
| | | |
| | | UserEntity ue = userService.selectByUid(user.getUid()); |
| | | if (ue == null) { |
| | | return fail("ç¨æ·åä¸åå¨", null); |
| | | } |
| | | |
| | | if (!Md5Helper.validatePassword(user.getPwd(), ue.getPwd())) { |
| | | tokenService.setPwdErrCache(ue); |
| | | return fail("å¯ç 䏿£ç¡®", null); |
| | | } |
| | | |
| | | LoginEntity le = loginService.getNewLogin(ue.getId(), 1, 1, 1, req); |
| | | Integer rows = loginService.insertLogin(le); |
| | | if (rows == 0) { |
| | | return fail("å建ç»å½æ¥å¿å¤±è´¥", null); |
| | | } |
| | | |
| | | TokenEntity te = tokenService.getNewToken(ue, req); |
| | | rows = tokenService.insertToken(te); |
| | | if (rows == 0) { |
| | | return fail("å建令ç失败", null); |
| | | } |
| | | |
| | | tokenService.saveToken(ue, te, req, res); |
| | | |
| | | return success(te); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "ç»åº") |
| | | @GetMapping(value = "/logout") |
| | | public ResponseMsg<Boolean> logout(HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | String token = WebHelper.getToken(req); |
| | | if (StringHelper.isEmpty(token)) { |
| | | return fail("æ²¡ææ£æµå°ä»¤ç", false); |
| | | } |
| | | |
| | | Boolean flag = tokenService.logout(token, req, res); |
| | | |
| | | return success(flag ? "ç»åºæå" : "ç»åºå¤±è´¥", flag); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), false); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "æ£æ¥æ¯/å¦ç»å½") |
| | | @GetMapping("/check") |
| | | public ResponseMsg<Boolean> check(HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | Boolean flag = tokenService.isLogin(req, res); |
| | | if (flag) { |
| | | // åæ¥å¿ |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | LoginEntity le = loginService.getNewLogin(ue.getId(), 1, 2, 1, req); |
| | | Integer rows = loginService.insertLogin(le); |
| | | } |
| | | |
| | | return success(flag ? "ç¨æ·å·²ç»å½" : "ç¨æ·æªç»å½", flag); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), false); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "è·åå½åç¨æ·") |
| | | @GetMapping("/getCurrentUser") |
| | | public ResponseMsg<UserEntity> getCurrentUser(HttpServletRequest req) { |
| | | try { |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue == null) { |
| | | return fail("æ²¡ææ¾å°", null); |
| | | } |
| | | |
| | | return success(ue); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | |
| | | @SysLog() |
| | | @ApiOperation(value = "è·åRSAå å¯å
¬é¥") |
| | | @GetMapping("/getPublicKey") |
| | | public ResponseMsg<String> getPublicKey() { |
| | | try { |
| | | String key = RsaHelper.getPublicKey(); |
| | | |
| | | return success(key); |
| | | } catch (Exception ex) { |
| | | return fail(ex.getMessage(), null); |
| | | } |
| | | } |
| | | } |