/**
   * @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);
  }
Пример #2
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();
      }
    }
  }