Search in sources :

Example 6 with User

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

the class UsersPage method createColumns.

/**
 * create columns
 */
private void createColumns() {
    Column<User, String> avatar = new Column<User, String>(UiHelper.IMAGE_PROTOTYPE) {

        @Override
        public String getValue(User object) {
            return object.avatar + "?s=" + UserHelper.AVATAR_HEADER_SIZE + "&default=retro";
        }
    };
    tblUsers.setColumnWidth(avatar, 20.0, Unit.PX);
    TextColumn<User> username = new TextColumn<User>() {

        @Override
        public String getValue(User object) {
            return object.username;
        }
    };
    TextColumn<User> name = new TextColumn<User>() {

        @Override
        public String getValue(User object) {
            return UserHelper.name(object);
        }
    };
    Column<User, SafeHtml> email = new Column<User, SafeHtml>(UiHelper.SAFE_HTML_PROTOTYPE) {

        @Override
        public SafeHtml getValue(User object) {
            return UsersPageTemplates.INSTANCE.emailLink(object.email, UserHelper.emailDescription(object));
        }
    };
    TextColumn<User> lastLoggedIn = new TextColumn<User>() {

        @Override
        public String getValue(User object) {
            return DateTimeHelper.ago(object.lastLoggedIn);
        }
    };
    Column<User, SafeHtml> edit = new Column<User, SafeHtml>(UiHelper.SAFE_HTML_PROTOTYPE) {

        @Override
        public SafeHtml getValue(User object) {
            return UiHelper.TEMPLATES.xsEdit(PageTypeHelper.asHref(PageType.ChangeDetailsPageType, "id", object.id.toString()));
        }
    };
    tblUsers.setColumnWidth(edit, 1.0, Unit.PX);
    Column<User, String> suspend = new Column<User, String>(UiHelper.ACTION_PROTOTYPE) {

        @Override
        public String getValue(User object) {
            return UserHelper.isSuspended(object) ? "unsuspend" : "suspend";
        }
    };
    suspend.setFieldUpdater(new FieldUpdater<User, String>() {

        @Override
        public void update(int index, User object, String value) {
            boolean suspended = UserHelper.isSuspended(object);
            if (suspended) {
                UserController.get().unsuspendUser(object);
            } else {
                if (Window.confirm("Are you sure you want to suspend " + object.username + "'s account indefinitely?")) {
                    UserController.get().suspendUser(object);
                }
            }
        }
    });
    tblUsers.setColumnWidth(suspend, 1.0, Unit.PX);
    Column<User, String> admin = new Column<User, String>(UiHelper.ACTION_PROTOTYPE) {

        @Override
        public String getValue(User object) {
            return "admin";
        }
    };
    final Role adminRole = RoleHelper.createFullAdmin();
    admin.setFieldUpdater(new FieldUpdater<User, String>() {

        @Override
        public void update(int index, User object, String value) {
            if (Window.confirm("Are you sure you want to make " + object.username + " a " + adminRole.name + "?")) {
                UserController.get().assignUserRoles(object, adminRole);
            }
        }
    });
    tblUsers.setColumnWidth(admin, 1.0, Unit.PX);
    tblUsers.addColumn(avatar);
    tblUsers.addColumn(username, "Username");
    tblUsers.addColumn(name, "Name");
    tblUsers.addColumn(email, "E-mail");
    tblUsers.addColumn(lastLoggedIn, "Last seen");
    tblUsers.addColumn(edit);
    tblUsers.addColumn(admin);
    tblUsers.addColumn(suspend);
}
Also used : Role(com.willshex.blogwt.shared.api.datatype.Role) User(com.willshex.blogwt.shared.api.datatype.User) TextColumn(com.google.gwt.user.cellview.client.TextColumn) Column(com.google.gwt.user.cellview.client.Column) SafeHtml(com.google.gwt.safehtml.shared.SafeHtml) TextColumn(com.google.gwt.user.cellview.client.TextColumn)

Example 7 with User

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

the class GetUsersActionHandler method getRelatedUsers.

/**
 * @param input
 * @return
 * @throws DisallowedByPropertyException
 * @throws InputValidationException
 */
private List<User> getRelatedUsers(GetUsersRequest input) throws DisallowedByPropertyException, InputValidationException {
    List<User> relatedUsers = null;
    User user = null;
    PropertyValidator.ensureTrue(PropertyHelper.ALLOW_USER_REGISTRATION, PropertyHelper.ENABLE_USER_RELATIONSHIPS);
    if (input.user == null) {
        user = input.user = UserValidator.validate(input.user, "input.user");
    } else {
        user = input.session.user;
    }
    List<Relationship> relationships = null;
    List<Long> userIds = null;
    if (Boolean.TRUE.equals(input.userIsOther)) {
        // Cannot reveal users blocking you
        if (input.relationshipType == RelationshipTypeType.RelationshipTypeTypeBlock)
            ApiValidator.throwServiceError(InputValidationException.class, ApiError.CannotRevealRelationshipUsers, "input.relationshipType");
        relationships = RelationshipServiceProvider.provide().getWithUserRelationships(user, input.relationshipType, input.pager.start, input.pager.count, RelationshipSortType.fromString(input.pager.sortBy), input.pager.sortDirection);
        if (relationships != null && !relationships.isEmpty()) {
            userIds = new ArrayList<Long>();
            for (Relationship relationship : relationships) {
                userIds.add(keyToId(relationship.oneKey));
            }
        }
    } else {
        relationships = RelationshipServiceProvider.provide().getUserRelationships(user, input.relationshipType, input.pager.start, input.pager.count, RelationshipSortType.fromString(input.pager.sortBy), input.pager.sortDirection);
        if (relationships != null && !relationships.isEmpty()) {
            userIds = new ArrayList<Long>();
            for (Relationship relationship : relationships) {
                userIds.add(keyToId(relationship.anotherKey));
            }
        }
    }
    if (userIds != null) {
        // order might become important later for now, it is not
        relatedUsers = PersistenceHelper.batchLookup(UserServiceProvider.provide(), PersistenceHelper.idsToKeys(User.class, userIds));
    }
    return relatedUsers;
}
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 8 with User

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

the class LoginActionHandler 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(LoginRequest input, LoginResponse output) throws Exception {
    input = ApiValidator.request(input, LoginRequest.class);
    input.accessCode = ApiValidator.accessCode(input.accessCode, "input.accessCode");
    boolean foundToken = false;
    if (input.session != null && input.session.id != null) {
        foundToken = true;
    }
    if (!foundToken) {
        IUserService userService = UserServiceProvider.provide();
        User user = null;
        if (input.username != null) {
            user = userService.getLoginUser(input.username, input.password);
            if (user == null)
                throw new AuthenticationException(input.username);
        }
        if (user == null && input.email != null) {
            user = userService.getEmailLoginUser(input.email, input.password);
            if (user == null)
                throw new AuthenticationException(input.email);
        }
        if (user == null)
            throw new AuthenticationException("Either username or email addressed cannot be null");
        ISessionService sessionService = SessionServiceProvider.provide();
        if (LOG.isLoggable(Level.FINER)) {
            LOG.finer("Getting user session");
        }
        output.session = sessionService.getUserSession(user);
        if (output.session == null) {
            if (LOG.isLoggable(Level.FINER)) {
                LOG.finer("Existing session not found, creating new session");
            }
            output.session = sessionService.createUserSession(user, input.longTerm);
            UserServiceProvider.provide().updateUserIdLastLoggedIn(user.id);
        } else {
            if (input.longTerm != null) {
                output.session.longTerm(input.longTerm);
            }
            output.session = SessionServiceProvider.provide().extendSession(output.session);
            output.session.user = user;
        }
    } else {
        output.session = SessionValidator.lookupCheckAndExtend(input.session, "input.session");
    }
    if (output.session.user.roleKeys != null) {
        output.session.user.roles = PersistenceHelper.batchLookup(RoleServiceProvider.provide(), output.session.user.roleKeys);
    }
    if (output.session.user.permissionKeys != null) {
        output.session.user.permissions = PersistenceHelper.batchLookup(PermissionServiceProvider.provide(), output.session.user.permissionKeys);
    }
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) AuthenticationException(com.willshex.blogwt.server.api.exception.AuthenticationException) ISessionService(com.willshex.blogwt.server.service.session.ISessionService) IUserService(com.willshex.blogwt.server.service.user.IUserService) LoginRequest(com.willshex.blogwt.shared.api.user.call.LoginRequest)

Example 9 with User

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

the class UserValidator method lookup.

public static User lookup(User user, String name) throws InputValidationException {
    notNull(user, CLASS, name);
    boolean isIdLookup = false, isNameLookup = false;
    if (user.id != null) {
        isIdLookup = true;
    } else if (user.username != null) {
        isNameLookup = true;
    }
    if (!(isIdLookup || isNameLookup))
        throwServiceError(InputValidationException.class, ApiError.DataTypeNoLookup, TYPE + ": " + name);
    User lookupUser = null;
    if (isIdLookup) {
        lookupUser = UserServiceProvider.provide().getUser(user.id);
    } else if (isNameLookup) {
        lookupUser = UserServiceProvider.provide().getUsernameUser(user.username);
    }
    if (lookupUser == null)
        throwServiceError(InputValidationException.class, ApiError.DataTypeNotFound, TYPE + ": " + name);
    return lookupUser;
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User) InputValidationException(com.willshex.gson.web.service.server.InputValidationException)

Example 10 with User

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

the class UserService method index.

/* (non-Javadoc)
	 * 
	 * @see
	 * com.willshex.blogwt.server.service.search.IIndex#index(java.lang.Long) */
@Override
public void index(Long id) {
    User user = getUser(id);
    if (user.roleKeys != null) {
        user.roles = PersistenceHelper.batchLookup(RoleServiceProvider.provide(), user.roleKeys);
    }
    if (user.permissionKeys != null) {
        user.permissions = PersistenceHelper.batchLookup(PermissionServiceProvider.provide(), user.permissionKeys);
    }
    SearchHelper.indexDocument(toDocument(user));
}
Also used : User(com.willshex.blogwt.shared.api.datatype.User)

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