use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.
the class UserMapper method userFromId.
public User userFromId(Long id) {
if (id == null) {
return null;
}
User user = new User();
user.setId(id);
return user;
}
use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.
the class AccountResource method registerAccount.
/**
* POST /register : register the user.
*
* @param managedUserVM the managed user View Model
* @throws InvalidPasswordException 400 (Bad Request) if the password is incorrect
* @throws EmailAlreadyUsedException 400 (Bad Request) if the email is already used
* @throws LoginAlreadyUsedException 400 (Bad Request) if the login is already used
*/
@PostMapping("/register")
@Timed
@ResponseStatus(HttpStatus.CREATED)
public void registerAccount(@Valid @RequestBody ManagedUserVM managedUserVM) {
if (!checkPasswordLength(managedUserVM.getPassword())) {
throw new InvalidPasswordException();
}
userRepository.findOneByLogin(managedUserVM.getLogin().toLowerCase()).ifPresent(u -> {
throw new LoginAlreadyUsedException();
});
userRepository.findOneByEmailIgnoreCase(managedUserVM.getEmail()).ifPresent(u -> {
throw new EmailAlreadyUsedException();
});
User user = userService.registerUser(managedUserVM, managedUserVM.getPassword());
mailService.sendActivationEmail(user);
}
use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.
the class NotificationService method updates.
@Transactional()
public List<Notification> updates(List<Notification> notifications) {
User user = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin().get()).get();
// if there are a notification that does not belongs to the user and isn't admin... error
notifications.forEach(notification -> {
if (!notification.getUser().equals(user) && !SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN)) {
throw new BadRequestAlertException("This notification doesn't belongs to you :)", ENTITY_NOTIFICATION, ErrorConstants.ERR_BAD_USER);
}
});
return notificationRepository.save(notifications);
}
use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.
the class NotificationService method markAs.
@Transactional(readOnly = true)
public List<Notification> markAs(List<Notification> notifications, Boolean status) {
User user = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin().get()).get();
notifications.forEach(notification -> {
if (!notification.getUser().equals(user) && !SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN)) {
throw new BadRequestAlertException("This notification doesn't belongs to you :)", ENTITY_NOTIFICATION, ErrorConstants.ERR_BAD_USER);
} else {
notification.setRead(status);
}
});
return notificationRepository.save(notifications);
}
use of com.arnaugarcia.uplace.domain.User in project uplace.es by Uplace.
the class NotificationService method findOneByType.
/**
* Get one notification by id.
*
* @param id the id of the entity
* @return the entity
*/
@Transactional(readOnly = true)
public Notification findOneByType(NotificationType notificationType, Long id) {
log.debug("Request to get Notification : {}", id);
Notification notification = null;
switch(notificationType) {
case NOTIFICATION:
notification = notificationRepository.findOneByType(NotificationType.NOTIFICATION, id);
break;
case REQUEST:
notification = notificationRepository.findOneByType(NotificationType.REQUEST, id);
break;
case ALERT:
throw new BadRequestAlertException("Not yet implemented", ENTITY_REQUEST, ErrorConstants.NOT_IMPLEMENTED);
}
User user = userService.getUserWithAuthoritiesByLogin(SecurityUtils.getCurrentUserLogin().get()).get();
if (notification == null || !notification.getType().equals(NotificationType.NOTIFICATION)) {
throw new BadRequestAlertException("No notification was found with this ID", ENTITY_NOTIFICATION, ErrorConstants.ERR_BAD_ID);
}
// If the notification.user does not match and isn't admin... error
if (!notification.getUser().equals(user) && !SecurityUtils.isCurrentUserInRole(AuthoritiesConstants.ADMIN)) {
throw new BadRequestAlertException("This notification doesn't belongs to you :)", ENTITY_NOTIFICATION, ErrorConstants.ERR_BAD_USER);
}
return notification;
}
Aggregations