diff --git a/common_config.py b/common_config.py index 86434ac..c4a2a4e 100644 --- a/common_config.py +++ b/common_config.py @@ -39,6 +39,11 @@ class Config: # 'password': 'Sekrit', } FROM_EMAIL = 'office@example.com' + SUBJECTS = { + 'prefix': '[Freenit] ', + 'confirm': 'Account confirmation', + 'register': 'Account registration', + } @staticmethod def init_app(app): diff --git a/freenit/api/auth.py b/freenit/api/auth.py index e811ada..50e2423 100644 --- a/freenit/api/auth.py +++ b/freenit/api/auth.py @@ -140,11 +140,13 @@ def post(self, args): } host = request.headers.get('Origin', request.url_root) requestToken = create_access_token(identity, expires_delta=expires) - url = f'{host}/register/{requestToken}' + url = f'{host}/confirm/{requestToken}' msg = MIMEText(url, 'plain', 'utf-8') + config = current_app.config + subject = config['SUBJECTS']['prefix'] + config['SUBJECTS']['register'] msg['To'] = user.email - msg['From'] = current_app.config['FROM_EMAIL'] - msg['Subject'] = 'Freenit message' + msg['From'] = config['FROM_EMAIL'] + msg['Subject'] = subject current_app.sendmail(msg) return user @@ -162,11 +164,18 @@ def get(self, token): user = User.get(id=identity['id']) except User.DoesNotExist: abort(404, message='User does not exist') + if user.active: + abort(409, message='User already activated') + user.active = True + user.save() text = 'Congratulation, your account is confirmed' msg = MIMEText(text, 'plain', 'utf-8') - msg['From'] = current_app.config['FROM_EMAIL'] - msg['Subject'] = 'Freenit message' - current_app.sendmail(user.email, msg) + config = current_app.config + subject = config['SUBJECTS']['prefix'] + config['SUBJECTS']['confirm'] + msg['To'] = user.email + msg['From'] = config['FROM_EMAIL'] + msg['Subject'] = subject + current_app.sendmail(msg) return user diff --git a/freenit/project/common_config.py b/freenit/project/common_config.py index a765990..6c65f30 100644 --- a/freenit/project/common_config.py +++ b/freenit/project/common_config.py @@ -29,6 +29,7 @@ class Config: OPENAPI_VERSION = '2.0.0' MEDIA_URL = '/media' MEDIA_PATH = 'media' + ACCOUNT_REQUEST_EXPIRY = 24 # in hours PASSWORD_RESET_EXPIRY = 2 # in hours DATABASE = { 'name': 'database.db', @@ -41,6 +42,12 @@ class Config: # 'username': 'someone@example.com', # 'password': 'Sekrit', } + FROM_EMAIL = 'office@example.com' + SUBJECTS = { + 'prefix': '[Freenit] ', + 'confirm': 'Account confirmation', + 'register': 'Account registration', + } @staticmethod def init_app(app): diff --git a/setup.py b/setup.py index 658a0ee..7ca9000 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name='freenit', - version='0.0.24', + version='0.0.25', description='REST API framework based on Flask-Smorest', long_description=README, long_description_content_type='text/markdown',