hjg
2023-10-14 f6c2f15c37aef4675dda01fb5ec17cde4e141c3f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.mandi.system.controller;
 
import java.io.IOException;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import com.mandi.fendan.mapper.FdMxWlgsMapper;
import com.mandi.fendan.persist.FdMxWlgs;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.mandi.common.Jacksonmethod;
import com.mandi.common.RequestParam;
import com.mandi.common.SessionMethod;
import com.mandi.dao.common.ObjectResult;
import com.mandi.springmvc.logs.OpLogs;
import com.mandi.system.persist.Login;
import com.mandi.system.persist.ModuleEnum;
import com.mandi.system.service.IFdUserService;
 
@Controller("fdlogincon")
@RequestMapping(value="/system",method={RequestMethod.POST})
public class FdLoginCon {
 
    @Resource
    private IFdUserService user;
    @Resource
    private FdMxWlgsMapper fdMxWlgsMapper;
 
    /**
     * 登录
     * @param r
     * @param re
     * @return
     */
    @RequestMapping(value="/login.htm",method={RequestMethod.POST})
    @OpLogs(module=ModuleEnum.系统管理,name="登录账号")
    @ResponseBody
    public String login(HttpServletRequest r,HttpServletResponse re){
        String username=RequestParam.getSqlString(r, "username");
        String password=RequestParam.getSqlString(r, "password");
        String valicode=RequestParam.getSqlString(r, "valicode");//验证码
        ObjectResult<Login> orr=new ObjectResult<Login>();
        System.out.println("valicode:::"+valicode);
        if (!SessionMethod.checkvalicode(valicode, r.getSession())) {
            orr.setCode(1);
            orr.setErrmsg("验证码错误!");
            SessionMethod.writeresp(re, Jacksonmethod.tojson_date(orr, false));
            return null;
        }
        try {
            orr=user.loginUser(username, password, r.getRemoteAddr());
        } catch (Exception e) {
            e.printStackTrace();
            orr.setCode(1);
            orr.setErrmsg(StringUtils.isEmpty(e.getMessage())?"账号登录出错!":e.getMessage());
        }
 
        if(orr.getCode()==0){
            int hasFdRole = fdMxWlgsMapper.selectFdRoleExists(orr.getItem().getUsername());
            if(hasFdRole>0) {
                orr.getItem().setFdAdmin(true);
            }else {
                orr.getItem().setFdAdmin(false);
            }
            SessionMethod.setlogin(r.getSession(), orr.getItem());
        }
        String str=Jacksonmethod.tojson(orr, false);
        SessionMethod.writeresp(re, str);
        return null;
    }
 
    /**
     * 退出系统
     * @param r
     * @param re
     * @return
     */
    @OpLogs(module=ModuleEnum.系统管理,name="退出账号")
    @RequestMapping(value = "/loginout.htm", method = { RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public String logout(HttpServletRequest r, HttpServletResponse re) {
        Login l=SessionMethod.getlogin(r.getSession());
        user.logout(l);
        r.getSession().invalidate();
        try {
            String url = r.getServletContext().getContextPath()+"/login.jsf";
            re.sendRedirect(url);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
 
    /**
     * 登录用户修改密码
     * @param r
     * @param re
     * @return
     */
    @OpLogs(module=ModuleEnum.系统管理,name="密码修改")
    @RequestMapping(value = "/savePwd.htm", method = { RequestMethod.POST})
    @ResponseBody
    public String savePwd(HttpServletRequest r, HttpServletResponse re) {
        String oldpwd=RequestParam.getSqlString(r, "oldpwd");
        String newpwd=RequestParam.getSqlString(r, "newpwd");
        Login lg=SessionMethod.getlogin(r.getSession());
        ObjectResult<Boolean> orr=new ObjectResult<Boolean>();
        try {
            orr=user.updateUserPwd(oldpwd, newpwd, lg);
        } catch (Exception e) {
            e.printStackTrace();
            orr.setCode(1);
            orr.setErrmsg(StringUtils.isEmpty(e.getMessage())?"账号修改密码出错!":e.getMessage());
        }
        String str=Jacksonmethod.tojson(orr, false);
        SessionMethod.writeresp(re, str);
        return null;
    }
 
}