Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoducer committed Sep 9, 2019
1 parent 62e33cd commit aa7cd71
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 29 deletions.
Binary file modified diary_app/__pycache__/forms.cpython-36.pyc
Binary file not shown.
Binary file modified diary_app/__pycache__/views.cpython-36.pyc
Binary file not shown.
61 changes: 61 additions & 0 deletions diary_app/templates/users/changepassword.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Change password - Daily Bytes</title>
<link href="https://fonts.googleapis.com/css?family=Abril+Fatface|Libre+Franklin|Playfair+Display&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
{% load static %}
<link rel="stylesheet" href="{% static '/css/auth.css' %}">

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-147095017-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'UA-147095017-1');
</script>
</head>
<body>
<div class="signin-form">
<form method="POST">
{% csrf_token %}
<h2>Daily Bytes</h2>

<div class="text-center medium" style="margin-top: 10px; margin-bottom: 16px;">Write your hearts out byte by byte</div>

<div class="text-center medium" style="margin-top: 20px; margin-bottom: 16px; font-size: 20px;">
{% if user.first_name %}
You are {{ user.first_name }}
{% elif user.username %}
You are {{ user.username }}
{% endif %}
</div>

<div class="form-group">
<input type="password" class="form-control input-lg" name="old_password" placeholder="Current password" required="required">
</div>
<div class="form-group">
<input type="password" class="form-control input-lg" name="new_password1" placeholder="New password" required="required">
</div>
<div class="form-group">
<input type="password" class="form-control input-lg" name="new_password2" placeholder="Confirm password" required="required">
{{form.errors}}
</div>

<div class="form-group">
<button type="submit" class="btn btn-success btn-lg btn-block signup-btn">Submit</button>
</div>
<div class="text-center medium" style="margin-top: 10px;">Back to <a href="/profile/">profile</a></div>

</form>
</div>
</body>
</html>
24 changes: 2 additions & 22 deletions diary_app/templates/users/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,13 @@ <h1 class="title">

<div class="field">
<div class="control">
{{nuform}}

<h6 class="subtitle is-6" style="margin-bottom: 10px;">Username</h6>
<input type="text" name="username" maxlength=50 class="input is-medium edit-title" value="{{current_user.username}}" required id="id_username">

<h6 class="subtitle is-6" style="margin-bottom: 10px;">Email</h6>
<input type="email" name="email" class="input is-medium edit-title" value="{{current_user.email}}" id="id_email" disabled>

{% if request.user.has_usable_password is True %}
<h6 class="subtitle is-6" style="margin-bottom: 10px;">Current password</h6>
<input type="password" name="old_password" class="input is-medium edit-title" id="id_password1">

<h6 class="subtitle is-6" style="margin-bottom: 10px;">New password</h6>
<input type="password" name="new_password1" class="input is-medium edit-title" id="id_password1">

<h6 class="subtitle is-6" style="margin-bottom: 10px;">Confirm password</h6>
<input type="password" name="new_password2" class="input is-medium edit-title" id="id_password2">
{% endif %}

<!-- {% if request.user.has_usable_password is False %}
<h6 class="subtitle is-6" style="margin-bottom: 10px;">Set a password</h6>
<input type="password" name="password1" class="input is-medium edit-title" id="id_password1">
<h6 class="subtitle is-6" style="margin-bottom: 10px;">Confirm password</h6>
<input type="password" name="password2" class="input is-medium edit-title" id="id_password2">
{% endif %} -->

{{form.error}}

<h6 class="subtitle is-6" style="margin-bottom: 10px;">First name</h6>
<input type="text" name="first_name" maxlength="50" class="input is-medium edit-title" value="{{current_user.first_name}}" required id="id_title">

Expand All @@ -77,6 +56,7 @@ <h6 class="subtitle is-6" style="margin-bottom: 10px;">Bio</h6>
</div>

<div class="buttons is-right">
<a class="button is-info is-outlined" href="/change-password/?next=/profile/">Change password</a>

<button class="button is-success is-outlined" type="submit"><img src="{% static '/images/save.svg' %}" alt="Save" width=15px height=15px style="margin-right: 10px;">Save profile</button>

Expand Down
25 changes: 19 additions & 6 deletions diary_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,30 @@ def Profile(request):
if request.method == 'POST':
uform = UserUpdateForm(request.POST, instance=current_user)
puform = ProfileUpdateForm(request.POST, instance=get_bio)
pcform = PasswordChangeForm(request.user, request.POST)

if uform.is_valid() and puform.is_valid() and pcform.is_valid():
if uform.is_valid() and puform.is_valid():
puform.save()
uform.save()
pwd = pcform.save()
update_session_auth_hash(request, pwd)
return redirect('home')
else:
uform = UserUpdateForm()
puform = ProfileUpdateForm()
pcform = PasswordChangeForm(request.user)

return render(request, "users/profile.html", {'uform': uform, 'puform': puform, 'pcform': pcform, 'current_user': current_user, 'get_bio': get_bio})
return render(request, "users/profile.html", {'uform': uform, 'puform': puform, 'current_user': current_user, 'get_bio': get_bio})


@login_required
def ChangePassword(request):
if request.method == 'POST':
pcform = PasswordChangeForm(request.user, request.POST)

if pcform.is_valid():
pwd = pcform.save()
update_session_auth_hash(request, pwd)
return redirect(request.GET.get('next'))
else:
return redirect(request.GET.get('next'))
else:
pcform = PasswordChangeForm(request.user)

return render(request, "users/changepassword.html", {'pcform': pcform})
Binary file modified diary_proj/__pycache__/settings.cpython-36.pyc
Binary file not shown.
Binary file modified diary_proj/__pycache__/urls.cpython-36.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion diary_proj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
path('profile/', views.Profile, name='profile'),
path('restore/<int:id>', views.restore),
path('confirm-delete/<int:id>', views.confirmdelete),
path('social-signup/', views.SocialSignUp, name='social-signup')
path('social-signup/', views.SocialSignUp, name='social-signup'),
path('change-password/', views.ChangePassword)

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

0 comments on commit aa7cd71

Please sign in to comment.