Use utils function to parse datetime strings

Rather than hard-coding a format string in a bunch of different places
we can use the function we already have in utils.

This commit also refactors some logic around password resets to put the
date-parsing changes in the most sensible bit of the codebase, so it’s
clearer what the intention of the view-layer code is.
This commit is contained in:
Chris Hill-Scott
2020-01-21 12:23:30 +00:00
parent 87b2686875
commit d93866bc7e
4 changed files with 25 additions and 8 deletions

View File

@@ -1,5 +1,4 @@
import json
from datetime import datetime
from flask import (
current_app,
@@ -29,8 +28,7 @@ def new_password(token):
email_address = json.loads(token_data)['email']
user = User.from_email_address(email_address)
if user.password_changed_at and datetime.strptime(user.password_changed_at, '%Y-%m-%d %H:%M:%S.%f') > \
datetime.strptime(json.loads(token_data)['created_at'], '%Y-%m-%d %H:%M:%S.%f'):
if user.password_changed_more_recently_than(json.loads(token_data)['created_at']):
flash('The link in the email has already been used')
return redirect(url_for('main.index'))