Search in sources :

Example 6 with UserData

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;
}
Also used : UserData(com.pratilipi.data.client.UserData) AuthorData(com.pratilipi.data.client.AuthorData)

Example 7 with 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);
}
Also used : UserData(com.pratilipi.data.client.UserData) Date(java.util.Date) Post(com.pratilipi.api.annotation.Post)

Example 8 with UserData

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);
}
Also used : UserData(com.pratilipi.data.client.UserData) Post(com.pratilipi.api.annotation.Post)

Example 9 with UserData

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);
}
Also used : Task(com.pratilipi.taskqueue.Task) UserData(com.pratilipi.data.client.UserData) LinkedList(java.util.LinkedList) Date(java.util.Date) Post(com.pratilipi.api.annotation.Post)

Example 10 with UserData

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);
}
Also used : Pattern(java.util.regex.Pattern) Email(com.pratilipi.data.type.Email) UserData(com.pratilipi.data.client.UserData) Matcher(java.util.regex.Matcher) DataAccessor(com.pratilipi.data.DataAccessor) Date(java.util.Date)

Aggregations

UserData (com.pratilipi.data.client.UserData)28 DataAccessor (com.pratilipi.data.DataAccessor)14 User (com.pratilipi.data.type.User)7 Date (java.util.Date)7 HashMap (java.util.HashMap)7 Post (com.pratilipi.api.annotation.Post)6 AuthorData (com.pratilipi.data.client.AuthorData)6 JsonObject (com.google.gson.JsonObject)5 InvalidArgumentException (com.pratilipi.common.exception.InvalidArgumentException)5 Gson (com.google.gson.Gson)4 InsufficientAccessException (com.pratilipi.common.exception.InsufficientAccessException)4 UserPratilipiData (com.pratilipi.data.client.UserPratilipiData)4 Author (com.pratilipi.data.type.Author)4 ArrayList (java.util.ArrayList)4 UnexpectedServerException (com.pratilipi.common.exception.UnexpectedServerException)3 PratilipiData (com.pratilipi.data.client.PratilipiData)3 AuditLog (com.pratilipi.data.type.AuditLog)3 JsonElement (com.google.gson.JsonElement)2 GenericResponse (com.pratilipi.api.shared.GenericResponse)2 Language (com.pratilipi.common.type.Language)2