Esempio n. 1
0
  protected void handleError(Controller controller) {

    controller.setAttr("status", "error");
    String actionKey = getActionKey();
    System.out.println("actionKey: " + actionKey);
    controller.renderJson();
  }
Esempio n. 2
0
 public void intercept(ActionInvocation ai) {
   Controller cl = ai.getController();
   Object user = cl.getSessionAttr(Constants.SESSION_MEMBER);
   if (user == null) {
     cl.render("/front/test_member_login.jsp");
   } else {
     ai.invoke();
   }
 }
Esempio n. 3
0
  private String buildCacheKey(Invocation inv, Controller controller) {
    StringBuilder sb = new StringBuilder(inv.getActionKey());
    String urlPara = controller.getPara();
    if (urlPara != null) sb.append("/").append(urlPara);

    String queryString = controller.getRequest().getQueryString();
    if (queryString != null) sb.append("?").append(queryString);
    return sb.toString();
  }
Esempio n. 4
0
  protected void validate(Controller c) {
    this.validateRequired("loginName", this.getErrorName("userNameRequire"), "用户名不能为空");
    this.validateRequired("password", this.getErrorName("passwordRequire"), "密码不能为空");

    // 名称是否重复
    if (checkUserNameDuplicate(c.getPara("loginName"), c.getPara("id"))) {
      this.addError(this.getErrorName("duplicateUserName"), "用户名已经存在");
    }
  }
 @Override
 public void intercept(Invocation inv) {
   // TODO 自动生成的方法存根
   Controller c = inv.getController();
   Object user = c.getSessionAttr("userphone");
   if (user == null) {
     c.redirect("/dealer/login");
   } else inv.invoke();
 }
  @Override
  public void intercept(ActionInvocation ai) {
    ai.invoke();

    Controller c = ai.getController();
    HttpSession hs = c.getSession(false);
    if (hs != null) {
      c.setAttr("session", new HttpSessionHashModel(hs, ObjectWrapper.DEFAULT_WRAPPER));
    }
  }
Esempio n. 7
0
  private void cacheAction(String cacheName, String cacheKey, Controller controller) {
    HttpServletRequest request = controller.getRequest();
    Map<String, Object> cacheData = new HashMap<String, Object>();
    for (Enumeration<String> names = request.getAttributeNames(); names.hasMoreElements(); ) {
      String name = names.nextElement();
      cacheData.put(name, request.getAttribute(name));
    }

    cacheData.put(renderKey, new RenderInfo(controller.getRender())); // cache RenderInfo
    CacheKit.put(cacheName, cacheKey, cacheData);
  }
Esempio n. 8
0
  private void useCacheDataAndRender(Map<String, Object> cacheData, Controller controller) {
    HttpServletRequest request = controller.getRequest();
    Set<Entry<String, Object>> set = cacheData.entrySet();
    for (Iterator<Entry<String, Object>> it = set.iterator(); it.hasNext(); ) {
      Entry<String, Object> entry = it.next();
      request.setAttribute(entry.getKey(), entry.getValue());
    }
    request.removeAttribute(renderKey);

    controller.render(
        ((RenderInfo) cacheData.get(renderKey)).createRender()); // set render from cacheData
  }
Esempio n. 9
0
  @Override
  protected void validate(Controller c) {

    if (getActionKey().equals("/member/control")) {
      if (c.getPara("do").equals("save")) {
        boolean usernameEmpty = ValidateKit.isNullOrEmpty(c.getPara("user.username"));
        if (usernameEmpty) addError("user_usernameMsg", "登录名不能为空");
        else if (User.dao.findFirstBy("`user`.username=?", c.getPara("user.username")) != null) {
          addError("user_usernameMsg", "登录名已存在");
        }
      } else if (c.getPara("do").equals("update")) {
        boolean idEmpty = ValidateKit.isNullOrEmpty(c.getPara("user.id"));
        if (idEmpty) addError("user_usernameMsg", "用户不存在");
        boolean usernameEmpty = ValidateKit.isNullOrEmpty(c.getPara("user.username"));
        User user =
            User.dao.findFirstBy(
                "`user`.username=? AND `user`.id <>?",
                c.getPara("user.username"),
                c.getPara("user.id"));
        if (!idEmpty && !usernameEmpty && user != null) {
          addError("user_usernameMsg", "登录名已存在");
        }
      }
    }
  }
Esempio n. 10
0
  public static String get(Controller ctr, String key) {

    String encrypt_key = PropKit.get("encrypt_key");
    String cookieValue = ctr.getCookie(key);

    if (StringUtils.isNotBlank(cookieValue)) {
      String cookieStrings[] = cookieValue.split(COOKIE_SEPARATOR);
      if (null != cookieStrings && 4 == cookieStrings.length) {
        String encrypt_value = cookieStrings[0];
        String saveTime = cookieStrings[1];
        String maxAgeInSeconds = cookieStrings[2];
        String value = cookieStrings[3];

        String encrypt = encrypt(encrypt_key, saveTime, maxAgeInSeconds, value);

        // 保证 cookie 不被人为修改
        if (encrypt_value != null && encrypt_value.equals(encrypt)) {
          long stime = Long.parseLong(saveTime);
          long maxtime = Long.parseLong(maxAgeInSeconds) * 1000;
          // 查看是否过时
          if ((stime + maxtime) - System.currentTimeMillis() > 0) {
            return value;
          }
        }
      }
    }
    return null;
  }
Esempio n. 11
0
 protected void validateEmail(String field, boolean notBlank) {
   if (notBlank) super.validateEmail(field, ERROR_MSG, "email 格式错误 请重新输入");
   else {
     String value = controller.getPara(field);
     if (!Validate.isEmpty(value)) super.validateEmail(field, ERROR_MSG, "email 格式错误 请重新输入");
   }
 }
Esempio n. 12
0
 @Override
 public void intercept(ActionInvocation ai) {
   Controller controller = ai.getController();
   try {
     User user = (User) controller.getSession().getAttribute("loginUser");
     if (user == null) {
       controller.renderJson(JsonHelp.buildFailed());
     }
     controller.renderJson(JsonHelp.buildSuccess(JsonKit.toJson(user)));
     System.out.println(user.getStr("email"));
   } catch (Exception e) {
     e.printStackTrace();
     controller.renderJson(JsonHelp.buildFailed());
   }
   ai.invoke();
 }
Esempio n. 13
0
  /**
   * 该拦截器取得当前ActionPath,从Cache中检查是否有传送给当前Action的Flash对象Map 若有,则遍历Map,并将所有key,value注入到当前的request请求中。
   */
  public void intercept(ActionInvocation ai) {
    Controller c = ai.getController();
    HttpSession session = c.getSession(false);
    if (null == session) {
      return;
    }

    // String curAction = ai.getViewPath()+ai.getMethodName();
    String curAction = c.getRequest().getServletPath();
    ConcurrentHashMap<String, Object> flashMap = c.getFlashManager().getFlash(session, curAction);
    if (flashMap != null) {
      for (Entry<String, Object> flashEntry : flashMap.entrySet()) {
        c.setAttr(flashEntry.getKey(), flashEntry.getValue());
      }
    }
    ai.invoke();
  }
Esempio n. 14
0
  protected void handleError(Controller controller) {
    controller.keepModel(DepartmentValidator.class);

    String actionKey = getActionKey();
    if (actionKey.equals("/dept/save")) {

    } else if (actionKey.equals("/dept/update")) {

    }
  }
Esempio n. 15
0
  protected void handleError(Controller controller) {
    controller.keepModel(StationValidator.class);

    String actionKey = getActionKey();
    if (actionKey.equals("/station/save")) {

    } else if (actionKey.equals("/station/update")) {

    }
  }
  @Override
  public void intercept(ActionInvocation ai) {
    Controller controller = ai.getController();
    int id = controller.getParaToInt("id", 0);
    if (id == 0) {
      controller.renderJson("msg", "id is blank");
      return;
    }

    User targetUser = UserService.getById(id);
    if (targetUser == null) {
      controller.renderJson("msg", "no such user");
      return;
    }

    controller.setAttr("targetUser", targetUser);

    ai.invoke();
  }
Esempio n. 17
0
  protected void handleError(Controller controller) {
    controller.keepModel(Dict.class);

    String actionKey = getActionKey();
    if (actionKey.equals("/dict/save")) {

    } else if (actionKey.equals("/dict/update")) {

    }
  }
 @Override
 public void intercept(ActionInvocation ai) {
   String actionKey = ai.getActionKey();
   String uri = actionKey.substring(actionKey.lastIndexOf("/") + 1, actionKey.length());
   Controller controller = ai.getController();
   if (IGNORE_URLS.contains(uri) || !uri.contains("admin")) {
     ai.invoke();
   } else {
     Admin admin = (Admin) controller.getSession().getAttribute("_ADMIN_USER");
     if (null != admin) {
       Method method = ai.getMethod();
       if (method.isAnnotationPresent(Record.class)) {
         Record record = method.getAnnotation(Record.class);
         logger.info(
             "==== Admin transaction here! --operation "
                 + record.value()
                 + " --target "
                 + record.target().getSimpleName());
         AdminTransaction transaction = new AdminTransaction();
         StringBuilder operation = new StringBuilder(record.value().toString() + " ");
         if (OperationType.ADD == record.value()) {
           operation.append(record.target().getSimpleName().toLowerCase());
         }
         transaction
             .set("adminId", admin.get("adminId"))
             .set("operation", operation.toString())
             .set("target", record.target().getSimpleName())
             .set(
                 "message",
                 record.value().getMessage() + " (" + record.target().getSimpleName() + ")")
             .set("createdTime", new Date())
             .save();
       }
       ai.invoke();
     } else {
       controller.redirect("/admin/login");
     }
   }
 }
Esempio n. 19
0
 @Override
 protected void handleError(Controller c) {
   c.keepModel(User.class);
   c.keepPara();
   c.setAttr("state", "failure");
   if (ReturnKit.isJson(c.getRequest())) c.renderJson();
   else {
     if (getActionKey().equals("/member/control")) c.forwardAction("/member");
   }
 }
Esempio n. 20
0
  public static void put(Controller ctr, String key, String value, int maxAgeInSeconds) {
    String encrypt_key = PropKit.get("encrypt_key");
    String saveTime = System.currentTimeMillis() + "";
    String encrypt_value = encrypt(encrypt_key, saveTime, maxAgeInSeconds + "", value);

    String cookieValue =
        encrypt_value
            + COOKIE_SEPARATOR
            + saveTime
            + COOKIE_SEPARATOR
            + maxAgeInSeconds
            + COOKIE_SEPARATOR
            + value;

    ctr.setCookie(key, cookieValue, maxAgeInSeconds);
  }
 @Override
 protected void handleError(Controller c) {
   c.render("/admin/error.html");
 }
Esempio n. 22
0
 protected void handleError(Controller c) {
   c.renderText(
       BackEndUtil.createInvokeResult(
           false, false, (StringUtils.join(this.collectErrorMessage(c), " "))));
 }
Esempio n. 23
0
  /**
   * add edit 无需处理
   *
   * <p>GET /user ---> index GET /user/id ---> show POST /user ---> save PUT /user/id ---> update
   * DELECT /user/id ---> delete
   */
  public void intercept(ActionInvocation ai) {
    // 阻止 JFinal 原有规则 action 请求
    Controller controller = ai.getController();
    Boolean isRestfulForward = controller.getAttr(isRestfulForwardKey);
    String methodName = ai.getMethodName();
    if (set.contains(methodName) && isRestfulForward == null) {
      ai.getController().renderError(404);
      return;
    }

    if (isRestfulForward != null && isRestfulForward) {
      ai.invoke();
      return;
    }

    String controllerKey = ai.getControllerKey();
    String method = controller.getRequest().getMethod().toUpperCase();
    String urlPara = controller.getPara();
    if ("GET".equals(method)) {
      if (urlPara != null && !"edit".equals(methodName)) {
        controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
        controller.forwardAction(controllerKey + "/show/" + urlPara);
        return;
      }
    } else if ("POST".equals(method)) {
      controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
      controller.forwardAction(controllerKey + "/save");
      return;
    } else if ("PUT".equals(method)) {
      controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
      controller.forwardAction(controllerKey + "/update/" + urlPara);
      return;
    } else if ("DELETE".equals(method)) {
      controller.setAttr(isRestfulForwardKey, Boolean.TRUE);
      controller.forwardAction(controllerKey + "/delete/" + urlPara);
      return;
    }

    ai.invoke();
  }
  @Override
  protected void handleError(Controller controller) {

    controller.redirect("/user/error");
  }
Esempio n. 25
0
 @Override
 protected void handleError(Controller c) {
   c.renderJson(ERROR_MSG, c.getAttr(ERROR_MSG));
 }
Esempio n. 26
0
 protected boolean isEmpty(String key) {
   return Validate.isEmpty(controller.getPara(key));
 }
Esempio n. 27
0
 public static void remove(Controller ctr, String key) {
   ctr.removeCookie(key);
 }
Esempio n. 28
0
 protected void handleError(Controller controller) {
   controller.keepModel(User.class);
   String actionKey = getActionKey();
   if (actionKey.equals("/user/save")) controller.render("add.jsp");
   else if (actionKey.equals("/user/update")) controller.render("edit.jsp");
 }
Esempio n. 29
0
 public String getGroup() {
   return controller.getGroup();
 }
Esempio n. 30
0
 // TODO 考虑与 EvictInterceptor 一样强制使用  @CacheName
 private String buildCacheName(Invocation inv, Controller controller) {
   CacheName cacheName = inv.getMethod().getAnnotation(CacheName.class);
   if (cacheName != null) return cacheName.value();
   cacheName = controller.getClass().getAnnotation(CacheName.class);
   return (cacheName != null) ? cacheName.value() : inv.getActionKey();
 }