Exemple #1
0
 @SuppressWarnings({"unchecked", "rawtypes"})
 public String doLogin() {
   if (super.getAccountMgr().validate(getAccount(), getPassword())) {
     Map session = ContextManager.currentSession();
     User user = getAccountMgr().getUser(getAccount());
     if (user != null && user.getId() > 0) {
       session.put(ContextManager.KEY_ACCOUNT, user.getAccount());
       session.put(ContextManager.KEY_USER_ID, user.getId());
       session.put(ContextManager.KEY_NAME, user.getName());
       Set<Role> roleList = new HashSet<Role>();
       for (Role role : user.getRoleList()) {
         Role copied = new Role();
         copied.setId(role.getId());
         copied.setName(role.getName());
         roleList.add(copied);
       }
       session.put(ContextManager.KEY_ROLE_LIST, roleList);
     } else {
       setErrMsg("用户不存在或密码错误");
       return ERROR;
     }
     if (getReturnUrl() != null && !getReturnUrl().trim().equals("")) {
       return "redirect";
     }
     return SUCCESS;
   } else {
     setErrMsg("用户不存在或密码错误");
     return ERROR;
   }
 }
Exemple #2
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  public String doLogin() {
    // 增加验证码
    Map<String, Object> session = ContextManager.currentSession();
    String kaptchaExpected =
        (String) session.get(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
    if (getKaptcha() == null || !getKaptcha().equals(kaptchaExpected)) {
      setErrMsg("验证码错误");
      return ERROR;
    }

    if (super.getAccountMgr().validate(getAccount(), getPassword())) {
      User user = getAccountMgr().getUser(getAccount());
      if (user != null && user.getId() > 0) {
        session.put(ContextManager.KEY_ACCOUNT, user.getAccount());
        session.put(ContextManager.KEY_USER_ID, user.getId());
        session.put(ContextManager.KEY_NAME, user.getName());
        Set<Role> roleList = new HashSet<Role>();
        for (Role role : user.getRoleList()) {
          Role copied = new Role();
          copied.setId(role.getId());
          copied.setName(role.getName());
          roleList.add(copied);
        }
        session.put(ContextManager.KEY_ROLE_LIST, roleList);
      } else {
        setErrMsg("用户不存在或密码错误");
        return ERROR;
      }
      if (getReturnUrl() != null && !getReturnUrl().trim().equals("")) {
        return "redirect";
      }
      return SUCCESS;
    } else {
      setErrMsg("用户不存在或密码错误");
      return ERROR;
    }
  }