use of com.willshex.blogwt.shared.api.datatype.User in project blogwt by billy1380.
the class ChangePasswordActionHandler 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(ChangePasswordRequest input, ChangePasswordResponse output) throws Exception {
ApiValidator.request(input, ChangePasswordRequest.class);
ApiValidator.accessCode(input.accessCode, "input.accessCode");
ApiValidator.notNull(input.changedPassword, String.class, "input.changedPassword");
if (input.session != null) {
try {
output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
} catch (InputValidationException ex) {
output.session = input.session = null;
}
}
// // if not the logged in user
// if (!DataTypeHelper.<User> same(input.user, input.session.user)) {
// List<Role> roles = new ArrayList<Role>();
// roles.add(RoleHelper.createAdmin());
//
// List<Permission> permissions = new ArrayList<Permission>();
// Permission postPermission = PermissionServiceProvider.provide()
// .getCodePermission(PermissionHelper.MANAGE_USERS);
// permissions.add(postPermission);
//
// UserValidator.authorisation(input.session.user, roles,
// permissions, "input.session.user");
// }
boolean isExistingPassword = false, isActionCode = false;
if (input.resetCode != null && input.resetCode.length() > 0) {
isActionCode = true;
}
if (input.password != null && input.password.length() > 0) {
isExistingPassword = true;
}
if (!(isActionCode || isExistingPassword))
ApiValidator.throwServiceError(InputValidationException.class, ApiError.InvalidValueNull, "String: input.password or input.resetCode");
User user = null;
if (isActionCode) {
input.resetCode = UserValidator.validateToken(input.resetCode, "input.resetCode");
user = UserServiceProvider.provide().getActionCodeUser(input.resetCode);
if (user == null)
ApiValidator.throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, "String: input.resetToken");
user.actionCode = null;
}
if (isExistingPassword && !isActionCode) {
user = input.session.user;
if (!UserServiceProvider.provide().verifyPassword(user, input.password))
ApiValidator.throwServiceError(InputValidationException.class, ApiError.AuthenticationFailedBadPassword, "String: input.password");
}
user.password = UserServiceProvider.provide().generatePassword(input.changedPassword);
UserServiceProvider.provide().updateUser(user);
}
use of com.willshex.blogwt.shared.api.datatype.User in project blogwt by billy1380.
the class ChangeUserDetailsActionHandler 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(ChangeUserDetailsRequest input, ChangeUserDetailsResponse output) throws Exception {
ApiValidator.request(input, ChangeUserDetailsRequest.class);
ApiValidator.accessCode(input.accessCode, "input.accessCode");
output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
User updatedUser = input.user;
input.user = UserValidator.lookup(input.user, "input.user");
// if the not logged in user
if (!DataTypeHelper.<User>same(input.user, input.session.user)) {
UserValidator.authorisation(input.session.user, Arrays.asList(PermissionServiceProvider.provide().getCodePermission(PermissionHelper.MANAGE_USERS)), "input.session.user");
}
updatedUser = UserValidator.validate(updatedUser, "input.user");
input.user.username = updatedUser.username;
input.user.forename = updatedUser.forename;
input.user.surname = updatedUser.surname;
input.user.email = updatedUser.email;
input.user.summary = updatedUser.summary;
output.user = UserServiceProvider.provide().updateUser(input.user);
}
use of com.willshex.blogwt.shared.api.datatype.User in project blogwt by billy1380.
the class FollowUsersActionHandler 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(FollowUsersRequest input, FollowUsersResponse output) throws Exception {
PropertyValidator.ensureTrue(PropertyHelper.ALLOW_USER_REGISTRATION, PropertyHelper.ENABLE_USER_RELATIONSHIPS);
ApiValidator.request(input, FollowUsersRequest.class);
ApiValidator.accessCode(input.accessCode, "input.accessCode");
output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
User user = null;
if (input.user == null) {
user = input.session.user;
} else {
user = input.user;
UserValidator.validate(user, "input.user");
if (!DataTypeHelper.<User>same(user, input.session.user)) {
UserValidator.authorisation(input.session.user, Arrays.asList(PermissionServiceProvider.provide().getCodePermission(PermissionHelper.MANAGE_USERS)), "input.session.user");
}
}
ApiValidator.notNull(input.others, User.class, "input.others");
List<Relationship> added = null;
if (!Boolean.TRUE.equals(input.un)) {
added = new ArrayList<Relationship>();
}
for (User other : input.others) {
try {
// validate each user
other = UserValidator.validate(other, "input.other[n]");
// add a relationship for the validated users (skip failures)
if (Boolean.TRUE.equals(input.un)) {
// un-follow
RelationshipServiceProvider.provide().deleteUsersRelationship(user, other, RelationshipTypeType.RelationshipTypeTypeFollow);
} else {
// follow
added.add(RelationshipServiceProvider.provide().addUsersRelationship(user, other, RelationshipTypeType.RelationshipTypeTypeFollow));
}
} catch (InputValidationException inEx) {
// just skip that user if the user is not valid
}
}
}
use of com.willshex.blogwt.shared.api.datatype.User in project blogwt by billy1380.
the class SearchController method fetchSearchResults.
private void fetchSearchResults(String query) {
final SearchAllRequest input = ApiHelper.setAccessCode(new SearchAllRequest());
input.session = SessionController.get().sessionForApiCall();
input.query = query;
if (searchAllRequest != null) {
searchAllRequest.cancel();
}
searchAllRequest = ApiHelper.createSearchClient().searchAll(input, new AsyncCallback<SearchAllResponse>() {
@Override
public void onSuccess(SearchAllResponse output) {
searchAllRequest = null;
if (output.status == StatusType.StatusTypeSuccess) {
List<SearchResult> results = new ArrayList<SearchController.SearchResult>();
if (output.posts != null) {
for (Post post : output.posts) {
results.add(new SearchResult(post));
}
}
if (output.pages != null) {
for (Page page : output.pages) {
results.add(new SearchResult(page));
}
}
if (output.users != null) {
for (User user : output.users) {
results.add(new SearchResult(user));
}
}
updateRowCount(results.size(), true);
updateRowData(0, results);
}
DefaultEventBus.get().fireEventFromSource(new SearchAllSuccess(input, output), SearchController.this);
}
@Override
public void onFailure(Throwable caught) {
searchAllRequest = null;
DefaultEventBus.get().fireEventFromSource(new SearchAllFailure(input, caught), SearchController.this);
}
});
}
use of com.willshex.blogwt.shared.api.datatype.User in project blogwt by billy1380.
the class ResetPasswordActionHandler 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(ResetPasswordRequest input, ResetPasswordResponse output) throws Exception {
ApiValidator.request(input, ResetPasswordRequest.class);
ApiValidator.accessCode(input.accessCode, "input.accessCode");
if (input.session != null) {
try {
output.session = input.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
} catch (InputValidationException ex) {
output.session = input.session = null;
}
}
ApiValidator.notNull(input.email, String.class, "input.email");
User user = UserServiceProvider.provide().getEmailUser(input.email);
if (user == null)
ApiValidator.throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, "String: input.email");
UserServiceProvider.provide().resetPassword(user);
}
Aggregations