Search in sources :

Example 36 with User

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);
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 37 with 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);
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User)

Example 38 with 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
        }
    }
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) Relationship(com.willshex.blogwt.shared.api.datatype.Relationship) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 39 with User

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);
        }
    });
}
Also used : SearchAllResponse(com.willshex.blogwt.shared.api.search.call.SearchAllResponse) SearchAllFailure(com.willshex.blogwt.client.api.search.event.SearchAllEventHandler.SearchAllFailure) SearchAllSuccess(com.willshex.blogwt.client.api.search.event.SearchAllEventHandler.SearchAllSuccess) User(com.willshex.blogwt.shared.api.datatype.User) Post(com.willshex.blogwt.shared.api.datatype.Post) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) Page(com.willshex.blogwt.shared.api.datatype.Page) SearchAllRequest(com.willshex.blogwt.shared.api.search.call.SearchAllRequest)

Example 40 with User

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);
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

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