Fatih Degirmenci | c2a4601 | 2019-09-30 12:07:45 +0200 | [diff] [blame] | 1 | from flask import jsonify, g |
| 2 | from app import db |
| 3 | from app.api import bp |
| 4 | from app.api.auth import basic_auth, token_auth |
| 5 | |
| 6 | @bp.route('/tokens', methods=['POST']) |
| 7 | @basic_auth.login_required |
| 8 | def get_token(): |
| 9 | token = g.current_user.get_token() |
| 10 | db.session.commit() |
| 11 | return jsonify({'token': token}) |
| 12 | |
| 13 | @bp.route('/tokens', methods=['DELETE']) |
| 14 | @token_auth.login_required |
| 15 | def revoke_token(): |
| 16 | g.current_user.revoke_token() |
| 17 | db.session.commit() |
| 18 | return '', 204 |