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 orr=new ObjectResult(); 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 orr=new ObjectResult(); 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; } }