Skip to content

Commit 4a3f80b

Browse files
committed
Fix registration activation page
On branch 22.01.1 Changes to be committed: modified: bco_api/api/scripts/method_specific/GET_activate_account.py new file: bco_api/api/scripts/method_specific/__init__.py new file: bco_api/api/scripts/utilities/__init__.py modified: bco_api/api/templates/api/account_activation_message.html modified: bco_api/api/views.py
1 parent fdaacf1 commit 4a3f80b

File tree

5 files changed

+43
-69
lines changed

5 files changed

+43
-69
lines changed
Lines changed: 42 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,64 @@
1-
# For interacting with the database
2-
from ..utilities import DbUtils
1+
#!/usr/bin/env python3
2+
"""Activate Account
33
4-
# For the user lookup
5-
from django.contrib.auth.models import User
4+
"""
65

6+
from api.scripts.utilities import DbUtils
7+
8+
# For url
9+
from django.conf import settings
710
# Responses
811
from rest_framework import status
912
from rest_framework.response import Response
1013

11-
1214
# Source: https://codeloop.org/django-rest-framework-course-for-beginners/
1315

14-
def GET_activate_account(
15-
username,
16-
temp_identifier
17-
):
18-
# Activate an account that is stored in the temporary table.
16+
def GET_activate_account(username,temp_identifier):
17+
"""Activate Account
1918
20-
# Instantiate any necessary imports.
21-
db = DbUtils.DbUtils()
19+
Parameters
20+
----------
21+
request: rest_framework.request.Request
22+
Django request object.
2223
23-
# Does the account associated with this e-mail already
24-
# exist in either a temporary or a permanent user profile?
25-
# if User.objects.filter(email=username).exists():
26-
# # TODO: This doesn't work since the username is the prefix of the email plus a random seed
27-
# # (so we can't actually check). So this can only be true if there is a clash.
28-
# # Account has already been activated.
29-
# return (Response({
30-
# 'previously_activated': True,
31-
# 'username' : username,
32-
# 'status' : status.HTTP_208_ALREADY_REPORTED,
33-
# },
34-
# status=status.HTTP_208_ALREADY_REPORTED)
35-
# )
24+
Returns
25+
-------
26+
rest_framework.response.Response
27+
An HttpResponse that allows its data to be rendered into
28+
arbitrary media types.
29+
"""
30+
# Activate an account that is stored in the temporary table.
31+
32+
db_utils = DbUtils.DbUtils()
3633

3734
# The account has not been activated, but does it exist
3835
# in the temporary table?
39-
if db.check_activation_credentials(
36+
if db_utils.check_activation_credentials(
4037
p_app_label='api',
4138
p_model_name='new_users',
4239
p_email=username,
4340
p_temp_identifier=temp_identifier
44-
) == 1:
45-
41+
):
4642

4743
# The credentials match, so activate the account.
48-
credential_try = db.activate_account(
49-
p_email=username
50-
)
44+
credential_try = db_utils.activate_account(p_email=username)
5145

5246
if len(credential_try) > 0:
5347
# Everything went fine.
54-
return (
55-
Response(
56-
{
57-
'activation_success': True,
58-
'username' : credential_try[0],
59-
'status': status.HTTP_201_CREATED,
60-
61-
},
62-
status=status.HTTP_201_CREATED
63-
)
64-
)
65-
66-
else:
67-
68-
# The credentials weren't good.
69-
return (
70-
Response(
71-
{
72-
'activation_success': False,
73-
'status' : status.HTTP_403_FORBIDDEN
74-
},
75-
status=status.HTTP_403_FORBIDDEN
76-
)
77-
)
78-
79-
else:
80-
81-
return (
82-
Response(
83-
{
84-
'activation_success': False,
85-
'status' : status.HTTP_424_FAILED_DEPENDENCY
86-
},
87-
status=status.HTTP_424_FAILED_DEPENDENCY
88-
)
89-
)
48+
return (Response({
49+
'activation_success': True,
50+
'activation_url': settings.PUBLIC_HOSTNAME+'/login/',
51+
'username': credential_try[0],
52+
'status': status.HTTP_201_CREATED,
53+
}, status=status.HTTP_201_CREATED))
54+
55+
# The credentials weren't good.
56+
return(Response({
57+
'activation_success': False,
58+
'status' : status.HTTP_403_FORBIDDEN},
59+
status=status.HTTP_403_FORBIDDEN))
60+
61+
return(Response({
62+
'activation_success': False,
63+
'status': status.HTTP_424_FAILED_DEPENDENCY},
64+
status=status.HTTP_424_FAILED_DEPENDENCY))

bco_api/api/scripts/method_specific/__init__.py

Whitespace-only changes.

bco_api/api/scripts/utilities/__init__.py

Whitespace-only changes.

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>

bco_api/api/views.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ class ApiAccountsNew(APIView):
412412
500: "Unable to save the new account or send authentication email."
413413
}, tags=["Account Management"])
414414
def post(self, request) -> Response:
415-
import pdb; pdb.set_trace()
416415
print("Request: {}".format(request))
417416
return check_post_and_process(request, POST_api_accounts_new)
418417

0 commit comments

Comments
 (0)