Search in sources :

Example 1 with GeneralUser

use of org.b3log.latke.user.GeneralUser in project solo by b3log.

the class UserQueryService method isLoggedIn.

/**
     * Checks whether the current request is made by a logged in user
     * (including default user and administrator lists in <i>users</i>).
     * 
     * <p>
     * Invokes this method will try to login with cookie first.
     * </p>
     *
     * @param request the specified request
     * @param response the specified response
     * @return {@code true} if the current request is made by logged in user,
     * returns {@code false} otherwise
     */
public boolean isLoggedIn(final HttpServletRequest request, final HttpServletResponse response) {
    userMgmtService.tryLogInWithCookie(request, response);
    final GeneralUser currentUser = userService.getCurrentUser(request);
    return null != currentUser;
}
Also used : GeneralUser(org.b3log.latke.user.GeneralUser)

Example 2 with GeneralUser

use of org.b3log.latke.user.GeneralUser in project solo by b3log.

the class UserQueryService method getCurrentUser.

/**
     * Gets the current user.
     *
     * @param request the specified request
     * @return the current user, {@code null} if not found
     */
public JSONObject getCurrentUser(final HttpServletRequest request) {
    final GeneralUser currentUser = userService.getCurrentUser(request);
    if (null == currentUser) {
        return null;
    }
    final String email = currentUser.getEmail();
    try {
        return userRepository.getByEmail(email);
    } catch (final RepositoryException e) {
        LOGGER.log(Level.ERROR, "Gets current user by request failed, returns null", e);
        return null;
    }
}
Also used : RepositoryException(org.b3log.latke.repository.RepositoryException) GeneralUser(org.b3log.latke.user.GeneralUser)

Aggregations

GeneralUser (org.b3log.latke.user.GeneralUser)2 RepositoryException (org.b3log.latke.repository.RepositoryException)1