use of org.olat.user.UserManager in project openolat by klemens.
the class CountryCodePropertyHandler method addFormItem.
/**
* @see org.olat.user.propertyhandlers.UserPropertyHandler#addFormItem(java.util.Locale,
* org.olat.core.id.User, java.lang.String, boolean,
* org.olat.core.gui.components.form.flexible.FormItemContainer)
*/
@Override
public FormItem addFormItem(Locale locale, User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
String[] allKeys = new String[countryKeys.length + 1];
System.arraycopy(countryKeys, 0, allKeys, 1, countryKeys.length);
allKeys[0] = NO_SEL_KEY;
SingleSelection sse = FormUIFactory.getInstance().addDropdownSingleselect(getName(), i18nFormElementLabelKey(), formItemContainer, allKeys, getTranslatedValues(allKeys, locale), null);
// make pre-selection of the formItem
String internalValue = getInternalValue(user);
if (internalValue == null || internalValue.isEmpty() || NO_SEL_KEY.equals(internalValue)) {
sse.select(NO_SEL_KEY, true);
} else if (isValidValue(user, internalValue, null, null) && internalValue != null) {
sse.select("country.code." + internalValue, true);
}
// enable/disable according to settings
UserManager um = UserManager.getInstance();
if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
sse.setEnabled(false);
}
if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
sse.setMandatory(true);
}
return sse;
}
use of org.olat.user.UserManager in project openolat by klemens.
the class Wiki method getRecentChanges.
protected String getRecentChanges(Locale locale) {
if (locale == null)
throw new AssertException("param was null which is not allowed");
final int MAX_RESULTS = 5;
List<WikiPage> pages = new ArrayList<>(wikiPages.values());
Collections.sort(pages, WikiPageSort.MODTIME_ORDER);
StringBuilder sb = new StringBuilder(512);
int counter = 0;
Formatter f = Formatter.getInstance(locale);
UserManager userManager = CoreSpringFactory.getImpl(UserManager.class);
for (Iterator<WikiPage> iter = pages.iterator(); iter.hasNext(); ) {
if (counter > MAX_RESULTS)
break;
WikiPage page = iter.next();
if (!page.getPageName().startsWith("O_") && !page.getPageName().startsWith(WikiPage.WIKI_MENU_PAGE)) {
sb.append("* [[");
sb.append(page.getPageName());
sb.append("]] ");
sb.append(f.formatDateAndTime(new Date(page.getModificationTime())));
sb.append(" Author: ");
long author = page.getModifyAuthor();
if (author != 0) {
String authorFullname = userManager.getUserDisplayName(author);
if (StringHelper.containsNonWhitespace(authorFullname)) {
sb.append(" Author: ").append(authorFullname);
} else {
sb.append("???");
}
}
sb.append("\n");
counter++;
}
}
return sb.toString();
}
use of org.olat.user.UserManager in project openolat by klemens.
the class AuthHelper method doInvitationLogin.
public static int doInvitationLogin(String invitationToken, UserRequest ureq, Locale locale) {
InvitationDAO invitationDao = CoreSpringFactory.getImpl(InvitationDAO.class);
boolean hasPolicies = invitationDao.hasInvitations(invitationToken, new Date());
if (!hasPolicies) {
return LOGIN_DENIED;
}
UserManager um = UserManager.getInstance();
BaseSecurity securityManager = BaseSecurityManager.getInstance();
GroupDAO groupDao = CoreSpringFactory.getImpl(GroupDAO.class);
Invitation invitation = invitationDao.findInvitation(invitationToken);
if (invitation == null) {
return LOGIN_DENIED;
}
// check if identity exists
Identity identity = um.findUniqueIdentityByEmail(invitation.getMail());
if (identity != null) {
SecurityGroup allUsers = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS);
if (securityManager.isIdentityInSecurityGroup(identity, allUsers)) {
// already a normal olat user, cannot be invited
return LOGIN_DENIED;
} else {
// fxdiff FXOLAT-151: add eventually the identity to the security group
if (!groupDao.hasRole(invitation.getBaseGroup(), identity, GroupRoles.invitee.name())) {
groupDao.addMembershipTwoWay(invitation.getBaseGroup(), identity, GroupRoles.invitee.name());
DBFactory.getInstance().commit();
}
int result = doLogin(identity, BaseSecurityModule.getDefaultAuthProviderIdentifier(), ureq);
// fxdiff FXOLAT-151: double check: problem with the DB, invitee is not marked has such
if (ureq.getUserSession().getRoles().isInvitee()) {
return result;
}
return LOGIN_DENIED;
}
}
Collection<String> supportedLanguages = CoreSpringFactory.getImpl(I18nModule.class).getEnabledLanguageKeys();
if (locale == null || !supportedLanguages.contains(locale.toString())) {
locale = I18nModule.getDefaultLocale();
}
// invitation ok -> create a temporary user
Identity invitee = invitationDao.createIdentityFrom(invitation, locale);
return doLogin(invitee, BaseSecurityModule.getDefaultAuthProviderIdentifier(), ureq);
}
use of org.olat.user.UserManager in project openolat by klemens.
the class NewUserForm method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("title.newuser");
setFormDescription("new.form.please.enter");
setFormContextHelp("User management");
formLayout.setElementCssClass("o_sel_id_create");
usernameTextElement = uifactory.addTextElement(LOGINNAME, "username", 128, "", formLayout);
usernameTextElement.setMandatory(true);
usernameTextElement.setDisplaySize(30);
usernameTextElement.setElementCssClass("o_sel_id_username");
UserManager um = UserManager.getInstance();
userPropertyHandlers = um.getUserPropertyHandlersFor(formIdentifyer, true);
// Add all available user fields to this form
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler == null)
continue;
FormItem formItem = userPropertyHandler.addFormItem(ureq.getLocale(), null, formIdentifyer, true, formLayout);
// special case to handle email field
if (userPropertyHandler.getName().equals(UserConstants.EMAIL)) {
emailTextElement = (TextElement) formItem;
if (!userModule.isEmailMandatory()) {
formItem.setMandatory(false);
}
}
formItem.setElementCssClass("o_sel_id_" + userPropertyHandler.getName().toLowerCase());
}
Map<String, String> languages = I18nManager.getInstance().getEnabledLanguagesTranslated();
String[] langKeys = StringHelper.getMapKeysAsStringArray(languages);
String[] langValues = StringHelper.getMapValuesAsStringArray(languages);
ArrayHelper.sort(langKeys, langValues, false, true, false);
// Build css classes for reference languages
languageSingleSelection = uifactory.addDropdownSingleselect("new.form.language", formLayout, langKeys, langValues, null);
// select default language in form
languageSingleSelection.select(I18nModule.getDefaultLocale().toString(), true);
// add password fields!!!
if (showPasswordFields) {
uifactory.addStaticTextElement("heading2", null, translate("new.form.please.enter.pwd"), formLayout);
// checkBox: generate user with OLAT authentication or not
String[] authKeys = { "xx" };
String[] authValues = { translate("new.form.auth.true") };
authCheckbox = uifactory.addCheckboxesHorizontal("new.form.auth", formLayout, authKeys, authValues);
authCheckbox.select("xx", showPasswordFields);
authCheckbox.addActionListener(FormEvent.ONCLICK);
// if OLAT authentication is used, use the pwd below
psw1TextElement = uifactory.addPasswordElement(PASSWORD_NEW1, "new.form.password.new1", 255, "", formLayout);
psw1TextElement.setMandatory(true);
psw1TextElement.setDisplaySize(30);
psw1TextElement.setVisible(showPasswordFields);
psw1TextElement.setElementCssClass("o_sel_id_password1");
psw1TextElement.setAutocomplete("new-password");
psw2TextElement = uifactory.addPasswordElement(PASSWORD_NEW2, "new.form.password.new2", 255, "", formLayout);
psw2TextElement.setMandatory(true);
psw2TextElement.setDisplaySize(30);
psw2TextElement.setVisible(showPasswordFields);
psw2TextElement.setElementCssClass("o_sel_id_password2");
psw2TextElement.setAutocomplete("new-password");
}
uifactory.addFormSubmitButton("save", "submit.save", formLayout);
}
use of org.olat.user.UserManager in project openolat by klemens.
the class ListRenderer method render.
/**
* Render contents of directory to a html table.
*
* @param dir
* @param secCallback
* @param ubu
* @param translator
* @param iframePostEnabled
* @return Render results.
*/
public void render(FolderComponent fc, StringOutput sb, URLBuilder ubu, Translator translator, boolean iframePostEnabled) {
if (lockManager == null) {
lockManager = CoreSpringFactory.getImpl(VFSLockManager.class);
}
if (userManager == null) {
userManager = CoreSpringFactory.getImpl(UserManager.class);
}
LicenseModule licenseModule = CoreSpringFactory.getImpl(LicenseModule.class);
LicenseHandler licenseHandler = CoreSpringFactory.getImpl(FolderLicenseHandler.class);
licensesEnabled = licenseModule.isEnabled(licenseHandler);
List<VFSItem> children = fc.getCurrentContainerChildren();
// folder empty?
if (children.size() == 0) {
sb.append("<div class=\"o_bc_empty\"><i class='o_icon o_icon_warn'></i> ").append(translator.translate("NoFiles")).append("</div>");
return;
}
boolean canVersion = FolderConfig.versionsEnabled(fc.getCurrentContainer());
String sortOrder = fc.getCurrentSortOrder();
boolean sortAsc = fc.isCurrentSortAsc();
String sortCss = (sortAsc ? "o_orderby_asc" : "o_orderby_desc");
sb.append("<table class=\"table table-condensed table-striped table-hover o_bc_table\">").append("<thead><tr><th><a class='o_orderby ").append(sortCss, FolderComponent.SORT_NAME.equals(sortOrder)).append("' ");
ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_SORTID, FolderComponent.SORT_NAME)).append(">").append(translator.translate("header.Name")).append("</a>").append("</th>");
sb.append("<th><a class='o_orderby ").append(sortCss, FolderComponent.SORT_SIZE.equals(sortOrder)).append("' ");
ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_SORTID, FolderComponent.SORT_SIZE)).append(">").append(translator.translate("header.Size")).append("</a>").append("</th><th><a class='o_orderby ").append(sortCss, FolderComponent.SORT_DATE.equals(sortOrder)).append("' ");
ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_SORTID, FolderComponent.SORT_DATE)).append(">").append(translator.translate("header.Modified")).append("</a>");
if (licensesEnabled) {
sb.append("<th>").append(translator.translate("header.license")).append("</th>");
}
if (canVersion) {
sb.append("</th><th><a class='o_orderby ").append(sortCss, FolderComponent.SORT_REV.equals(sortOrder)).append("' ");
// file size column
ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_SORTID, FolderComponent.SORT_REV)).append("><i class=\"o_icon o_icon_version o_icon-lg\" title=\"").append(translator.translate("versions")).append("\"></i></a>");
}
sb.append("</th><th><a class='o_orderby ").append(sortCss, FolderComponent.SORT_LOCK.equals(sortOrder)).append("' ");
ubu.buildHrefAndOnclick(sb, null, iframePostEnabled, false, false, new NameValuePair(PARAM_SORTID, FolderComponent.SORT_LOCK)).append("><i class=\"o_icon o_icon_locked o_icon-lg\" title=\"").append(translator.translate("lock.title")).append("\"></i></a>").append("</th><th><i class=\"o_icon o_icon_edit_metadata o_icon-lg\" title=\"").append(translator.translate("mf.edit")).append("\"></i></th></tr></thead>");
// render directory contents
String currentContainerPath = fc.getCurrentContainerPath();
if (currentContainerPath.length() > 0 && currentContainerPath.charAt(0) == '/') {
currentContainerPath = currentContainerPath.substring(1);
}
sb.append("<tbody>");
for (int i = 0; i < children.size(); i++) {
VFSItem child = children.get(i);
appendRenderedFile(fc, child, currentContainerPath, sb, ubu, translator, iframePostEnabled, canVersion, i);
}
sb.append("</tbody></table>");
}
Aggregations