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