| | |
| | | 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.UsersEntity; |
| | | 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.UsersService; |
| | | import com.lf.server.service.sys.UserService; |
| | | import com.lf.server.service.all.SignService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | |
| | | @RequestMapping("/sign") |
| | | public class SignController extends BaseController { |
| | | @Autowired |
| | | UsersService userService; |
| | | UserService userService; |
| | | |
| | | @Autowired |
| | | LoginService loginService; |
| | |
| | | public ModelAndView toIndex(ModelAndView mv, HttpServletRequest req) { |
| | | mv.setViewName("index"); |
| | | |
| | | UsersEntity ue = tokenService.getCurrentUser(req); |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | mv.addObject("msg", "Hello " + ue.getUname() + " !"); |
| | | } |
| | |
| | | mv.setViewName("druid"); |
| | | |
| | | try { |
| | | UsersEntity ue = tokenService.getCurrentUser(req); |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | String sessionId = WebHelper.getCookieByKey(StaticData.DRUID_COOKIE_KEY, req); |
| | | if (StringHelper.isNull(sessionId)) { |
| | |
| | | try { |
| | | mv.setViewName("redirect:/toLogin"); |
| | | |
| | | UsersEntity ue = tokenService.getCurrentUser(req); |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue != null) { |
| | | mv.setViewName("monitor"); |
| | | } |
| | |
| | | @ApiImplicitParam(name = "user", value = "用戶名", dataType = "UsersEntity", paramType = "body", example = "") |
| | | }) |
| | | @PostMapping(value = "/login", produces = "application/json; charset=UTF-8") |
| | | public ResponseMsg<TokenEntity> login(@RequestBody UsersEntity user, HttpServletRequest req, HttpServletResponse res) { |
| | | public ResponseMsg<TokenEntity> login(@RequestBody UserEntity user, HttpServletRequest req, HttpServletResponse res) { |
| | | try { |
| | | if (user == null) { |
| | | return fail("请输入用户名和密码!", null); |
| | |
| | | String uid = RsaHelper.decrypt(user.getUid()); |
| | | String pwd = RsaHelper.decrypt(user.getPwd()); |
| | | |
| | | UsersEntity ue = userService.selectByUid(uid); |
| | | UserEntity ue = userService.selectByUid(uid); |
| | | if (ue == null) { |
| | | return fail("用户名不存在!", null); |
| | | } |
| | |
| | | Boolean flag = tokenService.isLogin(req, res); |
| | | if (flag) { |
| | | // 写日志 |
| | | UsersEntity ue = tokenService.getCurrentUser(req); |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | LoginEntity le = loginService.getNewLogin(ue.getId(), 2, req); |
| | | Integer rows = loginService.insertLogin(le); |
| | | } |
| | |
| | | @SysLog() |
| | | @ApiOperation(value = "获取当前用户") |
| | | @GetMapping("/getCurrentUser") |
| | | public ResponseMsg<UsersEntity> getCurrentUser(HttpServletRequest req) { |
| | | public ResponseMsg<UserEntity> getCurrentUser(HttpServletRequest req) { |
| | | try { |
| | | UsersEntity ue = tokenService.getCurrentUser(req); |
| | | UserEntity ue = tokenService.getCurrentUser(req); |
| | | if (ue == null) { |
| | | return fail("没有找到", null); |
| | | } |