use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class UserManagementController method displayDeleteUserConfirmation.
/**
* @param request
* @param response
* @param model
* @return The pages audit set-up form page
*/
@RequestMapping(value = TgolKeyStore.DELETE_USER_URL, method = RequestMethod.POST)
@Secured(TgolKeyStore.ROLE_ADMIN_KEY)
public String displayDeleteUserConfirmation(HttpServletRequest request, HttpServletResponse response, Model model) {
Object userId = request.getSession().getAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY);
Long lUserId;
if (userId instanceof Long) {
lUserId = (Long) userId;
} else {
try {
lUserId = Long.valueOf(userId.toString());
} catch (NumberFormatException nfe) {
throw new ForbiddenUserException();
}
}
User user = getCurrentUser();
User userToDelete = userDataService.read(lUserId);
if (userToDelete == null || user.getId().equals(userToDelete.getId())) {
return TgolKeyStore.ACCESS_DENIED_VIEW_NAME;
}
for (Contract contract : userToDelete.getContractSet()) {
deleteAllAuditsFromContract(contract);
}
userDataService.delete(userToDelete.getId());
request.getSession().removeAttribute(TgolKeyStore.USER_ID_TO_DELETE_KEY);
request.getSession().setAttribute(TgolKeyStore.DELETED_USER_NAME_KEY, userToDelete.getEmail1());
return TgolKeyStore.ADMIN_VIEW_REDIRECT_NAME;
}
use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class HomeController method displayHomePage.
@RequestMapping(value = TgolKeyStore.HOME_URL, method = RequestMethod.GET)
@Secured({ TgolKeyStore.ROLE_USER_KEY, TgolKeyStore.ROLE_ADMIN_KEY })
public String displayHomePage(Model model) {
User user = getCurrentUser();
model.addAttribute(TgolKeyStore.CONTRACT_LIST_KEY, contractSortCommandHelper.prepareContractInfo(user, null, displayOptionFieldsBuilderList, model));
return TgolKeyStore.HOME_VIEW_NAME;
}
use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class UserDAO method isAccountActivated.
public boolean isAccountActivated(String email) {
Query query = entityManager.createQuery("SELECT u FROM " + getEntityClass().getName() + " u" + " WHERE u.email = :email");
query.setParameter("email", email);
try {
return ((User) query.getSingleResult()).isAccountActivated();
} catch (NoResultException e) {
return false;
}
}
use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class UserManagementControllerTest method testSubmitAddUserForm.
/**
* Test of submitAddUserForm method, of class UserManagementController.
*/
@Test
public void testSubmitAddUserForm() throws Exception {
setUpMockRoleDataService();
setUpMockUserDataService(true, false, false);
setUpMockAuthenticationContext();
// Finally the form is conform and the admin page is returned
CreateUserCommand createUserCommand = createUserCommandFactory.getNewCreateUserCommand();
createUserCommand.setSiteUrl("http://www.newSite.com/");
createUserCommand.setEmail("newUser@test.com");
createUserCommand.setPassword("P4sSw0rD");
createUserCommand.setConfirmPassword("P4sSw0rD");
BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
Model model = new ExtendedModelMap();
String result = instance.submitAddUserForm(createUserCommand, bindingResult, model);
assertEquals(ADMIN_VIEW_NAME, result);
assertFalse(bindingResult.hasErrors());
assertTrue(bindingResult.getFieldErrors().isEmpty());
assertEquals(2, model.asMap().size());
assertEquals("newUser@test.com", model.asMap().get(ADDED_USER_NAME_KEY));
assertTrue(((List<User>) model.asMap().get(TgolKeyStore.USER_LIST_KEY)).isEmpty());
}
use of org.asqatasun.entity.user.User in project Asqatasun by Asqatasun.
the class UserManagementControllerTest method testSubmitEditCurrentUserForm.
/**
* Test of submitEditUserForm method, of class UserManagementController.
*/
@Test
public void testSubmitEditCurrentUserForm() throws Exception {
setUpMockRoleDataService();
setUpMockUserDataService(false, false, true);
setUpMockAuthenticationContext();
// Finally the form is conform and the admin page is returned
CreateUserCommand createUserCommand = createUserCommandFactory.getNewCreateUserCommand();
createUserCommand.setEmail("admin@test.com");
createUserCommand.setLastName("newName");
createUserCommand.setFirstName("newFirstName");
createUserCommand.setPhoneNumber("0102030405");
createUserCommand.setActivated(false);
createUserCommand.setAdmin(false);
MockHttpServletRequest request = new MockHttpServletRequest();
request.getSession().setAttribute(TgolKeyStore.USER_ID_KEY, 4L);
BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand, "createUserCommand");
Model model = new ExtendedModelMap();
String result = instance.submitEditUserForm(createUserCommand, bindingResult, request, model);
assertEquals(TgolKeyStore.ADMIN_VIEW_NAME, result);
assertFalse(bindingResult.hasErrors());
assertTrue(bindingResult.getFieldErrors().isEmpty());
assertEquals(2, model.asMap().size());
assertEquals("admin@test.com", model.asMap().get(TgolKeyStore.UPDATED_USER_NAME_KEY));
assertTrue(((List<User>) model.asMap().get(TgolKeyStore.USER_LIST_KEY)).isEmpty());
}
Aggregations