use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.
the class UserVOFactory method post.
public static void post(User dbUser, UserVO user, Locale locale) {
UserManager um = UserManager.getInstance();
List<UserPropertyHandler> propertyHandlers = um.getUserPropertyHandlersFor(UserWebService.PROPERTY_HANDLER_IDENTIFIER, false);
dbUser.setProperty(UserConstants.FIRSTNAME, user.getFirstName());
dbUser.setProperty(UserConstants.LASTNAME, user.getLastName());
dbUser.setProperty(UserConstants.EMAIL, user.getEmail());
for (UserPropertyVO entry : user.getProperties()) {
for (UserPropertyHandler propertyHandler : propertyHandlers) {
if (entry.getName().equals(propertyHandler.getName())) {
String value = parseUserProperty(entry.getValue(), propertyHandler, locale);
String parsedValue;
if (propertyHandler instanceof DatePropertyHandler) {
parsedValue = formatDbDate(value, locale);
} else if (propertyHandler instanceof GenderPropertyHandler) {
parsedValue = parseGender(value, (GenderPropertyHandler) propertyHandler, locale);
} else {
parsedValue = propertyHandler.getStringValue(value, locale);
}
dbUser.setProperty(entry.getName(), parsedValue);
break;
}
}
}
}
use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.
the class UserVOFactory method get.
public static UserVO get(Identity identity, Locale locale, boolean allProperties, boolean isAdmin, boolean withPortrait) {
if (locale == null) {
locale = I18nModule.getDefaultLocale();
}
UserVO userVO = new UserVO();
User user = identity.getUser();
userVO.setKey(identity.getKey());
if (identity != null) {
userVO.setLogin(identity.getName());
}
userVO.setExternalId(identity.getExternalId());
userVO.setFirstName(user.getProperty(UserConstants.FIRSTNAME, null));
userVO.setLastName(user.getProperty(UserConstants.LASTNAME, null));
userVO.setEmail(user.getProperty(UserConstants.EMAIL, null));
if (withPortrait) {
File portrait = DisplayPortraitManager.getInstance().getSmallPortrait(identity.getName());
if (portrait != null && portrait.exists()) {
try {
InputStream input = new FileInputStream(portrait);
byte[] datas = IOUtils.toByteArray(input);
FileUtils.closeSafely(input);
byte[] data64 = Base64.encodeBase64(datas);
userVO.setPortrait(new String(data64, "UTF8"));
} catch (IOException e) {
log.error("", e);
}
}
}
if (allProperties) {
UserManager um = UserManager.getInstance();
HomePageConfig hpc = isAdmin ? null : HomePageConfigManagerImpl.getInstance().loadConfigFor(identity.getName());
List<UserPropertyHandler> propertyHandlers = um.getUserPropertyHandlersFor(UserWebService.PROPERTY_HANDLER_IDENTIFIER, false);
for (UserPropertyHandler propertyHandler : propertyHandlers) {
String propName = propertyHandler.getName();
if (hpc != null && !hpc.isEnabled(propName)) {
continue;
}
if (!UserConstants.FIRSTNAME.equals(propName) && !UserConstants.LASTNAME.equals(propName) && !UserConstants.EMAIL.equals(propName)) {
String value = propertyHandler.getUserProperty(user, locale);
userVO.putProperty(propName, value);
}
}
}
return userVO;
}
use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.
the class GroupController method init.
protected void init(UserRequest ureq, boolean mayModifyMembers, boolean keepAtLeastOne, boolean enableTablePreferences, boolean enableUserSelection, boolean allowDownload, boolean mandatoryEmail, SecurityGroup aSecurityGroup) {
this.securityGroup = aSecurityGroup;
this.mayModifyMembers = mayModifyMembers;
this.keepAtLeastOne = keepAtLeastOne;
this.mandatoryEmail = mandatoryEmail;
securityManager = BaseSecurityManager.getInstance();
imModule = CoreSpringFactory.getImpl(InstantMessagingModule.class);
imService = CoreSpringFactory.getImpl(InstantMessagingService.class);
userManager = CoreSpringFactory.getImpl(UserManager.class);
sessionManager = CoreSpringFactory.getImpl(UserSessionManager.class);
mailManager = CoreSpringFactory.getImpl(MailManager.class);
Roles roles = ureq.getUserSession().getRoles();
BaseSecurityModule securityModule = CoreSpringFactory.getImpl(BaseSecurityModule.class);
isAdministrativeUser = securityModule.isUserAllowedAdminProps(roles);
chatEnabled = imModule.isEnabled() && imModule.isPrivateEnabled();
// default group controller has no mail functionality
this.addUserMailDefaultTempl = null;
this.removeUserMailDefaultTempl = null;
groupmemberview = createVelocityContainer("index");
addUsersButton = LinkFactory.createButtonSmall("overview.addusers", groupmemberview, this);
addUsersButton.setElementCssClass("o_sel_group_import_users");
addUserButton = LinkFactory.createButtonSmall("overview.adduser", groupmemberview, this);
addUserButton.setElementCssClass("o_sel_group_add_user");
if (mayModifyMembers) {
groupmemberview.contextPut("mayadduser", Boolean.TRUE);
}
TableGuiConfiguration tableConfig = new TableGuiConfiguration();
tableConfig.setDownloadOffered(allowDownload);
if (enableTablePreferences) {
// save table preferences for each group seperatly
if (mayModifyMembers) {
tableConfig.setPreferencesOffered(true, "groupcontroller" + securityGroup.getKey());
} else {
// different rowcount...
tableConfig.setPreferencesOffered(true, "groupcontrollerreadonly" + securityGroup.getKey());
}
}
myTrans = userManager.getPropertyHandlerTranslator(getTranslator());
tableCtr = new TableController(tableConfig, ureq, getWindowControl(), myTrans);
listenTo(tableCtr);
initGroupTable(tableCtr, ureq, enableTablePreferences, enableUserSelection);
// set data model
reloadData();
groupmemberview.put("subjecttable", tableCtr.getInitialComponent());
putInitialPanel(groupmemberview);
}
use of org.olat.user.UserManager in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class ExtendedIdentitiesTableDataModel method addColumnDescriptors.
/**
* Add all column descriptors to this table that are available in the table
* model
*
* @param tableCtr
*/
public void addColumnDescriptors(TableController tableCtr, Translator trans) {
setLocale(trans.getLocale());
if (isAdministrativeUser) {
String action = actionEnabled ? COMMAND_SELECTUSER : null;
tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("table.identity.name", colCount++, action, getLocale()));
}
UserManager um = UserManager.getInstance();
// followed by the users fields
for (int i = 0; i < userPropertyHandlers.size(); i++) {
UserPropertyHandler userPropertyHandler = userPropertyHandlers.get(i);
boolean visible = um.isMandatoryUserProperty(usageIdentifyer, userPropertyHandler);
String action = null;
if (actionEnabled && i < 2) {
action = COMMAND_SELECTUSER;
}
tableCtr.addColumnDescriptor(visible, userPropertyHandler.getColumnDescriptor(colCount++, action, getLocale()));
}
// in the end the last login and creation date
tableCtr.addColumnDescriptor(false, new DefaultColumnDescriptor("table.identity.lastlogin", colCount++, null, getLocale()));
// creation date at the end, enabled by default
tableCtr.addColumnDescriptor(new DefaultColumnDescriptor("table.identity.creationdate", colCount++, null, getLocale()));
if (actionEnabled) {
StaticColumnDescriptor vcd = new StaticColumnDescriptor(COMMAND_VCARD, "table.header.vcard", trans.translate("table.identity.vcard"));
vcd.setIsPopUpWindowAction(true, "height=700, width=900, location=no, menubar=no, resizable=yes, status=no, scrollbars=yes, toolbar=no");
tableCtr.addColumnDescriptor(vcd);
}
}
Aggregations