Skip to content

Commit e705d7e

Browse files
committed
Fix account activation messages
Changes to be committed: modified: bco_api/api/scripts/method_specific/GET_activate_account.py modified: bco_api/api/scripts/method_specific/POST_api_accounts_new.py modified: bco_api/api/templates/api/account_activation_message.html
1 parent 9e06f00 commit e705d7e

File tree

3 files changed

+24
-42
lines changed

3 files changed

+24
-42
lines changed

bco_api/api/scripts/method_specific/GET_activate_account.py

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33

44
# For the user lookup
55
from django.contrib.auth.models import User
6-
6+
# For url
7+
from django.conf import settings
78
# Responses
89
from rest_framework import status
910
from rest_framework.response import Response
1011

1112

1213
# Source: https://codeloop.org/django-rest-framework-course-for-beginners/
1314

14-
def GET_activate_account(
15-
username,
16-
temp_identifier
17-
):
15+
def GET_activate_account(username,temp_identifier):
1816
# Activate an account that is stored in the temporary table.
1917

2018
# Instantiate any necessary imports.
@@ -44,45 +42,27 @@ def GET_activate_account(
4442
):
4543

4644
# The credentials match, so activate the account.
47-
credential_try = db.activate_account(
48-
p_email=username
49-
)
45+
credential_try = db.activate_account(p_email=username)
5046

5147
if len(credential_try) > 0:
5248
# Everything went fine.
53-
return (
54-
Response(
55-
{
56-
'activation_success': True,
57-
'username' : credential_try[0],
58-
'status': status.HTTP_201_CREATED,
59-
60-
},
61-
status=status.HTTP_201_CREATED
62-
)
63-
)
49+
return (Response({
50+
'activation_success': True,
51+
'activation_url': settings.PUBLIC_HOSTNAME+'/login/',
52+
'username': credential_try[0],
53+
'status': status.HTTP_201_CREATED,
54+
},
55+
status=status.HTTP_201_CREATED))
6456

6557
else:
66-
6758
# The credentials weren't good.
68-
return (
69-
Response(
70-
{
71-
'activation_success': False,
72-
'status' : status.HTTP_403_FORBIDDEN
73-
},
74-
status=status.HTTP_403_FORBIDDEN
75-
)
76-
)
59+
return(Response({
60+
'activation_success': False,
61+
'status' : status.HTTP_403_FORBIDDEN},
62+
status=status.HTTP_403_FORBIDDEN))
7763

7864
else:
79-
80-
return (
81-
Response(
82-
{
83-
'activation_success': False,
84-
'status' : status.HTTP_424_FAILED_DEPENDENCY
85-
},
86-
status=status.HTTP_424_FAILED_DEPENDENCY
87-
)
88-
)
65+
return(Response({
66+
'activation_success': False,
67+
'status': status.HTTP_424_FAILED_DEPENDENCY},
68+
status=status.HTTP_424_FAILED_DEPENDENCY))

bco_api/api/scripts/method_specific/POST_api_accounts_new.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ def POST_api_accounts_new(request):
110110
print('activation_link', activation_link)
111111
# print('ERROR: ', e)
112112
# TODO: Should handle when the send_mail function fails?
113-
return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR, data={"message": "Not able to send authentication email: {}".format(e)})
114-
return Response(status=status.HTTP_201_CREATED)
113+
# return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR, data={"message": "Not able to send authentication email: {}".format(e)})
114+
return Response(status=status.HTTP_201_CREATED, data={"message": "Account has been requested. Activation email was not sent. Check with your database administrator for activation of your api account"})
115+
116+
return Response(status=status.HTTP_201_CREATED, data={"message": "Account has been requested. Activation email has been sent"})
115117

116118
else:
117119

bco_api/api/templates/api/account_activation_message.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
{% else %}
3535
<p>Unsuccessful activation! The account may not have been requested or may have already been activated. Please request another activation e-mail on the Portal.</p>
3636
{% endif %}
37-
<button type = 'button'><a href = 'http://beta.portal.aws.biochemistry.gwu.edu/login/' target = '_blank'>Open Portal in new tab</a></button>
37+
<button type = 'button'><a href = {{ activation_url }}>Open Portal in new tab</a></button>
3838
</div>
3939
</body>
4040
</html>

0 commit comments

Comments
 (0)