use of org.olat.user.UserManager in project openolat by klemens.
the class RegistrationController method createNewUserAfterRegistration.
/**
* OO-92
* this will finally create the user, set all it's userproperties
*
* @return User the newly created, persisted User Object
*/
private Identity createNewUserAfterRegistration() {
// create user with mandatory fields from registration-form
UserManager um = UserManager.getInstance();
User volatileUser = um.createUser(registrationForm.getFirstName(), registrationForm.getLastName(), tempKey.getEmailAddress());
// set user configured language
Preferences preferences = volatileUser.getPreferences();
preferences.setLanguage(registrationForm.getLangKey());
volatileUser.setPreferences(preferences);
// create an identity with the given username / pwd and the user object
String login = registrationForm.getLogin();
String pwd = registrationForm.getPassword();
Identity persistedIdentity = registrationManager.createNewUserAndIdentityFromTemporaryKey(login, pwd, volatileUser, tempKey);
if (persistedIdentity == null) {
showError("user.notregistered");
return null;
} else {
// update other user properties from form
List<UserPropertyHandler> userPropertyHandlers = um.getUserPropertyHandlersFor(RegistrationForm2.USERPROPERTIES_FORM_IDENTIFIER, false);
User persistedUser = persistedIdentity.getUser();
// add eventually static value
UserPropertiesConfig userPropertiesConfig = CoreSpringFactory.getImpl(UserPropertiesConfig.class);
if (registrationModule.isStaticPropertyMappingEnabled()) {
String propertyName = registrationModule.getStaticPropertyMappingName();
String propertyValue = registrationModule.getStaticPropertyMappingValue();
if (StringHelper.containsNonWhitespace(propertyName) && StringHelper.containsNonWhitespace(propertyValue) && userPropertiesConfig.getPropertyHandler(propertyName) != null) {
try {
persistedUser.setProperty(propertyName, propertyValue);
} catch (Exception e) {
logError("Cannot set the static property value", e);
}
}
}
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
FormItem fi = registrationForm.getPropFormItem(userPropertyHandler.getName());
userPropertyHandler.updateUserFromFormItem(persistedUser, fi);
}
// persist changes in db
um.updateUserFromIdentity(persistedIdentity);
// send notification mail to sys admin
String notiEmail = CoreSpringFactory.getImpl(RegistrationModule.class).getRegistrationNotificationEmail();
if (notiEmail != null) {
registrationManager.sendNewUserNotificationMessage(notiEmail, persistedIdentity);
}
// tell system that this user did accept the disclaimer
registrationManager.setHasConfirmedDislaimer(persistedIdentity);
return persistedIdentity;
}
}
use of org.olat.user.UserManager in project openolat by klemens.
the class RegistrationForm2 method initForm.
/**
* Initialize the form
*/
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("title.register");
// first the configured user properties
UserManager um = UserManager.getInstance();
userPropertyHandlers = um.getUserPropertyHandlersFor(USERPROPERTIES_FORM_IDENTIFIER, false);
Translator tr = Util.createPackageTranslator(UserPropertyHandler.class, getLocale(), getTranslator());
// Add all available user fields to this form
for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
if (userPropertyHandler == null)
continue;
FormItem fi = userPropertyHandler.addFormItem(getLocale(), null, USERPROPERTIES_FORM_IDENTIFIER, false, formLayout);
fi.setTranslator(tr);
propFormItems.put(userPropertyHandler.getName(), fi);
}
uifactory.addSpacerElement("lang", formLayout, true);
// second the user language
Map<String, String> languages = i18nManager.getEnabledLanguagesTranslated();
lang = uifactory.addDropdownSingleselect("user.language", formLayout, StringHelper.getMapKeysAsStringArray(languages), StringHelper.getMapValuesAsStringArray(languages), null);
lang.select(languageKey, true);
uifactory.addSpacerElement("loginstuff", formLayout, true);
if (usernameReadonly) {
usernameStatic = uifactory.addStaticTextElement("username", "user.login", proposedUsername, formLayout);
} else {
username = uifactory.addTextElement("username", "user.login", 128, "", formLayout);
username.setMandatory(true);
}
if (proposedUsername != null) {
setLogin(proposedUsername);
}
if (userInUse) {
setLoginErrorKey("form.check6");
}
newpass1 = uifactory.addPasswordElement("newpass1", "form.password.new1", 128, "", formLayout);
newpass1.setMandatory(true);
newpass1.setAutocomplete("new-password");
newpass2 = uifactory.addPasswordElement("newpass2", "form.password.new2", 128, "", formLayout);
newpass2.setMandatory(true);
newpass2.setAutocomplete("new-password");
// Button layout
buttonLayout = FormLayoutContainer.createButtonLayout("button_layout", getTranslator());
formLayout.add(buttonLayout);
uifactory.addFormSubmitButton("submit.speichernUndweiter", buttonLayout);
}
use of org.olat.user.UserManager in project openolat by klemens.
the class RegistrationWebService method register.
/**
* Register with the specified email
* @response.representation.200.doc Registration successful
* @response.representation.304.doc Already registered, HTTP-Header location set to redirect
* @response.representation.400.doc Email address not allowed
* @param email The email address
* @param request The HTTP Request
* @return
*/
@PUT
public Response register(@QueryParam("email") String email, @Context HttpServletRequest request) {
if (!CoreSpringFactory.getImpl(RegistrationModule.class).isSelfRegistrationEnabled()) {
return Response.serverError().status(Status.NOT_FOUND).build();
}
ResponseBuilder response;
Locale locale = getLocale(request);
Translator translator = getTranslator(locale);
MailManager mailM = CoreSpringFactory.getImpl(MailManager.class);
UserManager userManager = UserManager.getInstance();
RegistrationManager rm = CoreSpringFactory.getImpl(RegistrationManager.class);
boolean foundUser = userManager.findUniqueIdentityByEmail(email) != null;
boolean noNewUserWithEmail = !userManager.isEmailAllowed(email);
String serverpath = Settings.getServerContextPathURI();
if (foundUser && noNewUserWithEmail) {
// redirect
URI redirectUri = UriBuilder.fromUri(Settings.getServerContextPathURI()).build();
response = Response.ok().status(Status.NOT_MODIFIED).location(redirectUri);
} else if (userManager.isEmailAllowed(email)) {
String ip = request.getRemoteAddr();
TemporaryKey tk = null;
UserModule userModule = CoreSpringFactory.getImpl(UserModule.class);
if (userModule.isEmailUnique()) {
tk = rm.loadTemporaryKeyByEmail(email);
}
if (tk == null) {
tk = rm.loadOrCreateTemporaryKeyByEmail(email, ip, RegistrationManager.REGISTRATION);
}
String today = DateFormat.getDateInstance(DateFormat.LONG, locale).format(new Date());
String[] bodyAttrs = new String[] { serverpath, tk.getRegistrationKey(), CoreSpringFactory.getImpl(I18nModule.class).getLocaleKey(locale) };
String[] whereFromAttrs = new String[] { serverpath, today, ip };
String body = translator.translate("reg.body", bodyAttrs) + SEPARATOR + translator.translate("reg.wherefrom", whereFromAttrs);
try {
MailBundle bundle = new MailBundle();
bundle.setTo(email);
bundle.setContent(translator.translate("reg.subject"), body);
MailerResult result = mailM.sendExternMessage(bundle, null, true);
if (result.isSuccessful()) {
response = Response.ok();
} else {
response = Response.serverError().status(Status.INTERNAL_SERVER_ERROR);
}
} catch (Exception e) {
response = Response.serverError().status(Status.INTERNAL_SERVER_ERROR);
log.error("", e);
}
} else {
response = Response.serverError().status(Status.BAD_REQUEST);
}
return response.build();
}
use of org.olat.user.UserManager in project openolat by klemens.
the class IdentityDocument method createDocument.
/**
* Factory method to create a new IdentityDocument
* @param searchResourceContext
* @param wikiPage
* @return
*/
public static Document createDocument(SearchResourceContext searchResourceContext, Identity identity) {
UserManager userMgr = UserManager.getInstance();
User user = identity.getUser();
HomePageConfigManager homepageMgr = HomePageConfigManagerImpl.getInstance();
HomePageConfig publishConfig = homepageMgr.loadConfigFor(identity.getName());
IdentityDocument identityDocument = new IdentityDocument();
identityDocument.setTitle(identity.getName());
identityDocument.setCreatedDate(user.getCreationDate());
// loop through all user properties and collect the content string and the last modified
List<UserPropertyHandler> userPropertyHanders = userMgr.getUserPropertyHandlersFor(IdentityDocument.class.getName(), false);
StringBuilder content = new StringBuilder();
for (UserPropertyHandler userPropertyHandler : userPropertyHanders) {
String propertyName = userPropertyHandler.getName();
// only index fields the user has published!
if (publishConfig.isEnabled(propertyName)) {
String value = user.getProperty(propertyName, I18nModule.getDefaultLocale());
if (value != null) {
content.append(value).append(" ");
}
}
}
// user text
String text = publishConfig.getTextAboutMe();
if (StringHelper.containsNonWhitespace(text)) {
text = FilterFactory.getHtmlTagsFilter().filter(text);
content.append(text).append(' ');
}
// finally use the properties as the content for this identity
if (content.length() > 0) {
identityDocument.setContent(content.toString());
}
identityDocument.setResourceUrl(searchResourceContext.getResourceUrl());
identityDocument.setDocumentType(searchResourceContext.getParentContextType());
identityDocument.setCssIcon(CSSHelper.CSS_CLASS_USER);
if (log.isDebug())
log.debug(identityDocument.toString());
return identityDocument.getLuceneDocument();
}
use of org.olat.user.UserManager in project openolat by klemens.
the class DatePropertyHandler 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, final User user, String usageIdentifyer, boolean isAdministrativeUser, FormItemContainer formItemContainer) {
org.olat.core.gui.components.form.flexible.elements.DateChooser dateElem = null;
Date val = decode(getInternalValue(user));
dateElem = FormUIFactory.getInstance().addDateChooser(getName(), i18nFormElementLabelKey(), val, formItemContainer);
dateElem.setItemValidatorProvider(new ItemValidatorProvider() {
@Override
public boolean isValidValue(String value, ValidationError validationError, Locale llocale) {
return DatePropertyHandler.this.isValidValue(user, value, validationError, llocale);
}
});
UserManager um = UserManager.getInstance();
if (um.isUserViewReadOnly(usageIdentifyer, this) && !isAdministrativeUser) {
dateElem.setEnabled(false);
}
if (um.isMandatoryUserProperty(usageIdentifyer, this)) {
dateElem.setMandatory(true);
}
dateElem.setExampleKey("form.example.free", new String[] { Formatter.getInstance(locale).formatDate(new Date()) });
return dateElem;
}
Aggregations