use of com.salesmanager.core.model.user.User in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method listByCriteria.
@Override
public ReadableUserList listByCriteria(UserCriteria criteria, int page, int count, Language language) {
try {
ReadableUserList readableUserList = new ReadableUserList();
// filtering by userName is not in this implementation
Page<User> userList = null;
Optional<String> storeCode = Optional.ofNullable(criteria.getStoreCode());
if (storeCode.isPresent()) {
// get store
MerchantStore store = merchantStoreService.getByCode(storeCode.get());
if (store != null && (store.isRetailer() != null)) {
if (store.isRetailer().booleanValue()) {
// get group stores
List<MerchantStore> stores = merchantStoreService.findAllStoreNames(store.getCode());
List<Integer> intList = stores.stream().map(s -> s.getId()).collect(Collectors.toList());
criteria.setStoreIds(intList);
// search over store list
criteria.setStoreCode(null);
}
}
}
userList = userService.listByCriteria(criteria, page, count);
List<ReadableUser> readableUsers = new ArrayList<ReadableUser>();
if (userList != null) {
readableUsers = userList.getContent().stream().map(user -> convertUserToReadableUser(language, user)).collect(Collectors.toList());
readableUserList.setRecordsTotal(userList.getTotalElements());
readableUserList.setTotalPages(userList.getTotalPages());
readableUserList.setNumber(userList.getSize());
readableUserList.setRecordsFiltered(userList.getSize());
}
readableUserList.setData(readableUsers);
return readableUserList;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Cannot get users by criteria user", e);
}
}
use of com.salesmanager.core.model.user.User in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method requestPasswordReset.
@Override
public void requestPasswordReset(String userName, String userContextPath, MerchantStore store, Language language) {
Validate.notNull(userName, "Username cannot be empty");
Validate.notNull(userContextPath, "Return url cannot be empty");
try {
// get user by user name
User user = userService.getByUserName(userName, store.getCode());
if (user == null) {
throw new ResourceNotFoundException("User [" + userName + "] not found for store [" + store.getCode() + "]");
}
// generates unique token
String token = UUID.randomUUID().toString();
Date expiry = DateUtil.addDaysToCurrentDate(2);
CredentialsReset credsRequest = new CredentialsReset();
credsRequest.setCredentialsRequest(token);
credsRequest.setCredentialsRequestExpiry(expiry);
user.setCredentialsResetRequest(credsRequest);
userService.saveOrUpdate(user);
// reset password link
// this will build http | https ://domain/contextPath
String baseUrl = userContextPath;
if (!filePathUtils.isValidURL(baseUrl)) {
throw new ServiceRuntimeException("Request url [" + baseUrl + "] is invalid");
}
// need to add link to controller receiving user reset password
// request
String customerResetLink = new StringBuilder().append(baseUrl).append(Constants.SLASH).append(String.format(resetUserLink, store.getCode(), token)).toString();
resetPasswordRequest(user, customerResetLink, store, lamguageService.toLocale(language, store));
} catch (Exception e) {
throw new ServiceRuntimeException("Error while executing resetPassword request", e);
}
}
use of com.salesmanager.core.model.user.User in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method getByCriteria.
@Override
public ReadableUserList getByCriteria(Language language, String drawParam, Criteria criteria) {
try {
ReadableUserList readableUserList = new ReadableUserList();
GenericEntityList<User> userList = userService.listByCriteria(criteria);
for (User user : userList.getList()) {
ReadableUser readableUser = this.convertUserToReadableUser(language, user);
readableUserList.getData().add(readableUser);
}
readableUserList.setRecordsTotal(userList.getTotalCount());
readableUserList.setNumber(userList.getList().size());
readableUserList.setTotalPages(userList.getTotalPages());
// readableUserList.setTotalPages(readableUserList.getData().size());
readableUserList.setRecordsFiltered(Math.toIntExact(userList.getTotalCount()));
return readableUserList;
} catch (ServiceException e) {
throw new ServiceRuntimeException("Cannot get users by criteria user", e);
}
}
use of com.salesmanager.core.model.user.User in project shopizer by shopizer-ecommerce.
the class AbstractAuthenticatinSuccessHandler method onAuthenticationSuccess.
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
// last access timestamp
String userName = authentication.getName();
/**
* Spring Security 4 does not seem to add security context in the session
* creating the authentication to be lost during the login
*/
SecurityContext securityContext = SecurityContextHolder.getContext();
HttpSession session = request.getSession(true);
session.setAttribute("SPRING_SECURITY_CONTEXT", securityContext);
try {
User user = userService.getByUserName(userName);
Date lastAccess = user.getLoginTime();
if (lastAccess == null) {
lastAccess = new Date();
}
user.setLastAccess(lastAccess);
user.setLoginTime(new Date());
userService.saveOrUpdate(user);
redirectAfterSuccess(request, response);
} catch (Exception e) {
LOGGER.error("User authenticationSuccess", e);
}
}
use of com.salesmanager.core.model.user.User in project shopizer by shopizer-ecommerce.
the class UserServiceImpl method listByCriteria.
@Override
public Page<User> listByCriteria(UserCriteria criteria, int page, int count) throws ServiceException {
Pageable pageRequest = PageRequest.of(page, count);
Page<User> users = null;
if (criteria.getStoreIds() != null) {
// search within a predefined list
// of stores
users = pageableUserRepository.listByStoreIds(criteria.getStoreIds(), criteria.getAdminEmail(), pageRequest);
} else if (StringUtils.isBlank(criteria.getStoreCode())) {
// search for
// a
// specific
// store
users = pageableUserRepository.listAll(criteria.getAdminEmail(), pageRequest);
} else if (criteria.getStoreCode() != null) {
// store code
users = pageableUserRepository.listByStore(criteria.getStoreCode(), criteria.getAdminEmail(), pageRequest);
}
return users;
}
Aggregations