use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class AccountSettingsController method displayAccountSettingsPage.
/**
* This method displays the form for an authenticated user
*
* @param model
* @return
*/
@RequestMapping(value = TgolKeyStore.ACCOUNT_SETTINGS_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displayAccountSettingsPage(Model model) {
User user = getCurrentUser();
if (this.forbiddenUserList.contains(user.getEmail1())) {
throw new ForbiddenPageException();
}
secondaryLevelMenuDisplayer.setModifiableReferentialsForUserToModel(user, model);
return prepateDataAndReturnCreateUserView(model, user, TgolKeyStore.ACCOUNT_SETTINGS_VIEW_NAME);
}
use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class UserManagementController method displayDeleteUserPage.
/**
* @param userId
* @param request
* @param response
* @param model
* @return The pages audit set-up form page
*/
@RequestMapping(value = TgolKeyStore.DELETE_USER_URL, method = RequestMethod.GET)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String displayDeleteUserPage(@RequestParam(TgolKeyStore.USER_ID_KEY) String userId, HttpServletRequest request, HttpServletResponse response, Model model) {
Long lUserId;
try {
lUserId = Long.valueOf(userId);
} catch (NumberFormatException nfe) {
throw new ForbiddenUserException();
}
User userToDelete = userDataService.read(lUserId);
if (userToDelete == null || getCurrentUser().getId().equals(userToDelete.getId())) {
return TgolKeyStore.ACCESS_DENIED_VIEW_NAME;
}
model.addAttribute(TgolKeyStore.USER_NAME_TO_DELETE_KEY, userToDelete.getEmail1());
request.getSession().setAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY, userToDelete.getId());
return TgolKeyStore.DELETE_USER_VIEW_NAME;
}
use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class UserManagementController method submitCreateUserForm.
/**
* A new user can be created from the main form that can be accessed without
* being authentified. In this case, we check the validity of the filled-in
* url and we prevent the new users to be activated and created with admin
* privileges.
* On the other side, if the user is created from the admin interface, it can
* be set with activation and admin privileges info but the check of the url
* is useless cause the field has been removed from the form.
*
* @param createUserCommand
* @param result
* @param model
* @param successViewName
* @param errorViewName
* @param successMessageKey
* @return
* @throws Exception
*/
private String submitCreateUserForm(CreateUserCommand createUserCommand, BindingResult result, Model model, String successViewName, String errorViewName, String successMessageKey) throws Exception {
// We check whether the form is valid
createUserFormValidator.validate(createUserCommand, result);
// If the form has some errors, we display it again with errors' details
if (result.hasErrors()) {
return displayFormWithErrors(model, createUserCommand, errorViewName);
}
User user = createUser(createUserCommand, true, true);
model.addAttribute(TgolKeyStore.USER_LIST_KEY, userDataService.findAll());
model.addAttribute(successMessageKey, user.getEmail1());
return successViewName;
}
use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class UserManagementController method displayDeleteUserAuditsPage.
/**
* @param userId
* @param request
* @param response
* @param model
* @return
*/
@RequestMapping(value = TgolKeyStore.DELETE_USER_AUDITS_URL, method = RequestMethod.GET)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String displayDeleteUserAuditsPage(@RequestParam(TgolKeyStore.USER_ID_KEY) String userId, HttpServletRequest request, HttpServletResponse response, Model model) {
Long lUserId;
try {
lUserId = Long.valueOf(userId);
} catch (NumberFormatException nfe) {
throw new ForbiddenUserException();
}
User userToDelete = userDataService.read(lUserId);
model.addAttribute(TgolKeyStore.USER_NAME_TO_DELETE_KEY, userToDelete.getEmail1());
request.getSession().setAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY, userToDelete.getId());
return TgolKeyStore.DELETE_AUDITS_VIEW_NAME;
}
use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class UserManagementController method createUser.
/**
* Create a user entit
* @param createUserCommand
* @return
* @throws Exception
*/
private User createUser(CreateUserCommand createUserCommand, boolean allowActivation, boolean allowAdmin) throws Exception {
User user = userDataService.create();
user.setEmail1(createUserCommand.getEmail());
user.setFirstName(createUserCommand.getFirstName());
user.setName(createUserCommand.getLastName());
user.setPhoneNumber(createUserCommand.getPhoneNumber());
user.setPassword(MD5Encoder.MD5(createUserCommand.getPassword()));
user.setWebUrl1(createUserCommand.getSiteUrl());
if (allowActivation) {
user.setAccountActivation(createUserCommand.getActivated());
} else {
user.setAccountActivation(false);
}
if (allowAdmin && createUserCommand.getAdmin()) {
user.setRole(createUserCommandFactory.getAdminRole());
} else {
user.setRole(createUserCommandFactory.getUserRole());
}
userDataService.saveOrUpdate(user);
return user;
}
Aggregations