Search in sources :

Example 6 with LanguageChangedEvent

use of org.olat.core.commons.chiefcontrollers.LanguageChangedEvent in project OpenOLAT by OpenOLAT.

the class RegistrationController method event.

/**
 * @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 == emailSendForm) {
        if (event == Event.DONE_EVENT) {
            // form
            // validation
            // was ok
            wizInfoController.setCurStep(2);
            // Email requested for tempkey
            // save the fields somewhere
            String email = emailSendForm.getEmailAddress();
            myContent.contextPut("email", email);
            myContent.contextPut("text", translate("step2.reg.text", email));
            // ef.setVisible(false);
            regarea.setVisible(false);
            // get remote address
            String ip = ureq.getHttpReq().getRemoteAddr();
            String serverpath = Settings.getServerContextPathURI();
            String today = DateFormat.getDateInstance(DateFormat.LONG, ureq.getLocale()).format(new Date());
            String[] whereFromAttrs = new String[] { serverpath, today, ip };
            boolean isMailSent = false;
            if (registrationManager.isRegistrationPending(email) || UserManager.getInstance().isEmailAllowed(email)) {
                TemporaryKey tk = null;
                if (userModule.isEmailUnique()) {
                    tk = registrationManager.loadTemporaryKeyByEmail(email);
                }
                if (tk == null)
                    tk = registrationManager.loadOrCreateTemporaryKeyByEmail(email, ip, RegistrationManager.REGISTRATION);
                myContent.contextPut("regKey", tk.getRegistrationKey());
                String link = serverpath + "/dmz/registration/index.html?key=" + tk.getRegistrationKey() + "&language=" + i18nModule.getLocaleKey(ureq.getLocale());
                String[] bodyAttrs = new String[] { // 0
                serverpath, // 1
                tk.getRegistrationKey(), // 2
                i18nModule.getLocaleKey(ureq.getLocale()), // 3
                "<a href=\"" + link + "\">" + link + "</a>" };
                String body = translate("reg.body", bodyAttrs);
                boolean htmlBody = StringHelper.isHtml(body);
                if (!htmlBody) {
                    body += SEPARATOR + translate("reg.wherefrom", whereFromAttrs);
                }
                try {
                    MailBundle bundle = new MailBundle();
                    bundle.setTo(email);
                    bundle.setContent(translate("reg.subject"), body);
                    MailerResult result = mailManager.sendExternMessage(bundle, null, htmlBody);
                    if (result.isSuccessful()) {
                        isMailSent = true;
                    }
                } catch (Exception e) {
                // nothing to do, emailSent flag is false, errors will be reported to user
                }
            } else {
                // if users with this email address exists, they are informed.
                List<Identity> identities = UserManager.getInstance().findIdentitiesByEmail(Collections.singletonList(email));
                for (Identity identity : identities) {
                    String body = translate("login.body", identity.getName()) + SEPARATOR + translate("reg.wherefrom", whereFromAttrs);
                    try {
                        MailBundle bundle = new MailBundle();
                        bundle.setTo(email);
                        bundle.setContent(translate("login.subject"), body);
                        MailerResult result = mailManager.sendExternMessage(bundle, null, true);
                        if (result.isSuccessful()) {
                            isMailSent = true;
                        }
                    } catch (Exception e) {
                    // nothing to do, emailSent flag is false, errors will be reported to user
                    }
                }
            }
            if (isMailSent) {
                showInfo("email.sent");
            } else {
                showError("email.notsent");
            }
        } else if (event == Event.CANCELLED_EVENT) {
            fireEvent(ureq, Event.CANCELLED_EVENT);
        }
    } else if (source == langChooserController) {
        if (event == Event.DONE_EVENT) {
            wizInfoController.setCurStep(2);
            createEmailForm(ureq);
            ureq.getUserSession().removeEntry(LocaleNegotiator.NEGOTIATED_LOCALE);
        } else if (event == Event.CANCELLED_EVENT) {
            ureq.getDispatchResult().setResultingMediaResource(new RedirectMediaResource(Settings.getServerContextPathURI()));
        } else if (event instanceof LanguageChangedEvent) {
            LanguageChangedEvent lcev = (LanguageChangedEvent) event;
            setLocale(lcev.getNewLocale(), true);
            myContent.contextPut("text", translate("select.language.description"));
        }
    } else if (source == registrationForm) {
        // Userdata entered
        if (event == Event.DONE_EVENT) {
            String lang = registrationForm.getLangKey();
            // change language if different then current language
            if (!lang.equals(i18nModule.getLocaleKey(ureq.getLocale()))) {
                Locale loc = i18nManager.getLocaleOrDefault(lang);
                ureq.getUserSession().setLocale(loc);
                getTranslator().setLocale(loc);
            }
            wizInfoController.setCurStep(4);
            myContent.contextPut("pwdhelp", "");
            myContent.contextPut("loginhelp", "");
            myContent.contextPut("text", translate("step4.reg.text"));
            removeAsListenerAndDispose(disclaimerController);
            disclaimerController = new DisclaimerController(ureq, getWindowControl());
            listenTo(disclaimerController);
            regarea.setContent(disclaimerController.getInitialComponent());
        } else if (event == Event.CANCELLED_EVENT) {
            ureq.getDispatchResult().setResultingMediaResource(new RedirectMediaResource(Settings.getServerContextPathURI()));
        }
    } else if (source == disclaimerController) {
        if (event == Event.DONE_EVENT) {
            // finalize the registration by creating the user
            Identity persitedIdentity = createNewUserAfterRegistration();
            // display step5
            displayFinalStep(persitedIdentity);
        } else if (event == Event.CANCELLED_EVENT) {
            ureq.getDispatchResult().setResultingMediaResource(new RedirectMediaResource(Settings.getServerContextPathURI()));
        }
    }
}
Also used : Locale(java.util.Locale) MailerResult(org.olat.core.util.mail.MailerResult) LanguageChangedEvent(org.olat.core.commons.chiefcontrollers.LanguageChangedEvent) Date(java.util.Date) RedirectMediaResource(org.olat.core.gui.media.RedirectMediaResource) MailBundle(org.olat.core.util.mail.MailBundle) Identity(org.olat.core.id.Identity)

Example 7 with LanguageChangedEvent

use of org.olat.core.commons.chiefcontrollers.LanguageChangedEvent in project openolat by klemens.

the class ShibbolethRegistrationController method event.

@Override
public void event(UserRequest ureq, Controller source, Event event) {
    if (source == migrationForm) {
        if (event == Event.CANCELLED_EVENT) {
            mainContainer.setPage(VELOCITY_ROOT + "/register.html");
        } else if (event == Event.DONE_EVENT) {
            state = STATE_MIGRATED_SHIB_USER;
            mainContainer.setPage(VELOCITY_ROOT + "/disclaimer.html");
        }
    } else if (source == regWithUserPropForm) {
        if (event == Event.CANCELLED_EVENT) {
            mainContainer.setPage(VELOCITY_ROOT + "/register.html");
        } else if (event == Event.DONE_EVENT) {
            state = STATE_NEW_SHIB_USER;
            mainContainer.setPage(VELOCITY_ROOT + "/disclaimer.html");
        }
    } else if (source == regForm) {
        if (event == Event.DONE_EVENT) {
            String choosenLogin = regForm.getLogin();
            BaseSecurity secMgr = BaseSecurityManager.getInstance();
            Identity identity = secMgr.findIdentityByName(choosenLogin);
            if (identity == null) {
                // ok, create new user
                if (isMandatoryUserPropertyMissing()) {
                    regWithUserPropForm = new ShibbolethRegistrationUserPropertiesFrom(ureq, getWindowControl(), shibbolethAttributes);
                    regWithUserPropForm.addControllerListener(this);
                    mainContainer.put("getUserPropsForm", regWithUserPropForm.getInitialComponent());
                    mainContainer.setPage(VELOCITY_ROOT + "/register_user_props.html");
                } else {
                    state = STATE_NEW_SHIB_USER;
                    mainContainer.setPage(VELOCITY_ROOT + "/disclaimer.html");
                }
            } else {
                // offer identity migration, if OLAT provider exists
                Authentication auth = secMgr.findAuthentication(identity, BaseSecurityModule.getDefaultAuthProviderIdentifier());
                if (auth == null) {
                    // no OLAT provider, migration not possible...
                    getWindowControl().setError(translator.translate("sr.error.loginexists", new String[] { WebappHelper.getMailConfig("mailSupport") }));
                } else {
                    // OLAT provider exists, offer migration...
                    migrationForm = new ShibbolethMigrationForm(ureq, getWindowControl(), auth);
                    migrationForm.addControllerListener(this);
                    mainContainer.put("migrationForm", migrationForm.getInitialComponent());
                    mainContainer.setPage(VELOCITY_ROOT + "/migration.html");
                }
            }
        }
    } else if (source == languageChooserController) {
        if (event == Event.DONE_EVENT) {
            // language choosed
            mainContainer.setPage(VELOCITY_ROOT + "/register.html");
            ureq.getUserSession().removeEntry(LocaleNegotiator.NEGOTIATED_LOCALE);
        } else if (event instanceof LanguageChangedEvent) {
            LanguageChangedEvent lcev = (LanguageChangedEvent) event;
            translator.setLocale(lcev.getNewLocale());
            dclController.changeLocale(lcev.getNewLocale());
        }
    } else if (source == dclController) {
        if (event == Event.DONE_EVENT) {
            // disclaimer accepted...
            if (state == STATE_NEW_SHIB_USER) {
                // ...proceed and create user
                String choosenLogin;
                if (regForm == null) {
                    choosenLogin = proposedUsername;
                } else {
                    choosenLogin = regForm.getLogin();
                }
                // check if login has been taken by another user in the meantime...
                BaseSecurity secMgr = BaseSecurityManager.getInstance();
                // check if login has been taken by another user in the meantime...
                Identity identity = secMgr.findIdentityByName(choosenLogin);
                if (identity != null) {
                    getWindowControl().setError(translator.translate("sr.login.meantimetaken"));
                    mainContainer.setPage(VELOCITY_ROOT + "/register.html");
                    state = STATE_UNDEFINED;
                    return;
                }
                String email = shibbolethAttributes.getValueForUserPropertyName(UserConstants.EMAIL);
                if (!UserManager.getInstance().isEmailAllowed(email)) {
                    // error, email already exists. should actually not happen if OLAT Authenticator has
                    // been set after removing shibboleth authenticator
                    getWindowControl().setError(translator.translate("sr.error.emailexists", new String[] { WebappHelper.getMailConfig("mailSupport") }));
                    mainContainer.setPage(VELOCITY_ROOT + "/register.html");
                    state = STATE_UNDEFINED;
                    return;
                }
                identity = shibbolethManager.createUser(choosenLogin, shibbolethUniqueID, locale.getLanguage(), shibbolethAttributes);
                // tell system that this user did accept the disclaimer
                CoreSpringFactory.getImpl(RegistrationManager.class).setHasConfirmedDislaimer(identity);
                doLogin(identity, ureq);
                return;
            } else if (state == STATE_MIGRATED_SHIB_USER) {
                // ...proceed and migrate user
                // create additional authentication
                Authentication auth = migrationForm.getAuthentication();
                Identity authenticationedIdentity = auth.getIdentity();
                BaseSecurity secMgr = BaseSecurityManager.getInstance();
                secMgr.createAndPersistAuthentication(authenticationedIdentity, ShibbolethDispatcher.PROVIDER_SHIB, shibbolethUniqueID, null, null);
                // update user profile
                shibbolethManager.syncUser(authenticationedIdentity, shibbolethAttributes);
                doLogin(authenticationedIdentity, ureq);
                return;
            }
        } else if (event == Event.CANCELLED_EVENT) {
            mainContainer.setPage(VELOCITY_ROOT + "/register.html");
            getWindowControl().setError(translator.translate("sr.error.disclaimer"));
        }
    }
}
Also used : RegistrationManager(org.olat.registration.RegistrationManager) Authentication(org.olat.basesecurity.Authentication) LanguageChangedEvent(org.olat.core.commons.chiefcontrollers.LanguageChangedEvent) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 8 with LanguageChangedEvent

use of org.olat.core.commons.chiefcontrollers.LanguageChangedEvent in project openolat by klemens.

the class BaseFullWebappController method event.

@Override
public void event(Event event) {
    if (event == Window.AFTER_VALIDATING) {
        // now update the guimessage
        List<ZIndexWrapper> places = getWindowControl().getWindowBackOffice().getGuiMessages();
        Panel winnerP = null;
        int maxZ = -1;
        if (places != null) {
            // we have places where we can put the gui message
            for (Iterator<ZIndexWrapper> it_places = places.iterator(); it_places.hasNext(); ) {
                ZIndexWrapper ziw = it_places.next();
                int cind = ziw.getZindex();
                if (cind > maxZ) {
                    maxZ = cind;
                    winnerP = ziw.getPanel();
                }
            }
        } else {
            winnerP = guimsgHolder;
        }
        if (winnerP != null && winnerP != currentMsgHolder) {
            currentMsgHolder.setContent(null);
            winnerP.setContent(guimsgPanel);
            currentMsgHolder = winnerP;
        } else {
            currentMsgHolder = guimsgHolder;
            currentMsgHolder.setContent(guimsgPanel);
            currentMsgHolder.setDirty(guimsgPanel.isDirty());
        }
    } else if (event instanceof LanguageChangedEvent) {
        LanguageChangedEvent lce = (LanguageChangedEvent) event;
        UserRequest ureq = lce.getCurrentUreq();
        getTranslator().setLocale(lce.getNewLocale());
        initialize(ureq);
        WindowManager winman = Windows.getWindows(ureq).getWindowManager();
        initializeBase(ureq, winman, initialPanel);
        initialPanel.setContent(mainVc);
        reload = Boolean.TRUE;
    } else if (event instanceof ChiefControllerMessageEvent) {
        // msg can be set to show only on one node or on all nodes
        updateStickyMessage();
    } else if (event instanceof AssessmentModeNotificationEvent) {
        try {
            processAssessmentModeNotificationEvent((AssessmentModeNotificationEvent) event);
        } catch (Exception e) {
            logError("", e);
        }
    }
}
Also used : OncePanel(org.olat.core.gui.components.panel.OncePanel) Panel(org.olat.core.gui.components.panel.Panel) StackedPanel(org.olat.core.gui.components.panel.StackedPanel) AssessmentModeNotificationEvent(org.olat.course.assessment.AssessmentModeNotificationEvent) ZIndexWrapper(org.olat.core.gui.control.util.ZIndexWrapper) LanguageChangedEvent(org.olat.core.commons.chiefcontrollers.LanguageChangedEvent) ChiefControllerMessageEvent(org.olat.core.commons.chiefcontrollers.ChiefControllerMessageEvent) HistoryPoint(org.olat.core.id.context.HistoryPoint) UserRequest(org.olat.core.gui.UserRequest) AssertException(org.olat.core.logging.AssertException) WindowManager(org.olat.core.gui.WindowManager)

Aggregations

LanguageChangedEvent (org.olat.core.commons.chiefcontrollers.LanguageChangedEvent)8 Locale (java.util.Locale)4 Identity (org.olat.core.id.Identity)4 Date (java.util.Date)2 Authentication (org.olat.basesecurity.Authentication)2 BaseSecurity (org.olat.basesecurity.BaseSecurity)2 ChiefControllerMessageEvent (org.olat.core.commons.chiefcontrollers.ChiefControllerMessageEvent)2 UserRequest (org.olat.core.gui.UserRequest)2 WindowManager (org.olat.core.gui.WindowManager)2 OncePanel (org.olat.core.gui.components.panel.OncePanel)2 Panel (org.olat.core.gui.components.panel.Panel)2 StackedPanel (org.olat.core.gui.components.panel.StackedPanel)2 ZIndexWrapper (org.olat.core.gui.control.util.ZIndexWrapper)2 RedirectMediaResource (org.olat.core.gui.media.RedirectMediaResource)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 HistoryPoint (org.olat.core.id.context.HistoryPoint)2 AssertException (org.olat.core.logging.AssertException)2 MultiUserEvent (org.olat.core.util.event.MultiUserEvent)2 MailBundle (org.olat.core.util.mail.MailBundle)2 MailerResult (org.olat.core.util.mail.MailerResult)2