Search in sources :

Example 41 with User

use of com.willshex.blogwt.shared.api.datatype.User in project blogwt by billy1380.

the class VerifyAccountActionHandler method handle.

/* (non-Javadoc)
	 * 
	 * @see
	 * com.willshex.gson.web.service.server.ActionHandler#handle(com.willshex.
	 * gson.web.service.shared.Request,
	 * com.willshex.gson.web.service.shared.Response) */
@Override
protected void handle(VerifyAccountRequest input, VerifyAccountResponse output) throws Exception {
    ApiValidator.request(input, VerifyAccountRequest.class);
    ApiValidator.accessCode(input.accessCode, "input.accessCode");
    ApiValidator.validateToken(input.actionCode, "input.actionCode");
    User user = UserServiceProvider.provide().getActionCodeUser(input.actionCode);
    if (user == null)
        ApiValidator.throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, "String: input.actionCode");
    user.verified = Boolean.TRUE;
    user.actionCode = null;
    user = UserServiceProvider.provide().updateUser(user);
    output.session = SessionServiceProvider.provide().getUserSession(user);
    if (output.session == null) {
        if (LOG.isLoggable(Level.FINER)) {
            LOG.finer("Existing session not found, creating new session");
        }
        output.session = SessionServiceProvider.provide().createUserSession(user, Boolean.FALSE);
        if (output.session != null) {
            output.session.user = user;
        } else {
            throw new Exception("Unexpected blank session after creating user session.");
        }
    } else {
        output.session = SessionServiceProvider.provide().extendSession(output.session);
        output.session.user = user;
    }
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) InputValidationException(com.willshex.gson.web.service.server.InputValidationException) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 42 with User

use of com.willshex.blogwt.shared.api.datatype.User in project blogwt by billy1380.

the class UserValidator method validate.

public static User validate(User user, String name) throws InputValidationException {
    boolean foundUsername = false, foundEmail = false;
    if (user.username != null) {
        validateLength(user.username, 1, 512, TYPE + ": " + name + "[" + user.username + "].username");
        foundUsername = true;
    }
    if (user.email != null) {
        validateLength(user.email, 1, 512, TYPE + ": " + name + "[" + user.email + "].email");
        foundEmail = true;
    }
    if (foundUsername) {
        User existingUsernameUser = UserServiceProvider.provide().getUsernameUser(user.username);
        if (existingUsernameUser != null && !DataTypeHelper.<User>same(user, existingUsernameUser))
            throwServiceError(InputValidationException.class, ApiError.UsernameInUse, "String: " + name + ".username");
    }
    if (foundEmail) {
        User existingEmailUser = UserServiceProvider.provide().getEmailUser(user.email);
        if (existingEmailUser != null && !DataTypeHelper.<User>same(user, existingEmailUser))
            throwServiceError(InputValidationException.class, ApiError.EmailInUse, "String: " + name + ".email");
    }
    if (!(foundUsername || foundEmail))
        throwServiceError(InputValidationException.class, ApiError.NotEnoughData, TYPE + ": no username or email in " + name);
    return user;
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 43 with User

use of com.willshex.blogwt.shared.api.datatype.User in project blogwt by billy1380.

the class GeneratedDownloadHelper method sendEmail.

/**
 * @param generatedDownload
 * @param data
 */
public static void sendEmail(GeneratedDownload generatedDownload, Filter filter, byte[] data) {
    User user = UserServiceProvider.provide().getUser(PersistenceHelper.keyToId(generatedDownload.userKey));
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("Sending generated download as attachment to user [" + user.id + "]");
    }
    if (user != null) {
        StringBuffer buffer = new StringBuffer();
        buffer.append("Hi ");
        buffer.append(UserHelper.name(user));
        buffer.append(",\n");
        buffer.append("Your download (" + filter.type + ") is ready. Please find it attached.\n");
        String emailBody = buffer.toString();
        buffer.setLength(0);
        buffer.append("Download ready - ");
        buffer.append(filter.type);
        String emailSubject = buffer.toString();
        Map<String, byte[]> attachments = new HashMap<>();
        attachments.put(fileName(generatedDownload, filter), data);
        EmailHelper.sendEmail(user.email, UserHelper.name(user), emailSubject, emailBody, false, attachments);
    }
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) HashMap(java.util.HashMap)

Example 44 with User

use of com.willshex.blogwt.shared.api.datatype.User in project blogwt by billy1380.

the class UserService method search.

/* (non-Javadoc)
	 * 
	 * @see com.willshex.blogwt.server.service.search.ISearch#search(java.lang.
	 * String, java.lang.Integer, java.lang.Integer, java.lang.String,
	 * com.willshex.blogwt.shared.api.SortDirectionType) */
@Override
public List<User> search(String query, Integer start, Integer count, String sortBy, SortDirectionType direction) {
    Results<ScoredDocument> matches = SearchHelper.getIndex().search(query);
    List<User> users = new ArrayList<User>();
    String id;
    User user;
    int limit = count;
    final String userServiceName = getName();
    for (ScoredDocument scoredDocument : matches) {
        if (limit == 0) {
            break;
        }
        if ((id = scoredDocument.getId()).startsWith(userServiceName)) {
            user = getUser(Long.valueOf(id.replace(userServiceName, "")));
            if (user != null) {
                users.add(user);
            }
        }
        limit--;
    }
    return users;
}
Also used : ScoredDocument(com.google.appengine.api.search.ScoredDocument) User(com.willshex.blogwt.shared.api.datatype.User) ArrayList(java.util.ArrayList)

Example 45 with User

use of com.willshex.blogwt.shared.api.datatype.User in project blogwt by billy1380.

the class GetRatingsRequest method fromJson.

@Override
public void fromJson(JsonObject jsonObject) {
    super.fromJson(jsonObject);
    if (jsonObject.has("by")) {
        JsonElement jsonBy = jsonObject.get("by");
        if (jsonBy != null) {
            by = new User();
            by.fromJson(jsonBy.getAsJsonObject());
        }
    }
    if (jsonObject.has("subjectId")) {
        JsonElement jsonSubjectId = jsonObject.get("subjectId");
        if (jsonSubjectId != null) {
            subjectId = Long.valueOf(jsonSubjectId.getAsLong());
        }
    }
    if (jsonObject.has("subjectType")) {
        JsonElement jsonSubjectType = jsonObject.get("subjectType");
        if (jsonSubjectType != null) {
            subjectType = jsonSubjectType.getAsString();
        }
    }
    if (jsonObject.has("pager")) {
        JsonElement jsonPager = jsonObject.get("pager");
        if (jsonPager != null) {
            pager = new Pager();
            pager.fromJson(jsonPager.getAsJsonObject());
        }
    }
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) JsonElement(com.google.gson.JsonElement) Pager(com.willshex.blogwt.shared.api.Pager)

Aggregations

User (com.willshex.blogwt.shared.api.datatype.User)46 JsonElement (com.google.gson.JsonElement)19 InputValidationException (com.willshex.gson.web.service.server.InputValidationException)10 Pager (com.willshex.blogwt.shared.api.Pager)6 Permission (com.willshex.blogwt.shared.api.datatype.Permission)5 Page (com.willshex.blogwt.shared.api.datatype.Page)4 Post (com.willshex.blogwt.shared.api.datatype.Post)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Key (com.googlecode.objectify.Key)3 Role (com.willshex.blogwt.shared.api.datatype.Role)3 Date (java.util.Date)3 HeadingElement (com.google.gwt.dom.client.HeadingElement)2 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)2 UiHandler (com.google.gwt.uibinder.client.UiHandler)2 MetaNotification (com.willshex.blogwt.shared.api.datatype.MetaNotification)2 Relationship (com.willshex.blogwt.shared.api.datatype.Relationship)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)1 ScoredDocument (com.google.appengine.api.search.ScoredDocument)1 JsonObject (com.google.gson.JsonObject)1