Пример #1
0
 /** 批量删除 */
 @RequestMapping(method = RequestMethod.DELETE)
 public String batchDelete(ModelMap model, @RequestParam("items") java.lang.Long[] items) {
   for (int i = 0; i < items.length; i++) {
     commentManager.removeById(items[i]);
   }
   Flash.current().success(DELETE_SUCCESS);
   return LIST_ACTION;
 }
Пример #2
0
  /** 保存新增,@Valid标注spirng在绑定对象时自动为我们验证对象属性并存放errors在BindingResult */
  @RequestMapping(method = RequestMethod.POST)
  public String create(
      ModelMap model,
      @Valid Comment comment,
      BindingResult errors,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    if (errors.hasErrors()) {
      return "/jtzs/comment/new";
    }

    commentManager.save(comment);
    Flash.current().success(CREATED_SUCCESS); // 存放在Flash中的数据,在下一次http请求中仍然可以读取数据,error()用于显示错误消息
    return LIST_ACTION;
  }
Пример #3
0
  /** 保存更新,@Valid标注spirng在绑定对象时自动为我们验证对象属性并存放errors在BindingResult */
  @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
  public String update(
      ModelMap model,
      @PathVariable java.lang.Long id,
      @Valid Comment comment,
      BindingResult errors,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    if (errors.hasErrors()) {
      return "/jtzs/comment/edit";
    }

    commentManager.update(comment);
    Flash.current().success(UPDATE_SUCCESS);
    return LIST_ACTION;
  }
Пример #4
0
 /** 删除 */
 @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
 public String delete(ModelMap model, @PathVariable java.lang.Long id) {
   commentManager.removeById(id);
   Flash.current().success(DELETE_SUCCESS);
   return LIST_ACTION;
 }
Пример #5
0
  /**
   * 登陆
   *
   * @author jhe
   * @throws Exception
   */
  @RequestMapping(value = "/authUser/doLogin", method = RequestMethod.POST)
  public String doLogin(
      ModelMap model, AuthUser user, HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    String page = INDEX_ACTION;

    // 获得cookie登陆状态,用以判断是否
    int loginStatus = paramUtils.getIntParameter(request, "loginStatus", 0);
    AuthUser dbAuthUser = authUserManager.getMember(user.getUserName().trim().toLowerCase());

    // 登陆处理,返回结果信息
    int loginResult = authUserManager.userLogin(user, dbAuthUser);
    // 判断登录结果,做对应处理
    switch (loginResult) {
        // 成功
      case 1:
        if (loginStatus == 1) {
          this.setCookieLogin(
              response,
              dbAuthUser.getUserName(),
              AuthConstants.LOGIN_COOKIE_TIME_LENGTH,
              dbAuthUser.getCode());
        } else {
          this.setCookieLogin(response, dbAuthUser.getUserName(), 0, dbAuthUser.getCode());
        }
        cookieUtil.setCookie(
            response,
            AuthConstants.COOKIE_ADMIN_MEMBER_KEY,
            dbAuthUser.getUserName(),
            AuthConstants.LOGIN_COOKIE_TIME_LENGTH);
        this.setSessionLogin(request, dbAuthUser);

        /** 设置登录信息,暂为定值,后可从用户信息中取默认站点 */
        // siteManager.setLoginSite(response, request, 1l,
        // CommonConstants.LOGIN_COOKIE_TIME_LENGTH);
        // this.setCookieSite(response, "1",
        // CommonConstants.LOGIN_COOKIE_TIME_LENGTH);
        // 更新登陆状态信息
        dbAuthUser.setLastIp(request.getRemoteAddr());
        dbAuthUser.setLastVisiTime(new Date().getTime());
        authUserManager.update(dbAuthUser);
        break;
        // 用户被禁用
      case 2:
        page = "/admin/login";
        Flash.current().error("用户已被禁用!");
        model.addAttribute("loginStatusChecked", loginStatus);
        break;
        // 以下做穿透处理,如果返回值属于以下三种情况,则归于“用户名或密码错误”处理
        // 用户类型错误
      case 3:
        // 密码错误
      case 4:
        // 用户不存在
      case 5:
        page = "/admin/login";
        Flash.current().error("用户名或密码错误!");
        model.addAttribute("loginStatusChecked", loginStatus);
        break;
    }

    model.addAttribute("member", user);
    return page;
  }