use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class ChangeEMailExecuteController method changeEMail.
/**
* change email
* @param wControl
* @return
*/
public boolean changeEMail(WindowControl wControl) {
XStream xml = XStreamHelper.createXStreamInstance();
@SuppressWarnings("unchecked") HashMap<String, String> mails = (HashMap<String, String>) xml.fromXML(tempKey.getEmailAddress());
Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(tempKey.getIdentityKey());
if (identity != null) {
String oldEmail = identity.getUser().getEmail();
identity.getUser().setProperty("email", mails.get("changedEMail"));
// if old mail address closed then set the new mail address
// unclosed
String value = identity.getUser().getProperty("emailDisabled", null);
if (value != null && value.equals("true")) {
identity.getUser().setProperty("emailDisabled", "false");
}
identity.getUser().setProperty("email", mails.get("changedEMail"));
// success info message
String currentEmailDisplay = UserManager.getInstance().getUserDisplayEmail(mails.get("currentEMail"), userRequest.getLocale());
String changedEmailDisplay = UserManager.getInstance().getUserDisplayEmail(mails.get("changedEMail"), userRequest.getLocale());
wControl.setInfo(pT.translate("success.change.email", new String[] { currentEmailDisplay, changedEmailDisplay }));
// remove keys
identity.getUser().setProperty("emchangeKey", null);
userRequest.getUserSession().removeEntryFromNonClearedStore(ChangeEMailController.CHANGE_EMAIL_ENTRY);
BaseSecurityManager.getInstance().deleteInvalidAuthenticationsByEmail(oldEmail);
} else {
// error message
wControl.setWarning(pT.translate("error.change.email.unexpected", new String[] { mails.get("currentEMail"), mails.get("changedEMail") }));
}
// delete registration key
rm.deleteTemporaryKeyWithId(tempKey.getRegistrationKey());
return true;
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class UsermanagerUserSearchForm 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)
*/
public void event(UserRequest ureq, Controller source, Event event) {
if (source == searchform) {
if (event == Event.DONE_EVENT) {
// form validation was ok
identitiesList = findIdentitiesFromSearchForm();
initUserListCtr(ureq, identitiesList, null);
userListVC.put("userlist", tableCtr.getInitialComponent());
userListVC.contextPut("emptyList", (identitiesList.size() == 0 ? Boolean.TRUE : Boolean.FALSE));
panel.setContent(userListVC);
// fxdiff BAKS-7 Resume function
ContextEntry currentEntry = getWindowControl().getBusinessControl().getCurrentContextEntry();
if (currentEntry != null) {
currentEntry.setTransientState(searchform.getStateEntry());
}
addToHistory(ureq, tableCtr);
} else if (event == Event.CANCELLED_EVENT) {
fireEvent(ureq, Event.CANCELLED_EVENT);
}
} else if (source == tableCtr) {
if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
TableEvent te = (TableEvent) event;
String actionid = te.getActionId();
if (actionid.equals(ExtendedIdentitiesTableDataModel.COMMAND_SELECTUSER)) {
int rowid = te.getRowId();
Identity foundIdentity = tdm.getObject(rowid);
// Tell parentController that a subject has been found
fireEvent(ureq, new SingleIdentityChosenEvent(foundIdentity));
} else if (actionid.equals(ExtendedIdentitiesTableDataModel.COMMAND_VCARD)) {
// get identity and open new visiting card controller in new window
int rowid = te.getRowId();
final Identity identity = tdm.getObject(rowid);
ControllerCreator userInfoMainControllerCreator = new ControllerCreator() {
@Override
public Controller createController(UserRequest lureq, WindowControl lwControl) {
return new UserInfoMainController(lureq, lwControl, identity, true, false);
}
};
// wrap the content controller into a full header layout
ControllerCreator layoutCtrlr = BaseFullWebappPopupLayoutFactory.createAuthMinimalPopupLayout(ureq, userInfoMainControllerCreator);
// open in new browser window
PopupBrowserWindow pbw = getWindowControl().getWindowBackOffice().getWindowManager().createNewPopupBrowserWindowFor(ureq, layoutCtrlr);
pbw.open(ureq);
}
}
if (event instanceof TableMultiSelectEvent) {
// Multiselect events
TableMultiSelectEvent tmse = (TableMultiSelectEvent) event;
if (tmse.getAction().equals(CMD_BULKEDIT)) {
if (tmse.getSelection().isEmpty()) {
// empty selection
showWarning("msg.selectionempty");
return;
}
selectedIdentities = tdm.getIdentities(tmse.getSelection());
// valid selection: load in wizard
Step start = new UserBulkChangeStep00(ureq, selectedIdentities);
// callback executed in case wizard is finished.
StepRunnerCallback finish = new StepRunnerCallback() {
public Step execute(UserRequest ureq1, WindowControl wControl1, StepsRunContext runContext) {
// all information to do now is within the runContext saved
boolean hasChanges = false;
try {
if (runContext.containsKey("validChange") && ((Boolean) runContext.get("validChange")).booleanValue()) {
HashMap<String, String> attributeChangeMap = (HashMap<String, String>) runContext.get("attributeChangeMap");
HashMap<String, String> roleChangeMap = (HashMap<String, String>) runContext.get("roleChangeMap");
List<Long> ownGroups = (List<Long>) runContext.get("ownerGroups");
List<Long> partGroups = (List<Long>) runContext.get("partGroups");
// List<Long> mailGroups = (List<Long>) runContext.get("mailGroups");
if (attributeChangeMap.size() != 0 || roleChangeMap.size() != 0 || ownGroups.size() != 0 || partGroups.size() != 0) {
Identity addingIdentity = ureq1.getIdentity();
ubcMan.changeSelectedIdentities(selectedIdentities, attributeChangeMap, roleChangeMap, notUpdatedIdentities, isAdministrativeUser, ownGroups, partGroups, getTranslator(), addingIdentity);
hasChanges = true;
}
}
} catch (Exception any) {
// return new ErrorStep
}
// signal correct completion and tell if changes were made or not.
return hasChanges ? StepsMainRunController.DONE_MODIFIED : StepsMainRunController.DONE_UNCHANGED;
}
};
removeAsListenerAndDispose(userBulkChangeStepsController);
userBulkChangeStepsController = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("bulkChange.title"), "o_sel_user_bulk_change_wizard");
listenTo(userBulkChangeStepsController);
getWindowControl().pushAsModalDialog(userBulkChangeStepsController.getInitialComponent());
} else if (tmse.getAction().equals(CMD_MAIL)) {
if (tmse.getSelection().isEmpty()) {
// empty selection
showWarning("msg.selectionempty");
return;
}
// create e-mail message
ContactMessage cmsg = new ContactMessage(ureq.getIdentity());
selectedIdentities = tdm.getIdentities(tmse.getSelection());
ContactList contacts = new ContactList(translate("mailto.userlist"));
contacts.addAllIdentites(selectedIdentities);
cmsg.addEmailTo(contacts);
// create contact form controller with ContactMessage
removeAsListenerAndDispose(contactCtr);
contactCtr = new ContactFormController(ureq, getWindowControl(), true, false, false, cmsg);
listenTo(contactCtr);
mailVC.put("mailform", contactCtr.getInitialComponent());
panel.setContent(mailVC);
}
}
} else if (source == contactCtr) {
// in any case go back to list (events: done, failed or cancel)
panel.setContent(userListVC);
} else if (source == userBulkChangeStepsController) {
if (event == Event.CANCELLED_EVENT) {
getWindowControl().pop();
} else if (event == Event.CHANGED_EVENT) {
getWindowControl().pop();
Integer selIdentCount = selectedIdentities.size();
if (notUpdatedIdentities.size() > 0) {
Integer notUpdatedIdentCount = notUpdatedIdentities.size();
Integer sucChanges = selIdentCount - notUpdatedIdentCount;
String changeErrors = "";
for (String err : notUpdatedIdentities) {
changeErrors += err + "<br />";
}
getWindowControl().setError(translate("bulkChange.partialsuccess", new String[] { sucChanges.toString(), selIdentCount.toString(), changeErrors }));
} else {
showInfo("bulkChange.success");
}
// update table model - has changed
reloadDataModel(ureq);
} else if (event == Event.DONE_EVENT) {
showError("bulkChange.failed");
}
}
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class UserBulkChangePasswordController method event.
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (event == Event.DONE_EVENT) {
String[] usernames = changePasswordForm.getUsernames();
String password = changePasswordForm.getPassword();
boolean autodisc = changePasswordForm.getDisclaimerAccept();
boolean langGerman = changePasswordForm.getLangGerman();
BaseSecurity identityManager = BaseSecurityManager.getInstance();
int c = 0;
for (String username : usernames) {
if (username.length() == 0)
continue;
try {
Identity identity = identityManager.findIdentityByName(username);
if (identity != null) {
if (password != null && password.trim().length() > 0) {
olatAuthenticationSpi.changePassword(ureq.getIdentity(), identity, password);
log.info("changePassword for username: " + username);
}
if (autodisc) {
registrationManager.setHasConfirmedDislaimer(identity);
log.info("Disclaimer accepted for username: " + username);
}
if (langGerman) {
identity.getUser().getPreferences().setLanguage("de");
UserManager.getInstance().updateUserFromIdentity(identity);
log.info("Set language German for username: " + username);
}
c++;
} else {
log.warn("could find user with username: " + username);
}
} catch (Exception e) {
log.error("Failed to change password/settings for username: " + username, e);
}
}
// notify done
getWindowControl().setInfo(translate("bulk.psw.done", "" + c));
// TODO: clear the form
// changePasswordForm.clearForm(); //???
}
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class CourseOverviewController method removeUserFromCourse.
private void removeUserFromCourse(UserRequest ureq, List<RepositoryEntry> repoEntriesToLeave, List<BusinessGroup> groupsToLeave, List<BusinessGroup> groupsToDelete, boolean doSendMail) {
List<Identity> membersToRemove = Collections.singletonList(editedIdentity);
for (BusinessGroup group : groupsToLeave) {
if (groupsToDelete.contains(group)) {
// really delete the group as it has no more owners/participants
if (doSendMail) {
String businessPath = getWindowControl().getBusinessControl().getAsString();
businessGroupService.deleteBusinessGroupWithMail(group, businessPath, getIdentity(), getLocale());
} else {
businessGroupService.deleteBusinessGroup(group);
}
} else {
// 1) remove as owner
if (businessGroupService.hasRoles(editedIdentity, group, GroupRoles.coach.name())) {
businessGroupService.removeOwners(ureq.getIdentity(), membersToRemove, group);
}
MailPackage mailing = new MailPackage(doSendMail);
// 2) remove as participant
businessGroupService.removeParticipants(getIdentity(), membersToRemove, group, mailing);
MailHelper.printErrorsAndWarnings(mailing.getResult(), getWindowControl(), ureq.getUserSession().getRoles().isOLATAdmin(), getLocale());
}
}
for (RepositoryEntry repoEntry : repoEntriesToLeave) {
if (isRepoMember(repoEntry)) {
MailPackage mailing = new MailPackage(doSendMail);
repositoryManager.removeMembers(getIdentity(), membersToRemove, repoEntry, mailing);
}
}
updateModel();
StringBuilder groupNames = new StringBuilder();
for (BusinessGroup group : groupsToLeave) {
if (groupNames.length() > 0)
groupNames.append(", ");
groupNames.append(group.getName());
}
showInfo("unsubscribe.successful");
}
use of org.olat.core.id.Identity in project OpenOLAT by OpenOLAT.
the class StatusController 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)
*/
public void event(UserRequest ureq, Controller source, Event event) {
if (source == tableCtr) {
if (event.getCommand().equals(Table.COMMANDLINK_ROWACTION_CLICKED)) {
TableEvent te = (TableEvent) event;
if (te.getActionId().equals(ACTION_SINGLESELECT_CHOOSE)) {
int rowid = te.getRowId();
Identity foundIdentity = tdm.getObject(rowid);
UserDeletionManager.getInstance().setIdentityAsActiv(foundIdentity);
updateUserList();
}
}
}
}
Aggregations