Ejemplo n.º 1
0
  public HttpServletRequest addtagurl(HttpServletRequest req, HttpServletResponse response)
      throws SQLException {
    User user = User.getInstance();
    if (user == null) {
      this.parent.redirect("login", true);
      return req;
    } else {

      String uri = (String) req.getParameter("url");
      String listTag = (String) req.getParameter("list");
      Url url = user.getUrlById(Integer.valueOf(uri));
      String str[] = listTag.split("@");
      for (int i = 0; i < str.length; i++) {
        Tag tag = user.getTagByName(str[i]);
        if (tag == null) {
          // add tag
          tag = new Tag(str[i], user.getuId());
          tag.addTagtoBDD();
          tag.setTid(tag.getTagIdFromBDD());
          user.addOneTag(tag);
        }
        if (!url.hasTag(tag)) {
          TagMap tm = new TagMap(tag, url);
          tm.addTagMaptoBDD(user.getuId());
          tm.setTmId(tm.getIdFromBdd());
          user.addOneMap(tm);
        }
      }
      return req;
    }
  }
Ejemplo n.º 2
0
  /**
   * Fonction login Gere la connexion de l'utilisateur lors de son arrivee dans l'application
   *
   * @param req : HttpServletRequest *
   */
  public HttpServletRequest login(HttpServletRequest req, HttpServletResponse response) {
    String email = req.getParameter("email");
    String mdp = req.getParameter("password");
    boolean access = false;
    User user;
    if (email != null) {
      try {
        user = User.getInstance(email, mdp);
        System.out.println(email);
        System.out.println(mdp);
        if (user != null) {
          Cookie userCookie = new Cookie("userId", Integer.toString(user.getuId()));
          response.addCookie(userCookie);
          this.parent.session().open(user);
          this.parent.redirect("accueil", true);
        }
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    return req;
  }