管道基础大数据平台系统开发-【后端】-Server
1
13693261870
2022-10-17 42128cb41c46b240f18f4aa132c142db0138b3ed
src/main/java/com/lf/server/controller/all/SignController.java
@@ -6,11 +6,11 @@
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;
@@ -33,7 +33,7 @@
@RequestMapping("/sign")
public class SignController extends BaseController {
    @Autowired
    UsersService userService;
    UserService userService;
    @Autowired
    LoginService loginService;
@@ -53,7 +53,7 @@
    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() + " !");
        }
@@ -78,7 +78,7 @@
        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)) {
@@ -86,7 +86,7 @@
                }
            }
        } catch (Exception ex) {
            //
            log.error(ex.getMessage() + ex.getStackTrace() + "\n");
        }
        return mv;
@@ -99,12 +99,12 @@
        try {
            mv.setViewName("redirect:/toLogin");
            UsersEntity ue = tokenService.getCurrentUser(req);
            UserEntity ue = tokenService.getCurrentUser(req);
            if (ue != null) {
                mv.setViewName("monitor");
            }
        } catch (Exception ex) {
            //
            log.error(ex.getMessage() + ex.getStackTrace() + "\n");
        }
        return mv;
@@ -116,44 +116,33 @@
            @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);
            }
            if (StringHelper.isEmpty(user.getUid())) {
                return fail("用户名不能为空!", null);
            }
            if (StringHelper.isEmpty(user.getPwd())) {
                return fail("密码不能为空!", null);
            String str = userService.validateLoginPwd(user);
            if (str != null) {
                return fail(str, null);
            }
            // 解密
            String uid = RsaHelper.decrypt(user.getUid());
            String pwd = RsaHelper.decrypt(user.getPwd());
            UsersEntity ue = userService.selectByUid(uid);
            UserEntity ue = userService.selectByUid(user.getUid());
            if (ue == null) {
                return fail("用户名不存在!", null);
                return fail("用户名不存在", null);
            }
            LoginEntity le = loginService.getNewLogin(ue.getId(), 1, req);
            if (!Md5Helper.validatePassword(pwd, ue.getPwd())) {
                le.setStatus(0);
                le.setDescr("密码错误");
                loginService.insertLogin(le);
                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);
                return fail("创建登录日志失败", null);
            }
            TokenEntity te = tokenService.getNewToken(ue.getId(), req);
            rows = tokenService.insertToken(te);
            if (rows == 0) {
                return fail("创建令牌信息失败!", null);
                return fail("创建令牌失败", null);
            }
            tokenService.saveToken(ue, te, req, res);
@@ -190,8 +179,8 @@
            Boolean flag = tokenService.isLogin(req, res);
            if (flag) {
                // 写日志
                UsersEntity ue = tokenService.getCurrentUser(req);
                LoginEntity le = loginService.getNewLogin(ue.getId(), 2, req);
                UserEntity ue = tokenService.getCurrentUser(req);
                LoginEntity le = loginService.getNewLogin(ue.getId(), 1, 2, 1, req);
                Integer rows = loginService.insertLogin(le);
            }
@@ -204,9 +193,9 @@
    @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);
            }