mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-05 20:51:49 +02:00
format code
This commit is contained in:
parent
d9a4389d42
commit
bbcc233cda
4 changed files with 15 additions and 6 deletions
|
@ -35,7 +35,9 @@ def need_auth(f):
|
|||
auth_token = auth_header.split(" ")[1]
|
||||
except IndexError:
|
||||
abort(401)
|
||||
project_id = Project.verify_token(auth_token, token_type="auth", project_id=project_id)
|
||||
project_id = Project.verify_token(
|
||||
auth_token, token_type="auth", project_id=project_id
|
||||
)
|
||||
if auth_token and project_id:
|
||||
project = Project.query.get(project_id)
|
||||
if project:
|
||||
|
|
|
@ -367,7 +367,8 @@ class Project(db.Model):
|
|||
:param token: Serialized TimedJsonWebToken
|
||||
:param token_type: Either "auth" for authentication (invalidated when project code changed),
|
||||
or "reset" for password reset (invalidated after expiration)
|
||||
:param project_id: Project ID. Used for token_type "auth" to use the password as serializer secret key.
|
||||
:param project_id: Project ID. Used for token_type "auth" to use the password as serializer
|
||||
secret key.
|
||||
:param max_age: Token expiration time (in seconds). Only used with token_type "reset"
|
||||
"""
|
||||
loads_kwargs = {}
|
||||
|
@ -378,7 +379,7 @@ class Project(db.Model):
|
|||
loads_kwargs["max_age"] = max_age
|
||||
else:
|
||||
project = Project.query.get(project_id)
|
||||
password = project.password if project is not None else ''
|
||||
password = project.password if project is not None else ""
|
||||
serializer = URLSafeSerializer(
|
||||
current_app.config["SECRET_KEY"] + password, salt=token_type
|
||||
)
|
||||
|
@ -390,7 +391,9 @@ class Project(db.Model):
|
|||
return None
|
||||
|
||||
data_project = data.get("project_id")
|
||||
return data_project if project_id is None or data_project == project_id else None
|
||||
return (
|
||||
data_project if project_id is None or data_project == project_id else None
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
|
|
@ -213,7 +213,9 @@ class APITestCase(IhatemoneyTestCase):
|
|||
"/api/projects/raclette/token", headers=self.get_auth("raclette")
|
||||
)
|
||||
decoded_resp = json.loads(resp.data.decode("utf-8"))
|
||||
resp = self.client.get(f"/authenticate?token={decoded_resp['token']}&project_id=raclette")
|
||||
resp = self.client.get(
|
||||
f"/authenticate?token={decoded_resp['token']}&project_id=raclette"
|
||||
)
|
||||
# Test that we are redirected.
|
||||
self.assertEqual(302, resp.status_code)
|
||||
|
||||
|
|
|
@ -206,7 +206,9 @@ def authenticate(project_id=None):
|
|||
# Try to get project_id from token first
|
||||
token = request.args.get("token")
|
||||
if token:
|
||||
project_id = Project.verify_token(token, token_type="auth", project_id=project_id)
|
||||
project_id = Project.verify_token(
|
||||
token, token_type="auth", project_id=project_id
|
||||
)
|
||||
token_auth = True
|
||||
else:
|
||||
token_auth = False
|
||||
|
|
Loading…
Reference in a new issue