mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-30 06:21:50 -05:00
Changes as per code review comments.
Fix my backward date math :P
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import random
|
||||
from datetime import (datetime, timedelta)
|
||||
|
||||
from sqlalchemy import func
|
||||
|
||||
from app import db
|
||||
from app.models import (User, VerifyCode)
|
||||
|
||||
@@ -48,7 +46,7 @@ def get_user_code(user, code, code_type):
|
||||
# time searching for the correct code.
|
||||
codes = VerifyCode.query.filter_by(
|
||||
user=user, code_type=code_type).order_by(
|
||||
VerifyCode.created_at.desc())
|
||||
VerifyCode.created_at.desc())
|
||||
retval = None
|
||||
for x in codes:
|
||||
if x.check_code(code):
|
||||
@@ -86,7 +84,8 @@ def count_user_verify_codes(user):
|
||||
query = db.session.query(
|
||||
func.count().label('count')
|
||||
).filter(VerifyCode.user == user,
|
||||
VerifyCode.expiry_datetime <= datetime.utcnow()).one()
|
||||
VerifyCode.expiry_datetime > datetime.utcnow(),
|
||||
VerifyCode.code_used.is_(False)).one()
|
||||
return query.count
|
||||
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ def send_user_sms_code(user_id):
|
||||
|
||||
if count_user_verify_codes(user_to_send_to) >= current_app.config.get('MAX_VERIFY_CODE_COUNT'):
|
||||
# Prevent more than `MAX_VERIFY_CODE_COUNT` active verify codes at a time
|
||||
current_app.logger.warn('Max verify code has exceeded for user {}'.format(user_to_send_to.id))
|
||||
return jsonify({}), 204
|
||||
|
||||
secret_code = create_secret_code()
|
||||
|
||||
Reference in New Issue
Block a user