示例#1
0
 /**
  * 构建用户菜单
  *
  * @param requestDataForm
  * @param usb
  * @return
  */
 private String bulidMenu(RequestDataForm requestDataForm, UserSessionBean usb) {
   String ctxPath =
       String.valueOf(
           requestDataForm.getRequest().getSession().getServletContext().getAttribute("ctxPath"));
   String sql =
       "select a.MENU_ID,a.PARENT_MENU_ID,a.MENU_NAME,a.SEQUENCE,a.MENU_PATH,a.MENU_TYPE,b.PRIV_ID,a.URL_ID "
           + " from sys_menu_tab a"
           + " left join sys_url_tab b on a.URL_ID=b.URL_ID"
           + " where sys_abbr=?"
           + " order by PARENT_MENU_ID,SEQUENCE";
   List<Map<String, Object>> list = jdbcDao.queryForList(sql, new Object[] {sysCode});
   return MenuUtil.createMenu(ctxPath, list);
 }
示例#2
0
 /** 自动登录 */
 public ResponseDataForm autoLogin(String userId, RequestDataForm requestDataForm) {
   ResponseDataForm rdf = new ResponseDataForm();
   String loginsql = "select * from ms_user_tab where user_id=?  and is_disabled=1 ";
   Map<String, Object> map = jdbcDao.queryForMap(loginsql, new Object[] {userId});
   if (map == null || map.size() == 0) { // login faiule
     rdf.setResult(ResponseDataForm.FAULAIE);
     rdf.setResultInfo("用户不存在或密码输入有误!");
     return rdf; // 登录失败,用户名或密码有误,请重新输入!
   }
   UserSessionBean usb = new UserSessionBean();
   usb.setUserCode(map.get("USER_CODE").toString());
   usb.setUserId(map.get("USER_ID").toString());
   usb.setUserName(map.get("USER_NAME").toString());
   //		usb.setMobile(map.get("MOBILE").toString());
   usb.setUserInfo(map);
   // 设置登录信息
   requestDataForm
       .getRequest()
       .getSession()
       .setAttribute(Environment.SESSION_USER_LOGIN_INFO, usb);
   // 记录登录日志insert into cs_user_login_log_tab( LOGIN_IP, USER_CODE, OP_TIME,USER_ID,USER_NAME)
   // select ?,?,now(),?,?
   String logSql =
       "insert into cs_user_login_log_tab( LOGIN_IP, USER_CODE, OP_TIME,USER_ID,USER_NAME) select ?,?,now(),?,?";
   jdbcDao.execute(
       logSql,
       new Object[] {
         requestDataForm.getRequest().getRemoteAddr(),
         map.get("USER_CODE").toString(),
         userId,
         map.get("USER_NAME").toString()
       });
   requestDataForm
       .getRequest()
       .getSession()
       .setAttribute("session_user_menu", bulidMenu(requestDataForm, usb));
   rdf.setResult(ResponseDataForm.SESSFUL);
   return rdf;
 }
示例#3
0
  @Override
  @Transactional
  public ResponseDataForm service(RequestDataForm requestDataForm) throws Exception {
    String usercode = requestDataForm.getRequest().getParameter("usercode");
    String passwd = requestDataForm.getRequest().getParameter("passwd");
    ResponseDataForm rdf = new ResponseDataForm();
    String loginsql =
        "select * from ms_user_tab a where lower(a.USER_CODE)=lower(?) and a.USER_PWD=MD5(?) and a.is_disabled='N' ";
    Map<String, Object> map = jdbcDao.queryForMap(loginsql, new Object[] {usercode, passwd});
    if (map == null || map.size() == 0) { // login faiule
      rdf.setResult(ResponseDataForm.FAULAIE); // 登录失败,用户名或密码有误,请重新输入!
      rdf.setResultInfo("用户不存在或密码输入有误!");
      rdf.setPage("login");
    } else {
      UserSessionBean usb = new UserSessionBean();
      usb.setUserCode(map.get("USER_CODE").toString());
      usb.setUserId(map.get("USER_ID").toString());
      usb.setUserName(map.get("USER_NAME").toString());
      //	usb.setMobile(map.get("MOBILE").toString());
      usb.setUserInfo(map);
      // 设置登录信息
      requestDataForm
          .getRequest()
          .getSession()
          .setAttribute(Environment.SESSION_USER_LOGIN_INFO, usb);
      // 设置用户菜单
      requestDataForm
          .getRequest()
          .getSession()
          .setAttribute("session_user_menu", bulidMenu(requestDataForm, usb));
      rdf.setResult(ResponseDataForm.SESSFUL);
      String logSql =
          "insert into cs_user_login_log_tab( LOGIN_IP, USER_CODE, OP_TIME,USER_ID,USER_NAME) select ?,?,now(),?,?";
      jdbcDao.execute(
          logSql,
          new Object[] {
            Util.getIP(requestDataForm.getRequest()),
            usercode,
            map.get("USER_ID").toString(),
            map.get("USER_NAME").toString()
          });
      String uptSql =
          "update ms_user_tab set LAST_LOGIN_TIME = now() where user_code=? and user_pwd=MD5(?)";
      jdbcDao.execute(uptSql, new Object[] {usercode, passwd});
      if (requestDataForm.getRequest().getParameter("autologin") != null) { // 自动登录实现
        String userCode64 = Base64.encodeBase64String(usb.getUserId().getBytes("UTF-8"));
        userCode64 = userCode64.replace("\r\n", "");
        userCode64 = userCode64.replace("\n", "");
        String userEncoder = java.net.URLEncoder.encode(userCode64, Environment.ENCODING);
        Cookie usercookie = new Cookie("weiming-gswl-usercode", userEncoder);

        String passwd64 = Base64.encodeBase64String(passwd.getBytes("UTF-8"));
        passwd64 = passwd64.replace("\r\n", "");
        passwd64 = passwd64.replace("\n", "");
        String pwdEncoder = java.net.URLEncoder.encode(passwd64, Environment.ENCODING);
        Cookie passwdcookie = new Cookie("weiming-gswl-passwd", pwdEncoder);

        usercookie.setPath("/");
        passwdcookie.setPath("/");
        usercookie.setMaxAge(60 * 60 * 24 * 360); // 一年以内
        passwdcookie.setMaxAge(60 * 60 * 24 * 360); // 一年以内
        requestDataForm.getResponse().addCookie(usercookie);
        requestDataForm.getResponse().addCookie(passwdcookie);
      }
    }
    return rdf;
  }