Skip to content

Commit

Permalink
Fix account activation messages
Browse files Browse the repository at this point in the history
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
  • Loading branch information
HadleyKing committed Dec 3, 2021
1 parent 9e06f00 commit e705d7e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 42 deletions.
58 changes: 19 additions & 39 deletions bco_api/api/scripts/method_specific/GET_activate_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@

# For the user lookup
from django.contrib.auth.models import User

# For url
from django.conf import settings
# Responses
from rest_framework import status
from rest_framework.response import Response


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

def GET_activate_account(
username,
temp_identifier
):
def GET_activate_account(username,temp_identifier):
# Activate an account that is stored in the temporary table.

# Instantiate any necessary imports.
Expand Down Expand Up @@ -44,45 +42,27 @@ def GET_activate_account(
):

# The credentials match, so activate the account.
credential_try = db.activate_account(
p_email=username
)
credential_try = db.activate_account(p_email=username)

if len(credential_try) > 0:
# Everything went fine.
return (
Response(
{
'activation_success': True,
'username' : credential_try[0],
'status': status.HTTP_201_CREATED,

},
status=status.HTTP_201_CREATED
)
)
return (Response({
'activation_success': True,
'activation_url': settings.PUBLIC_HOSTNAME+'/login/',
'username': credential_try[0],
'status': status.HTTP_201_CREATED,
},
status=status.HTTP_201_CREATED))

else:

# The credentials weren't good.
return (
Response(
{
'activation_success': False,
'status' : status.HTTP_403_FORBIDDEN
},
status=status.HTTP_403_FORBIDDEN
)
)
return(Response({
'activation_success': False,
'status' : status.HTTP_403_FORBIDDEN},
status=status.HTTP_403_FORBIDDEN))

else:

return (
Response(
{
'activation_success': False,
'status' : status.HTTP_424_FAILED_DEPENDENCY
},
status=status.HTTP_424_FAILED_DEPENDENCY
)
)
return(Response({
'activation_success': False,
'status': status.HTTP_424_FAILED_DEPENDENCY},
status=status.HTTP_424_FAILED_DEPENDENCY))
6 changes: 4 additions & 2 deletions bco_api/api/scripts/method_specific/POST_api_accounts_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ def POST_api_accounts_new(request):
print('activation_link', activation_link)
# print('ERROR: ', e)
# TODO: Should handle when the send_mail function fails?
return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR, data={"message": "Not able to send authentication email: {}".format(e)})
return Response(status=status.HTTP_201_CREATED)
# return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR, data={"message": "Not able to send authentication email: {}".format(e)})
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"})

return Response(status=status.HTTP_201_CREATED, data={"message": "Account has been requested. Activation email has been sent"})

else:

Expand Down
2 changes: 1 addition & 1 deletion bco_api/api/templates/api/account_activation_message.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
{% else %}
<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>
{% endif %}
<button type = 'button'><a href = 'http://beta.portal.aws.biochemistry.gwu.edu/login/' target = '_blank'>Open Portal in new tab</a></button>
<button type = 'button'><a href = {{ activation_url }}>Open Portal in new tab</a></button>
</div>
</body>
</html>

0 comments on commit e705d7e

Please sign in to comment.