use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class UserDataUtil method createUserData.
public static UserData createUserData(User user, Author author) {
if (user == null)
return null;
UserData userData = new UserData(user.getId());
userData.setFacebookId(user.getFacebookId());
userData.setPassword(user.getPassword() != null);
userData.setEmail(user.getEmail());
userData.setPhone(user.getPhone());
userData.setLanguage(user.getLanguage());
userData.setState(user.getState());
userData.setSignUpDate(user.getSignUpDate());
userData.setFollowCount(user.getFollowCount());
userData.setFirebaseToken(FirebaseApi.getCustomTokenForUser(userData.getId()));
if (author != null) {
AuthorData authorData = AuthorDataUtil.createAuthorData(author);
userData.setAuthor(authorData);
if (userData.getLanguage() == null)
userData.setLanguage(author.getLanguage());
userData.setFirstName(authorData.getFirstName() != null ? authorData.getFirstName() : authorData.getFirstNameEn());
userData.setLastName(authorData.getLastName() != null ? authorData.getLastName() : authorData.getLastNameEn());
userData.setDisplayName(userData.getFirstName() != null ? userData.getFirstName() : userData.getLastName());
userData.setGender(authorData.getGender());
userData.setDateOfBirth(authorData.getDateOfBirth());
userData.setProfilePageUrl(authorData.getPageUrl());
userData.setProfileImageUrl(authorData.getImageUrl());
}
return userData;
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class UserLoginGoogleApi method post.
@Post
public UserV1Api.Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
UserData userData = UserDataUtil.loginGoogleUser(request.googleIdToken, UserDataUtil.getUserSignUpSource(false, true));
if (new Date().getTime() - userData.getSignUpDate().getTime() <= 60000) {
Long authorId = AuthorDataUtil.createAuthorProfile(userData, request.language == null ? UxModeFilter.getFilterLanguage() : request.language);
// Fetching updated UserData
userData = UserDataUtil.getCurrentUser();
/*
// Send welcome mail to the user
Task welcomeMailTask = TaskQueueFactory.newTask()
.setUrl( "/user/email" )
.addParam( "userId", userData.getId().toString() )
.addParam( "language", ( request.language == null ? ( UxModeFilter.getDisplayLanguage() == null ? Language.ENGLISH : UxModeFilter.getDisplayLanguage() ) : request.language ).toString() )
.addParam( "sendWelcomeMail", "true" );
TaskQueueFactory.getUserTaskQueue().add( welcomeMailTask );
// Process Author data
Task task = TaskQueueFactory.newTask()
.setUrl( "/author/process" )
.addParam( "authorId", authorId.toString() )
.addParam( "processData", "true" );
TaskQueueFactory.getAuthorTaskQueue().add( task );
*/
}
return new UserV1Api.Response(userData, UserLoginGoogleApi.class);
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class UserRegisterApi method post.
@Post
public UserV1Api.Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
String firstName = request.name.trim();
String lastName = null;
String email = request.email.trim().toLowerCase();
if (firstName.lastIndexOf(' ') != -1) {
lastName = firstName.substring(firstName.lastIndexOf(' ') + 1);
firstName = firstName.substring(0, firstName.lastIndexOf(' '));
}
// Register the User.
UserData userData = UserDataUtil.registerUser(firstName, lastName, email, request.password, UserDataUtil.getUserSignUpSource(false, false));
// Create Author profile for the User.
Long authorId = AuthorDataUtil.createAuthorProfile(userData, request.language);
// Log-in the User and get update UserData
userData = UserDataUtil.loginUser(email, request.password);
return new UserV1Api.Response(userData, UserRegisterApi.class);
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class UserLoginFacebookApi method post.
@Post
public UserV1Api.Response post(PostRequest request) throws InvalidArgumentException, InsufficientAccessException, UnexpectedServerException {
UserData userData = UserDataUtil.loginFacebookUser(request.fbUserAccessToken, UserDataUtil.getUserSignUpSource(true, false));
List<Task> taskList = new LinkedList<>();
if (new Date().getTime() - userData.getSignUpDate().getTime() <= 60000) {
Long authorId = AuthorDataUtil.createAuthorProfile(userData, request.language == null ? UxModeFilter.getFilterLanguage() : request.language);
// Fetching updated UserData
userData = UserDataUtil.getCurrentUser();
if (userData.getEmail() != null) {
// Send welcome mail to the user
/*
Task welcomeMailTask = TaskQueueFactory.newTask()
.setUrl( "/user/email" )
.addParam( "userId", userData.getId().toString() )
.addParam( "language", ( request.language == null ? ( UxModeFilter.getDisplayLanguage() == null ? Language.ENGLISH : UxModeFilter.getDisplayLanguage() ) : request.language ).toString() )
.addParam( "sendWelcomeMail", "true" );
taskList.add( welcomeMailTask );
*/
}
// Process Author data
/*
Task task = TaskQueueFactory.newTask()
.setUrl( "/author/process" )
.addParam( "authorId", authorId.toString() )
.addParam( "processData", "true" );
TaskQueueFactory.getAuthorTaskQueue().add( task );
*/
}
return new UserV1Api.Response(userData, UserLoginFacebookApi.class);
}
use of com.pratilipi.data.client.UserData in project pratilipi by Pratilipi.
the class EmailDataUtil method _sendConsolidatedEmail.
private static void _sendConsolidatedEmail(Long userId, List<Email> emailList) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
UserData user = UserDataUtil.createUserData(dataAccessor.getUser(userId));
// Dropping mails if user doesn't have name or language
if (user.getDisplayName() == null || user.getLanguage() == null) {
for (Email email : emailList) {
email.setState(EmailState.DROPPED);
email.setLastUpdated(new Date());
}
emailList = dataAccessor.createOrUpdateEmailList(emailList);
return;
}
String consolidatedContent = new String();
for (Email email : emailList) {
if (email.getState() != EmailState.IN_PROGRESS)
continue;
if (!_isToday(email.getScheduledDate()) && email.getScheduledDate().before(new Date())) {
email.setState(EmailState.DROPPED);
email.setLastUpdated(new Date());
continue;
}
consolidatedContent = consolidatedContent + _getContentSnippet(email, user.getLanguage());
email.setState(EmailState.SENT);
email.setLastUpdated(new Date());
}
if (consolidatedContent.isEmpty()) {
// No IN_PROGRESS emails
dataAccessor.createOrUpdateEmailList(emailList);
return;
}
String content = EmailTemplateUtil.getEmailBody(consolidatedContent, user.getLanguage());
Pattern senderNamePattern = Pattern.compile("<!-- SENDER_NAME:(.+?) -->");
Pattern senderEmailPattern = Pattern.compile("<!-- SENDER_EMAIL:(.+?) -->");
String senderName = null;
String senderEmail = null;
String subject = dataAccessor.getI18nStrings(I18nGroup.EMAIL, user.getLanguage()).get("email_consolidated_subject");
Matcher m = null;
if ((m = senderNamePattern.matcher(content)).find())
senderName = m.group(1).trim();
if ((m = senderEmailPattern.matcher(content)).find())
senderEmail = m.group(1).trim();
EmailUtil.sendMail(senderName, senderEmail, user.getDisplayName(), user.getEmail(), subject, content);
dataAccessor.createOrUpdateEmailList(emailList);
_updateUserEntity(userId);
}
Aggregations