use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class UserDataUtil method sendPasswordResetMail.
public static void sendPasswordResetMail(String email, Language language) throws InvalidArgumentException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
User user = dataAccessor.getUserByEmail(email.toLowerCase());
if (user == null)
throw new InvalidArgumentException(GenericRequest.ERR_EMAIL_NOT_REGISTERED);
String verificationToken = _getNextToken(user.getVerificationToken());
if (!verificationToken.equals(user.getVerificationToken())) {
user.setVerificationToken(verificationToken);
user = dataAccessor.createOrUpdateUser(user);
}
Map<String, String> dataModel = new HashMap<>();
String passwordResetUrl = "/" + "?" + "email=" + user.getEmail() + "&" + "token=" + verificationToken.substring(0, verificationToken.indexOf("|")) + "&" + "passwordReset=" + Boolean.TRUE;
dataModel.put("passwordResetUrl", passwordResetUrl);
EmailUtil.sendMail(createUserData(user).getDisplayName(), user.getEmail(), "password-reset", language, dataModel);
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class UserDataUtil method saveUserData.
public static UserData saveUserData(UserData userData) throws InvalidArgumentException, InsufficientAccessException {
_validateUserDataForSave(userData);
boolean isNew = userData.getId() == null;
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
User user = isNew ? dataAccessor.newUser() : dataAccessor.getUser(userData.getId());
if (isNew && !hasAccessToAddUserData(userData))
throw new InsufficientAccessException();
if (!isNew && !hasAccessToUpdateUserData(user, userData))
throw new InsufficientAccessException();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), isNew ? AccessType.USER_ADD : AccessType.USER_UPDATE, user);
if (userData.hasEmail() && !userData.getEmail().equals(user.getEmail())) {
user.setEmail(userData.getEmail());
if (user.getState() == UserState.ACTIVE)
user.setState(UserState.REGISTERED);
user.setVerificationToken(null);
}
if (userData.hasPhone())
user.setPhone(userData.getPhone());
if (userData.hasLanguage())
user.setLanguage(userData.getLanguage());
if (isNew) {
// Assuming only AEEs have USER_ADD access.
user.setState(UserState.REFERRAL);
user.setCampaign(UserCampaign.AEE_TEAM);
user.setReferrer(AccessTokenFilter.getAccessToken().getUserId().toString());
user.setSignUpDate(new Date());
user.setSignUpSource(getUserSignUpSource(false, false));
}
user.setLastUpdated(new Date());
user = dataAccessor.createOrUpdateUser(user, auditLog);
if (isNew) {
String firstName = userData.getFirstName();
String lastName = userData.getLastName();
userData = createUserData(user, null);
userData.setFirstName(firstName);
userData.setLastName(lastName);
} else {
userData = createUserData(user);
}
return userData;
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class UserPratilipiDataUtil method createUserPratilipiData.
private static UserPratilipiData createUserPratilipiData(UserPratilipiDoc userPratilipiDoc) {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
User user = dataAccessor.getUser(userPratilipiDoc.getUserId());
UserData userData = UserDataUtil.createUserData(user);
UserPratilipiData userPratilipiData = new UserPratilipiData();
userPratilipiData.setId(userPratilipiDoc.getId());
userPratilipiData.setUserId(userPratilipiDoc.getUserId());
userPratilipiData.setUser(userData);
userPratilipiData.setUserName(userData.getDisplayName());
userPratilipiData.setUserImageUrl(userData.getProfileImageUrl());
userPratilipiData.setUserProfilePageUrl(userData.getProfilePageUrl());
userPratilipiData.setRating(userPratilipiDoc.getRating());
userPratilipiData.setReview(processReview(userPratilipiDoc.getReviewTitle(), userPratilipiDoc.getReview()));
userPratilipiData.setReviewDate(userPratilipiDoc.getReviewDate());
userPratilipiData.setLikeCount(userPratilipiDoc.getLikeCount());
userPratilipiData.setCommentCount(userPratilipiDoc.getCommentCount());
userPratilipiData.setLiked(userPratilipiDoc.getLikedByUserIds().contains(AccessTokenFilter.getAccessToken().getUserId()));
return userPratilipiData;
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class UserPratilipiDataUtil method getUserLibrary.
public static DataListCursorTuple<PratilipiData> getUserLibrary(Long userId, String cursor, Integer offset, Integer resultCount) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
DataListCursorTuple<Long> pratilipiIdListCursorTuple = dataAccessor.getUserLibrary(userId, cursor, offset, resultCount);
return new DataListCursorTuple<PratilipiData>(PratilipiDataUtil.createPratilipiDataList(pratilipiIdListCursorTuple.getDataList(), true), pratilipiIdListCursorTuple.getCursor());
}
use of com.pratilipi.data.DataAccessor in project pratilipi by Pratilipi.
the class UserPratilipiDataUtil method saveUserPratilipiAddToLibrary.
public static UserPratilipiData saveUserPratilipiAddToLibrary(Long userId, Long pratilipiId, String lastOpenedPage, Boolean addedToLibrary) throws InsufficientAccessException, UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
UserPratilipi userPratilipi = dataAccessor.getUserPratilipi(userId, pratilipiId);
if (userPratilipi == null) {
userPratilipi = dataAccessor.newUserPratilipi();
userPratilipi.setUserId(userId);
userPratilipi.setPratilipiId(pratilipiId);
}
if (lastOpenedPage == null && addedToLibrary == null)
return createUserPratilipiData(userPratilipi);
if (!hasAccessToUpdateUserPratilipiData(userPratilipi, AccessType.USER_PRATILIPI_LIBRARY))
throw new InsufficientAccessException();
AuditLog auditLog = dataAccessor.newAuditLog(AccessTokenFilter.getAccessToken(), AccessType.USER_PRATILIPI_LIBRARY, userPratilipi);
if (lastOpenedPage != null) {
userPratilipi.setLastOpenedPage(lastOpenedPage);
userPratilipi.setLastOpenedDate(new Date());
}
if (addedToLibrary != null) {
userPratilipi.setAddedToLib(addedToLibrary);
userPratilipi.setAddedToLibDate(new Date());
}
userPratilipi = dataAccessor.createOrUpdateUserPratilipi(userPratilipi, auditLog);
return createUserPratilipiData(userPratilipi);
}
Aggregations