Skip to content

Commit aa7cd71

Browse files
committed
update
1 parent 62e33cd commit aa7cd71

File tree

8 files changed

+84
-29
lines changed

8 files changed

+84
-29
lines changed
29 Bytes
Binary file not shown.
217 Bytes
Binary file not shown.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>Change password - Daily Bytes</title>
8+
<link href="https://fonts.googleapis.com/css?family=Abril+Fatface|Libre+Franklin|Playfair+Display&display=swap" rel="stylesheet">
9+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
10+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
11+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
12+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
13+
{% load static %}
14+
<link rel="stylesheet" href="{% static '/css/auth.css' %}">
15+
16+
<!-- Global site tag (gtag.js) - Google Analytics -->
17+
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-147095017-1"></script>
18+
<script>
19+
window.dataLayer = window.dataLayer || [];
20+
function gtag(){dataLayer.push(arguments);}
21+
gtag('js', new Date());
22+
23+
gtag('config', 'UA-147095017-1');
24+
</script>
25+
</head>
26+
<body>
27+
<div class="signin-form">
28+
<form method="POST">
29+
{% csrf_token %}
30+
<h2>Daily Bytes</h2>
31+
32+
<div class="text-center medium" style="margin-top: 10px; margin-bottom: 16px;">Write your hearts out byte by byte</div>
33+
34+
<div class="text-center medium" style="margin-top: 20px; margin-bottom: 16px; font-size: 20px;">
35+
{% if user.first_name %}
36+
You are {{ user.first_name }}
37+
{% elif user.username %}
38+
You are {{ user.username }}
39+
{% endif %}
40+
</div>
41+
42+
<div class="form-group">
43+
<input type="password" class="form-control input-lg" name="old_password" placeholder="Current password" required="required">
44+
</div>
45+
<div class="form-group">
46+
<input type="password" class="form-control input-lg" name="new_password1" placeholder="New password" required="required">
47+
</div>
48+
<div class="form-group">
49+
<input type="password" class="form-control input-lg" name="new_password2" placeholder="Confirm password" required="required">
50+
{{form.errors}}
51+
</div>
52+
53+
<div class="form-group">
54+
<button type="submit" class="btn btn-success btn-lg btn-block signup-btn">Submit</button>
55+
</div>
56+
<div class="text-center medium" style="margin-top: 10px;">Back to <a href="/profile/">profile</a></div>
57+
58+
</form>
59+
</div>
60+
</body>
61+
</html>

diary_app/templates/users/profile.html

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,34 +36,13 @@ <h1 class="title">
3636

3737
<div class="field">
3838
<div class="control">
39-
{{nuform}}
39+
4040
<h6 class="subtitle is-6" style="margin-bottom: 10px;">Username</h6>
4141
<input type="text" name="username" maxlength=50 class="input is-medium edit-title" value="{{current_user.username}}" required id="id_username">
4242

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

46-
{% if request.user.has_usable_password is True %}
47-
<h6 class="subtitle is-6" style="margin-bottom: 10px;">Current password</h6>
48-
<input type="password" name="old_password" class="input is-medium edit-title" id="id_password1">
49-
50-
<h6 class="subtitle is-6" style="margin-bottom: 10px;">New password</h6>
51-
<input type="password" name="new_password1" class="input is-medium edit-title" id="id_password1">
52-
53-
<h6 class="subtitle is-6" style="margin-bottom: 10px;">Confirm password</h6>
54-
<input type="password" name="new_password2" class="input is-medium edit-title" id="id_password2">
55-
{% endif %}
56-
57-
<!-- {% if request.user.has_usable_password is False %}
58-
<h6 class="subtitle is-6" style="margin-bottom: 10px;">Set a password</h6>
59-
<input type="password" name="password1" class="input is-medium edit-title" id="id_password1">
60-
61-
<h6 class="subtitle is-6" style="margin-bottom: 10px;">Confirm password</h6>
62-
<input type="password" name="password2" class="input is-medium edit-title" id="id_password2">
63-
{% endif %} -->
64-
65-
{{form.error}}
66-
6746
<h6 class="subtitle is-6" style="margin-bottom: 10px;">First name</h6>
6847
<input type="text" name="first_name" maxlength="50" class="input is-medium edit-title" value="{{current_user.first_name}}" required id="id_title">
6948

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

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

8161
<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>
8262

diary_app/views.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,30 @@ def Profile(request):
217217
if request.method == 'POST':
218218
uform = UserUpdateForm(request.POST, instance=current_user)
219219
puform = ProfileUpdateForm(request.POST, instance=get_bio)
220-
pcform = PasswordChangeForm(request.user, request.POST)
221220

222-
if uform.is_valid() and puform.is_valid() and pcform.is_valid():
221+
if uform.is_valid() and puform.is_valid():
223222
puform.save()
224223
uform.save()
225-
pwd = pcform.save()
226-
update_session_auth_hash(request, pwd)
227224
return redirect('home')
228225
else:
229226
uform = UserUpdateForm()
230227
puform = ProfileUpdateForm()
231-
pcform = PasswordChangeForm(request.user)
232228

233-
return render(request, "users/profile.html", {'uform': uform, 'puform': puform, 'pcform': pcform, 'current_user': current_user, 'get_bio': get_bio})
229+
return render(request, "users/profile.html", {'uform': uform, 'puform': puform, 'current_user': current_user, 'get_bio': get_bio})
230+
231+
232+
@login_required
233+
def ChangePassword(request):
234+
if request.method == 'POST':
235+
pcform = PasswordChangeForm(request.user, request.POST)
236+
237+
if pcform.is_valid():
238+
pwd = pcform.save()
239+
update_session_auth_hash(request, pwd)
240+
return redirect(request.GET.get('next'))
241+
else:
242+
return redirect(request.GET.get('next'))
243+
else:
244+
pcform = PasswordChangeForm(request.user)
245+
246+
return render(request, "users/changepassword.html", {'pcform': pcform})
-58 Bytes
Binary file not shown.
46 Bytes
Binary file not shown.

diary_proj/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
path('profile/', views.Profile, name='profile'),
5454
path('restore/<int:id>', views.restore),
5555
path('confirm-delete/<int:id>', views.confirmdelete),
56-
path('social-signup/', views.SocialSignUp, name='social-signup')
56+
path('social-signup/', views.SocialSignUp, name='social-signup'),
57+
path('change-password/', views.ChangePassword)
5758

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

0 commit comments

Comments
 (0)