rev: 491566fa24ddd88cee7987a361d3a63f466f8c76 Wikked/wikked/api/user.py -rw-r--r-- 1.4 KiB View raw Log this file
491566fa24ddLudovic Chabant cm: Upgrade dependencies and fix deprecated APIs. 1 year, 6 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from flask import jsonify, abort, request
from flask_login import logout_user, current_user
from wikked.web import app, get_wiki
from wikked.webimpl.admin import do_login_user


@app.route('/api/user/login', methods=['POST'])
def api_user_login():
    if do_login_user():
        username = request.form.get('username')
        result = {'username': username, 'logged_in': 1}
        return jsonify(result)
    abort(401)


@app.route('/api/user/is_logged_in')
def api_user_is_logged_in():
    if current_user.is_authenticated:
        result = {'logged_in': True}
        return jsonify(result)
    abort(401)


@app.route('/api/user/logout', methods=['POST'])
def api_user_logout():
    logout_user()
    result = {'ok': 1}
    return jsonify(result)


@app.route('/api/user/info')
def api_current_user_info():
    user = current_user
    if user.is_authenticated:
        result = {
            'user': {
                'username': user.username,
                'groups': user.groups
            }
        }
        return jsonify(result)
    return jsonify({'user': False})


@app.route('/api/user/info/<name>')
def api_user_info(name):
    wiki = get_wiki()
    user = wiki.auth.getUser(name)
    if user is not None:
        result = {
            'user': {
                'username': user.username,
                'groups': user.groups
            }
        }
        return jsonify(result)
    abort(404)