mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-05 06:01:46 -04:00
Merge with master.
This commit is contained in:
20
app/utils.py
20
app/utils.py
@@ -1,3 +1,5 @@
|
||||
import re
|
||||
|
||||
from functools import wraps
|
||||
from flask import (abort, session)
|
||||
|
||||
@@ -28,6 +30,11 @@ class BrowsableItem(object):
|
||||
pass
|
||||
|
||||
|
||||
class InvalidEmailError(Exception):
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
|
||||
|
||||
class InvalidPhoneError(Exception):
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
@@ -74,6 +81,19 @@ def format_phone_number(number):
|
||||
return '+447{}{}{}'.format(*re.findall('...', number))
|
||||
|
||||
|
||||
def validate_email_address(email_address):
|
||||
if re.match(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", email_address):
|
||||
return
|
||||
raise InvalidEmailError('Not a valid email address')
|
||||
|
||||
|
||||
def validate_recipient(recipient, template_type):
|
||||
return {
|
||||
'email': validate_email_address,
|
||||
'sms': validate_phone_number
|
||||
}[template_type](recipient)
|
||||
|
||||
|
||||
def user_has_permissions(*permissions):
|
||||
def wrap(func):
|
||||
@wraps(func)
|
||||
|
||||
Reference in New Issue
Block a user