/*
   * (non-Javadoc)
   *
   * @see
   * javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest
   * , javax.servlet.http.HttpServletResponse)
   */
  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    this.load(req, resp);

    _title = "register";

    HttpSession session = req.getSession();
    String userName = req.getParameter("user_name");
    String password = req.getParameter("password");
    String retypePassword = req.getParameter("retype_password");
    String superResource = req.getParameter("super_resource");
    String isIssuer = req.getParameter("is_issuer");

    UserManager um = UserManager.getInstance();

    if (password == null || password.length() < 6) {
      _content = "<div id=\"notification\">Password to short.</div><br />";
      _content += getRegisterForm();
    } else if (!password.equals(retypePassword)) {
      _content = "<div id=\"notification\">Password and retyped password do not match.</div><br />";
      _content += getRegisterForm();
    } else if (userName == null || userName.length() < 1) {
      _content = "<div id=\"notification\">Username must be set.</div><br />";
      _content += getRegisterForm();
    } else if (um.getUser(userName) != null) {
      _content =
          "<div id=\"notification\">Username is already taken. Please choose another one.</div><br />";
      _content += getRegisterForm();
    } else {

      User user = new User();
      user.setUserName(userName);
      user.setPassword(password);
      user.setResourcePath(superResource);
      user.setResourceName(superResource + "/" + userName);
      user.setIssuer(isIssuer != null);
      um.registerUser(user);

      _content =
          "<p>user successfully registered!<p>"
              + "<br /><p>please log in now at: <a href=\"/login\">login</a></p>"
              + "<br /><p>user profile at: <a href=\""
              + user.getResourceName()
              + "\">"
              + user.getResourceName()
              + "</a></p>";
    }

    send();
  }
  private String getIssuers() {
    List<User> issuerList = UserManager.getInstance().getAllIssuers();
    StringBuffer selectStr = new StringBuffer();

    Iterator<User> iter = issuerList.iterator();
    while (iter.hasNext())
      selectStr.append("<option>" + iter.next().getResourceName() + "</option>");
    return selectStr.toString();
  }