From 1590db908beea5933af0b778db1376b0b6d7a188 Mon Sep 17 00:00:00 2001 From: Muhammad Date: Sat, 25 Nov 2023 19:09:33 +0500 Subject: [PATCH] api: check if user is subscribed for dictation token --- auth/api.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/auth/api.py b/auth/api.py index 56b9a3b..4732ecd 100644 --- a/auth/api.py +++ b/auth/api.py @@ -59,15 +59,17 @@ def pebble_dev_portal_me(): @oauth.require_oauth('pebble') def get_dictation_token(): user = request.oauth.user - asr_token = IssuedToken.query.filter_by(user_id=user.id, scopes='{asr}').first() - if not asr_token: - asr_token = IssuedToken(user_id=user.id, client_id='asr', scopes=['asr'], - expires=datetime.datetime.utcnow() + datetime.timedelta(days=3650), - access_token=generate_token(15, 'abcdefghijklmnopqrsstuvwxyz0123456789'), refresh_token=generate_token()) - db.session.add(asr_token) - db.session.commit() - return jsonify(token=asr_token.access_token) - + if (user.is_subscribed): + asr_token = IssuedToken.query.filter_by(user_id=user.id, scopes='{asr}').first() + if not asr_token: + asr_token = IssuedToken(user_id=user.id, client_id='asr', scopes=['asr'], + expires=datetime.datetime.utcnow() + datetime.timedelta(days=3650), + access_token=generate_token(15, 'abcdefghijklmnopqrsstuvwxyz0123456789'), refresh_token=generate_token()) + db.session.add(asr_token) + db.session.commit() + return jsonify(token=asr_token.access_token) + else: + abort(401) def init_app(app, url_prefix='/api/v1'): app.register_blueprint(api, url_prefix=url_prefix)