diff --git a/doc/client/index.rst b/doc/client/index.rst index 83150af..e10826d 100644 --- a/doc/client/index.rst +++ b/doc/client/index.rst @@ -67,9 +67,9 @@ All URLs must end with "/"; if you forget to add them in the URL, you'll receive a redirect to the path with "/". API ----- +==== .. toctree:: - :maxdepth: 2 + :maxdepth: 3 users_and_tokens diff --git a/doc/client/users_and_tokens.rst b/doc/client/users_and_tokens.rst index 2cf65a7..9f6d76b 100644 --- a/doc/client/users_and_tokens.rst +++ b/doc/client/users_and_tokens.rst @@ -10,7 +10,7 @@ should use this request to get a valid token: .. autoflask:: luncho.server:app :blueprints: token - :undoc-endpoints: static + :undoc-endpoints: static,show_api Users @@ -18,4 +18,4 @@ Users .. autoflask:: luncho.server:app :blueprints: users - :undoc-endpoints: static + :undoc-endpoints: static,show_api diff --git a/doc/conf.py b/doc/conf.py index f2766c2..2ee3ef7 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -15,11 +15,12 @@ import sys import os +import sphinx_readable_theme + # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath('..')) -sys.path.append(os.path.abspath('_themes/flask-sphinx-themes')) # -- General configuration ------------------------------------------------ @@ -105,7 +106,7 @@ pygments_style = 'sphinx' # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. #html_theme = 'default' -html_theme = 'flask' +html_theme = 'readable' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -113,7 +114,7 @@ html_theme = 'flask' #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -html_theme_path = ['_themes/flask-sphinx-themes/'] +html_theme_path = [sphinx_readable_theme.get_html_theme_path()] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". diff --git a/luncho/blueprints/token.py b/luncho/blueprints/token.py index 8f196ed..37391c1 100644 --- a/luncho/blueprints/token.py +++ b/luncho/blueprints/token.py @@ -19,7 +19,15 @@ from luncho.exceptions import LunchoException # ---------------------------------------------------------------------- class UserDoesNotExistException(LunchoException): - """There is no such user in the database.""" + """There is no such user in the database. + + .. sourcecode:: http + + HTTP/1.1 404 Not found + Content-Type: text/json + + { "status": "ERROR", "message": "User does not exist" } + """ def __init__(self): super(UserDoesNotExistException, self).__init__() self.status = 404 @@ -27,7 +35,15 @@ class UserDoesNotExistException(LunchoException): class InvalidPasswordException(LunchoException): - """Invalid password.""" + """Invalid password. + + .. sourcecode:: http + + HTTP/1.1 401 Unauthorized + Content-Type: text/json + + { "status": "ERROR", "message": "Invalid password" } + """ def __init__(self): super(InvalidPasswordException, self).__init__() self.status = 401 @@ -62,23 +78,9 @@ def get_token(): { "status": "OK", "token": "access_token" } - **Invalid password (401)**: - - .. sourcecode:: http - - HTTP/1.1 401 Unauthorized - Content-Type: text/json - - { "status": "ERROR", "message": "Invalid password" } + **Invalid password (401)**: :py:class:`InvalidPasswordException` - **Unknown user (404)**: - - .. sourcecode:: http - - HTTP/1.1 404 Not found - Content-Type: text/json - - { "status": "ERROR", "message": "User does not exist" } + **Unknown user (404)**: :py:class:`UserDoesNotExistException` """ json = request.get_json(force=True) diff --git a/luncho/helpers.py b/luncho/helpers.py index 41afec6..06dcd0e 100644 --- a/luncho/helpers.py +++ b/luncho/helpers.py @@ -46,6 +46,11 @@ class ForceJSON(object): def auth(func): + """Decorator to make the request authenticated via token. If the token + is missing or it is invalid, the decorator will raise the proper + exceptions (and return the proper error codes). If the token is valid, + a "user" property will be added to the request object with the current + user.""" @wraps(func) def check_auth(*args, **kwargs): if not request.authorization: diff --git a/requirements-dev.txt b/requirements-dev.txt index b3573cd..c21d118 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,3 +2,4 @@ nose nosexcover sphinx sphinxcontrib-httpdomain +sphinx-readable-theme