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;
}
}
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;
}
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);
}
}
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;
}
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());
}
}
}
Aggregations