api.token.verify_password()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
from flask import Blueprint, g
2
from flask_httpauth import HTTPBasicAuth
3
from .models import User
4
from .errors import unauthorized
5
from .decorators import no_cache, json
6
7
token = Blueprint('token', __name__)
8
token_auth = HTTPBasicAuth()
9
10
11
@token_auth.verify_password
12
def verify_password(username_or_token, password):
13
  g.user = User.query.filter_by(username=username_or_token).first()
14
  if not g.user:
15
    return False
16
  return g.user.verify_password(password)
17
18
19
@token_auth.error_handler
20
def unauthorized_error():
21
  return unauthorized('Please authenticate to access this API')
22
23
24
@token.route('/request-token')
25
@no_cache
26
@token_auth.login_required
27
@json
28
def request_token():
29
  return {'token': g.user.generate_auth_token()}
30