Skip to content
Snippets Groups Projects
Commit e5913055 authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB
Browse files

updating lvem password management page

parent 09d50e89
No related branches found
No related tags found
No related merge requests found
......@@ -6,24 +6,30 @@
{% block content %}
<p> Passwords generated here are intended only for scripted access to GraceDB by LV-EM users. Your password allows access to the <a href={% url "basic:api-root" %}>REST API</a>. </p>
<p>Passwords generated here are intended only for scripted access to GraceDB by LV-EM users. Your password allows access to the <a href={% url "basic:api-root" %}>REST API</a>.</p>
<p> Your username is: <span style="color: red"> {{ username }} </span> </p>
<p> Your username is: <b>{{ username }}</b></p>
{% if has_password %}
{% if password %}
<p>Your password is: <b>{{ password }}</b></p>
{% endif %}
{% if expired %}
<p>Your password has <b>expired</b>. Please generate a new one by clicking the button below.</p>
{% else %}
<p>Your password expires in <b>{{ expiration_days }} days.</b></p>
{% endif %}
{% if password %}
<p>Your password is: <span style="color: red">{{ password }}</span></p>
{% else %}
<p>You do not currently have a password set.</p>
{% endif %}
<br/>
<p> Press the button here to get a new password (or change your existing one): </p>
<p>Press the button here to get a new password (or change your existing one):</p>
<form action={% url "userprofile-manage-password" %} method="post">
<input type="submit" value="Get me a password!">
</form>
<p><b>Note:</b>Clicking this button has the effect of changing your password, and any old passwords will no longer work. Also, passwords will expire after one year.</p>
<p><b>Note:</b> clicking this button has the effect of changing your password, and any old passwords will no longer work. Also, passwords will expire after one year.</p>
{% endblock %}
......@@ -38,13 +38,31 @@ def index(request):
@lvem_user_required
def managePassword(request):
# Set up context dictionary
d = { 'username': request.user.username }
if request.method == "POST":
password = User.objects.make_random_password(length=20)
d['password'] = password
request.user.set_password(password)
request.user.date_joined = timezone.now()
request.user.save()
if request.user.has_usable_password():
d['has_password'] = True
# Check if password is expired
# NOTE: This is super hacky because we are using date_joined to store
# the date when the password was set.
password_expiry = request.user.date_joined + \
settings.PASSWORD_EXPIRATION_TIME - timezone.now()
if (password_expiry.total_seconds() < 0):
d['expired'] = True
else:
d['expired'] = False
d['expiration_days'] = password_expiry.days
else:
d['has_password'] = False
return render(request, 'profile/manage_password.html', context=d)
@internal_user_required
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment