Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
21 changes: 15 additions & 6 deletions freenit/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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


Expand Down
7 changes: 7 additions & 0 deletions freenit/project/common_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down