def get_user(session_id, user_id=None):
    '''
    Retrieves the user information associated with the specified session ID or user ID.
    '''
    siteUser = None
    
    if (user_id):
        userResponse = client_get_user_by_id(user_id, session_id)
    else:
        userResponse = client_get_user_by_session(session_id)
        
    if (userResponse):
        if ((not userResponse.status.success) or (not userResponse.reckoner_user)):
            logger.warning('Failed to retrieve user from Reckoner Services: ' \
                           + userResponse.status.message)
            return None
        else:
            if (userResponse.auth_session):
                siteUser = SiteCustomUser(reckoner_user = userResponse.reckoner_user, 
                                          auth_session = userResponse.auth_session) 
            else:
                siteUser = SiteCustomUser(reckoner_user = userResponse.reckoner_user)                   
                siteUser.session_id = session_id
               
    return siteUser
def authenticate(oAuthReceipt = None, username = None, password = None):
    '''
    Authenticate against the Reckoner Content Services using a User Token retrieved from an 
    OAUTH provider.
    
    Supply the OAUTH token provided by the OAUTH provider (as an OAuthAccessToken).
    Returns a ReckonerUser object, as provided by the service.
    Username and password are also included as arguments, but not currently supported.
    '''
    siteUser = None
    
    if (oAuthReceipt):
        authResponse = client_authenticate_user(oAuthReceipt)
    
    if (authResponse):
        if ((not authResponse.status.success) or (not authResponse.reckoner_user)):
            # For invalid Google Accounts (i.e. non G+ Google Accounts), mark the user
            # and return to the view.  Otherwise, return None and the view will handle it.
            if (authResponse.status.message == "R707_AUTH_USER"):
                siteUser = SiteCustomUser(is_invalid_google_user=True)
                return siteUser
            
            logger.warning('Failed to authenticate user against Reckoner Services: ' \
                           + authResponse.status.message)
            return None
        else:
            siteUser = SiteCustomUser(reckoner_user = authResponse.reckoner_user, 
                                        auth_session = authResponse.auth_session)
            
            if (authResponse.status.message == "R703_AUTH_USER"):
                siteUser.is_new_user = True

    return siteUser