/**
   * @see org.olat.login.auth.AuthenticationController#init(org.olat.core.gui.UserRequest,
   *     org.olat.core.gui.control.WindowControl)
   */
  public OLATAuthenticationController(UserRequest ureq, WindowControl winControl) {
    // use fallback translator to registration module
    super(
        ureq,
        winControl,
        Util.createPackageTranslator(RegistrationManager.class, ureq.getLocale()));

    loginComp = createVelocityContainer("olat_log", "olatlogin");

    if (userModule.isAnyPasswordChangeAllowed()) {
      pwLink = LinkFactory.createLink("_olat_login_change_pwd", "menu.pw", loginComp, this);
      pwLink.setElementCssClass("o_login_pwd");
    }

    if (registrationModule.isSelfRegistrationEnabled()
        && registrationModule.isSelfRegistrationLoginEnabled()) {
      registerLink =
          LinkFactory.createLink("_olat_login_register", "menu.register", loginComp, this);
      registerLink.setElementCssClass("o_login_register");
      registerLink.setTitle("menu.register.alt");
    }

    // prepare login form
    loginForm = new OLATAuthentcationForm(ureq, winControl, "olat_login", getTranslator());
    listenTo(loginForm);

    loginComp.put("loginForm", loginForm.getInitialComponent());

    // Check if form is triggered by external loginworkflow that has been failed
    if (ureq.getParameterSet().contains(PARAM_LOGINERROR)) {
      showError(translate("login.error", WebappHelper.getMailConfig("mailReplyTo")));
    }

    putInitialPanel(loginComp);
  }
 /**
  * Create an URL for the given locale, bundle and page that can be dispatched by this dispatcher
  *
  * @param locale The desired locale
  * @param bundleName The bundle name, e.g. "org.olat.core"
  * @param page The page, e.g. "my-file.html"
  * @return
  */
 public static String createContextHelpURI(Locale locale, String bundleName, String page) {
   return WebappHelper.getServletContextPath()
       + PATH_CHELP
       + locale.toString()
       + "/"
       + bundleName
       + "/"
       + page;
 }
Exemplo n.º 3
0
  private void sendFeedback(List<BulkAssessmentFeedback> feedbacks) {
    if (task == null) {
      log.error("Haven't a task to know creator and modifiers of the task", null);
      return;
    }

    Identity creator = task.getCreator();
    String language = creator.getUser().getPreferences().getLanguage();
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(language);
    Translator translator =
        Util.createPackageTranslator(
            BulkAssessmentOverviewController.class,
            locale,
            Util.createPackageTranslator(AssessmentManager.class, locale));
    MailManager mailManager = CoreSpringFactory.getImpl(MailManager.class);
    TaskExecutorManager taskManager = CoreSpringFactory.getImpl(TaskExecutorManager.class);

    String feedbackStr = renderFeedback(feedbacks, translator);

    MailBundle mail = new MailBundle();
    mail.setToId(creator);
    mail.setFrom(WebappHelper.getMailConfig("mailReplyTo"));
    List<Identity> modifiers = taskManager.getModifiers(task);
    if (modifiers.size() > 0) {
      ContactList cc = new ContactList("CC");
      cc.addAllIdentites(modifiers);
      mail.setContactList(cc);
    }

    String businessPath = "";
    ICourse course = CourseFactory.loadCourse(courseRes);
    CourseNode node = course.getRunStructure().getNode(courseNodeIdent);
    String courseTitle = course.getCourseTitle();
    String nodeTitle = node.getShortTitle();
    String numOfAssessedIds = Integer.toString(datas == null ? 0 : datas.getRowsSize());
    String date = Formatter.getInstance(locale).formatDateAndTime(new Date());

    mail.setContext(new MailContextImpl(courseRes, courseNodeIdent, businessPath));
    String subject =
        translator.translate("confirmation.mail.subject", new String[] {courseTitle, nodeTitle});
    String body =
        translator.translate(
            "confirmation.mail.body",
            new String[] {courseTitle, nodeTitle, feedbackStr, numOfAssessedIds, date});
    mail.setContent(subject, body);
    mailManager.sendMessage(mail);
  }
  /**
   * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
   *     org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
   */
  @Override
  public void event(UserRequest ureq, Controller source, Event event) {
    if (source == loginForm && event == Event.DONE_EVENT) {
      String login = loginForm.getLogin();
      String pass = loginForm.getPass();
      if (loginModule.isLoginBlocked(login)) {
        // do not proceed when blocked
        showError("login.blocked", loginModule.getAttackPreventionTimeoutMin().toString());
        getLogger()
            .audit(
                "Login attempt on already blocked login for "
                    + login
                    + ". IP::"
                    + ureq.getHttpReq().getRemoteAddr(),
                null);
        return;
      }
      authenticatedIdentity = olatAuthenticationSpi.authenticate(null, login, pass);
      if (authenticatedIdentity == null) {
        if (loginModule.registerFailedLoginAttempt(login)) {
          getLogger()
              .audit(
                  "Too many failed login attempts for "
                      + login
                      + ". Login blocked. IP::"
                      + ureq.getHttpReq().getRemoteAddr(),
                  null);
          showError("login.blocked", loginModule.getAttackPreventionTimeoutMin().toString());
          return;
        } else {
          showError("login.error", WebappHelper.getMailConfig("mailReplyTo"));
          return;
        }
      } else {
        try {
          String language = authenticatedIdentity.getUser().getPreferences().getLanguage();
          UserSession usess = ureq.getUserSession();
          if (StringHelper.containsNonWhitespace(language)) {
            usess.setLocale(I18nManager.getInstance().getLocaleOrDefault(language));
          }
        } catch (Exception e) {
          logError("Cannot set the user language", e);
        }
      }

      loginModule.clearFailedLoginAttempts(login);

      // Check if disclaimer has been accepted
      if (registrationManager.needsToConfirmDisclaimer(authenticatedIdentity)) {
        // accept disclaimer first

        removeAsListenerAndDispose(disclaimerCtr);
        disclaimerCtr = new DisclaimerController(ureq, getWindowControl());
        listenTo(disclaimerCtr);

        removeAsListenerAndDispose(cmc);
        cmc =
            new CloseableModalController(
                getWindowControl(), translate("close"), disclaimerCtr.getInitialComponent());
        listenTo(cmc);

        cmc.activate();

      } else {
        // disclaimer acceptance not required
        authenticated(ureq, authenticatedIdentity);
      }
    } else if (source == disclaimerCtr) {
      cmc.deactivate();
      if (event == Event.DONE_EVENT) {
        // disclaimer accepted
        registrationManager.setHasConfirmedDislaimer(authenticatedIdentity);
        authenticated(ureq, authenticatedIdentity);
      }
    } else if (cmc == source) {
      cleanUp();
    }
    if (source == subController) {
      if (event == Event.CANCELLED_EVENT) {
        cmc.deactivate();
        cleanUp();
      }
    }
  }
  /**
   * @see org.olat.core.dispatcher.Dispatcher#execute(javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse, java.lang.String)
   */
  @Override
  public void execute(HttpServletRequest request, HttpServletResponse response) {
    UserRequest ureq = null;

    try {
      String uriPrefix = DispatcherModule.getLegacyUriPrefix(request);
      ureq = new UserRequestImpl(uriPrefix, request, response);
      if (!ContextHelpModule.isContextHelpEnabled()) {
        // disabled context help - redirect immediately
        DispatcherModule.sendNotFound(ureq.getNonParsedUri(), response);
        return;
      }

      ChiefController cc =
          (ChiefController)
              Windows.getWindows(ureq.getUserSession()).getAttribute(CONTEXTHELPCHIEFCONTROLLER);
      // reuse existing chief controller for this user
      if (cc != null) {
        Window currentWindow = cc.getWindow();
        // Check if this is a start URL or a framework URL
        if (ureq.isValidDispatchURI()) {
          // A standard framework request, dispatch by component
          currentWindow.dispatchRequest(ureq, false);
          return;
        } else {
          // If path contains complete URL, dispose and start from scratch
          Windows.getWindows(ureq).deregisterWindow(currentWindow);
          cc.dispose();
        }
      }

      // Creator code to create
      // 1) the chief controller
      // 2) the layout controller
      // 3) the context help main controller
      ControllerCreator cHelpPopupWindowControllerCreator =
          new ControllerCreator() {
            public Controller createController(UserRequest lureq, WindowControl lwControl) {
              ControllerCreator cHelpMainControllerCreator =
                  new ControllerCreator() {
                    public Controller createController(UserRequest lureq, WindowControl lwControl) {
                      // create the context help controller and wrapp it using the layout controller
                      ContextHelpMainController helpCtr =
                          new ContextHelpMainController(lureq, lwControl);
                      LayoutMain3ColsController layoutCtr =
                          new LayoutMain3ColsController(
                              lureq, lwControl, null, null, helpCtr.getInitialComponent(), null);
                      layoutCtr.addDisposableChildController(helpCtr);
                      return layoutCtr;
                    }
                  };
              ContextHelpLayoutControllerCreator cHelpPopupLayoutCreator =
                  new ContextHelpLayoutControllerCreator(cHelpMainControllerCreator);
              return new BaseFullWebappPopupBrowserWindow(
                  lureq, lwControl, cHelpPopupLayoutCreator.getFullWebappParts());
            }
          };

      BaseChiefControllerCreator bbc = new BaseChiefControllerCreator();
      bbc.setContentControllerCreator(cHelpPopupWindowControllerCreator);
      cc = bbc.createChiefController(ureq);
      // add to user session for cleanup on user logout
      Windows.getWindows(ureq.getUserSession()).setAttribute(CONTEXTHELPCHIEFCONTROLLER, cc);
      Window currentWindow = cc.getWindow();
      currentWindow.setUriPrefix(WebappHelper.getServletContextPath() + PATH_CHELP);
      Windows.getWindows(ureq).registerWindow(currentWindow);
      // finally dispatch the initial request
      currentWindow.dispatchRequest(ureq, true);

    } catch (Throwable th) {
      try {
        ChiefController msgcc = MsgFactory.createMessageChiefController(ureq, th);
        // the controller's window must be failsafe also
        msgcc.getWindow().dispatchRequest(ureq, true);
        // do not dispatch (render only), since this is a new Window created as
        // a result of another window's click.
      } catch (Throwable t) {
        logError("Sorry, can't handle this context help request....", t);
      }
    }
  }