示例#1
0
  protected void doDSPost(Context context, HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException, SQLException, AuthorizeException {
    // Process the POSTed email and password
    String netid = request.getParameter("login_netid");
    String password = request.getParameter("login_password");
    String jsp = null;

    // Locate the eperson
    int status = AuthenticationManager.authenticate(context, netid, password, null, request);

    if (status == AuthenticationMethod.SUCCESS) {
      // Logged in OK.
      Authenticate.loggedIn(context, request, context.getCurrentUser());

      // Set the Locale according to user preferences
      Locale epersonLocale = I18nUtil.getEPersonLocale(context.getCurrentUser());
      context.setCurrentLocale(epersonLocale);
      Config.set(request.getSession(), Config.FMT_LOCALE, epersonLocale);

      log.info(LogManager.getHeader(context, "login", "type=explicit"));

      // resume previous request
      Authenticate.resumeInterruptedRequest(request, response);

      return;
    } else if (status == AuthenticationMethod.CERT_REQUIRED) {
      jsp = "/error/require-certificate.jsp";
    } else {
      jsp = "/login/incorrect.jsp";
    }

    // If we reach here, supplied email/password was duff.
    log.info(
        LogManager.getHeader(
            context, "failed_login", "netid=" + netid + ", result=" + String.valueOf(status)));
    JSPManager.showJSP(request, response, jsp);
  }
  /**
   * Show a collection home page, or deal with button press on home page
   *
   * @param context Context object
   * @param request the HTTP request
   * @param response the HTTP response
   * @param community the community
   * @param collection the collection
   */
  private void collectionHome(
      Context context,
      HttpServletRequest request,
      HttpServletResponse response,
      Community community,
      Collection collection)
      throws ServletException, IOException, SQLException, AuthorizeException {
    // Handle click on a browse or search button
    if (!handleButton(request, response, IdentifierService.getURL(community))) {
      // Will need to know whether to commit to DB
      boolean updated = false;

      // No search or browse button pressed, check for
      if (request.getParameter("submit_subscribe") != null) {
        // Subscribe button pressed.
        // Only registered can subscribe, so redirect unless logged in.
        if (context.getCurrentUser() == null
            && !Authenticate.startAuthentication(context, request, response)) return;
        else {
          SubscriptionManager.subscribe(context, context.getCurrentUser(), collection);
          updated = true;
        }
      } else if (request.getParameter("submit_unsubscribe") != null) {
        SubscriptionManager.unsubscribe(context, context.getCurrentUser(), collection);
        updated = true;
      }

      // display collection home page
      log.info(
          LogManager.getHeader(context, "view_collection", "collection_id=" + collection.getID()));

      // perform any necessary pre-processing
      preProcessCollectionHome(context, request, response, collection);

      // Is the user logged in/subscribed?
      EPerson e = context.getCurrentUser();
      boolean subscribed = false;

      if (e != null) {
        subscribed = SubscriptionManager.isSubscribed(context, e, collection);

        // is the user a COLLECTION_EDITOR?
        //                if (collection.canEditBoolean())
        if (AuthorizeManager.canEdit(collection, context)) {
          // set a variable to create an edit button
          request.setAttribute("editor_button", new Boolean(true));
        }

        // can they admin this collection?
        if (AuthorizeManager.authorizeActionBoolean(
            context, collection, Constants.COLLECTION_ADMIN)) {
          request.setAttribute("admin_button", new Boolean(true));

          // give them a button to manage submitter list
          // what group is the submitter?
          Group group = collection.getSubmitters();

          if (group != null) {
            request.setAttribute("submitters", group);
          }
        }

        // can they submit to this collection?
        if (AuthorizeManager.authorizeActionBoolean(context, collection, Constants.ADD)) {
          request.setAttribute("can_submit_button", new Boolean(true));

        } else {
          request.setAttribute("can_submit_button", new Boolean(false));
        }
      }

      // Forward to collection home page
      request.setAttribute("collection", collection);
      request.setAttribute("community", community);
      request.setAttribute("logged.in", new Boolean(e != null));
      request.setAttribute("subscribed", new Boolean(subscribed));
      JSPManager.showJSP(request, response, "/collection-home.jsp");

      if (updated) {
        context.complete();
      }
    }
  }