~homeworkprod/byceps

ref: c8b4b0f58f33432fbeff3e25175677aa9cbb5c14 byceps/byceps/blueprints/site/user/current/views.py -rw-r--r-- 798 bytes
c8b4b0f5 — Jochen Kupperschmidt Introduce one-line helper for script execution 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
byceps.blueprints.site.user.current.views
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from flask import abort, g, jsonify, Response

from .....config import get_app_mode
from .....util.framework.blueprint import create_blueprint


blueprint = create_blueprint('user_current', __name__)


@blueprint.route('/me.json')
def view_as_json():
    """Show selected attributes of the current user's profile as JSON."""
    user = g.user

    if not user.authenticated:
        # Return empty response.
        return Response(status=403)

    return jsonify(
        {
            'id': user.id,
            'screen_name': user.screen_name,
            'avatar_url': user.avatar_url,
        }
    )