Skip to content

Commit

Permalink
add password change page
Browse files Browse the repository at this point in the history
  • Loading branch information
gothack329 committed Mar 6, 2018
1 parent 062eb3b commit 6872930
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 12 deletions.
Binary file modified article/templatetags/__pycache__/timetonow.cpython-36.pyc
Binary file not shown.
11 changes: 7 additions & 4 deletions article/templatetags/timetonow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ def timetonow(value):

s = delta.total_seconds()
if s>86400:
return '%d天前' % (int(s/86400))
if int(s%86400/3600) == 0:
return '%d天前' % (int(s/86400))
else:
return '%d天%d小时前' % (int(s/86400),s%86400/3600)
elif s>3600:
return '%d小时前' % (int(s/3600))
return '%d小时前' % (int(s/3600))
elif s>120:
return '%d分钟前' % (int(s/60))
return '%d分钟前' % (int(s/60))
else:
return '刚刚'
return '刚刚'

timetonow.is_safe = True
Binary file modified db.sqlite3
Binary file not shown.
Binary file modified userpage/__pycache__/models.cpython-36.pyc
Binary file not shown.
Binary file modified userpage/__pycache__/urls.cpython-36.pyc
Binary file not shown.
Binary file modified userpage/__pycache__/views.cpython-36.pyc
Binary file not shown.
18 changes: 18 additions & 0 deletions userpage/migrations/0009_profile_telegram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.0.2 on 2018-03-06 13:59

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('userpage', '0008_auto_20180305_1717'),
]

operations = [
migrations.AddField(
model_name='profile',
name='telegram',
field=models.CharField(blank=True, max_length=128),
),
]
Binary file not shown.
8 changes: 8 additions & 0 deletions userpage/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Profile(models.Model):
instagram = models.CharField(max_length=128, blank=True)
facebook = models.CharField(max_length=128, blank=True)
twitter = models.CharField(max_length=128, blank=True)
telegram = models.CharField(max_length=128, blank=True)


def __str__(self):
Expand All @@ -48,6 +49,13 @@ class Meta:
}
widgets = {
'avatar':ClearableFileInput(attrs={'class':'form-control','placeholder':"头像"}),
'mobile':TextInput(attrs={'class':'form-control'}),
'weibo':TextInput(attrs={'class':'form-control'}),
'wechat':TextInput(attrs={'class':'form-control'}),
'facebook':TextInput(attrs={'class':'form-control'}),
'twitter':TextInput(attrs={'class':'form-control'}),
'instagram':TextInput(attrs={'class':'form-control'}),
'telegram':TextInput(attrs={'class':'form-control'}),
}


Expand Down
52 changes: 52 additions & 0 deletions userpage/templates/userpage/change.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{% extends 'base.html' %}
{% load timetonow %}

{% block header %}
<title> 物志 › {{request.user}} </title>


{% endblock %}

{% block banner %}
<div style="height:30px">
<p></p>
</div>
{% endblock %}

{% block content %}
<div class="card">
<form class="form-inline " method="post" action="" novalidate>{% csrf_token %}
<a href="/">物志</a> › 修改密码
<hr>
{{form.as_p}}
<p style="text-align:center">
<button class="btn btn-primary" type="submit" >确认修改</button>
</p>
</form>
</div>



{% if messages %}
{% for m in messages %}
<script type="text/javascript">
$.notify({
// options
message: '{{ m|escape }}',
},{
// settings
type: 'danger',
delay: 5000,
timer: 1000,
animate: {
enter: 'animated flipInY',
exit: 'animated flipOutX'
},
},);
</script>
{% endfor %}
{% endif %}



{% endblock %}
43 changes: 36 additions & 7 deletions userpage/templates/userpage/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,35 @@
</div>

<div class="profile-tab" >
<p></p>
{% for i in points %}
<div class="row member_comments">
<p>{{i.record_time|timetonow}},{{i.get_event_display}},{{i.point_record}}</p>
</div>
{% endfor %}
<table class="table">
<thead>
<th>时间</th>
<th>记录</th>
<th>积分</th>
</thead>
{% for i in points %}
<tr>
<td>{{i.record_time}}</td>
<td>{{i.get_event_display}}</td>
<td class="pointrecord">{{i.point_record}}</td>
</tr>
{% endfor %}
</table>
<script type="text/javascript">
$(function(){
$('.pointrecord').each(function(){
if($(this).text()>0){
const value = $(this).text();
$(this).text('+'+value);
$(this).css('color','#47830d');
} else {
$(this).css('color','#d73a49');
}
})
})
</script>
</div>


<div class="profile-tab" >
{# 编辑资料 #}
<p></p>
Expand All @@ -163,6 +183,15 @@
<p style="text-align:center"><label style="width:100px;text-align:right" for="first_name">名:</label>{{ user_form.first_name}}</p>
<p style="text-align:center"><label style="width:100px;text-align:right" for="last_name">姓:</label>{{ user_form.last_name}}</p>
<p style="text-align:center"><label style="width:100px;text-align:right" for="email">邮箱:</label>{{ user_form.email}}</p>
<p style="text-align:center"><label style="width:100px;text-align:right" for="mobile">手机:</label>{{ profile_form.mobile}}</p>
<p style="text-align:center"><label style="width:100px;text-align:right" for="wechat">微信:</label>{{ profile_form.wechat}}</p>
<p style="text-align:center"><label style="width:100px;text-align:right" for="weibo">微博:</label>{{ profile_form.weibo}}</p>
<p style="text-align:center"><label style="width:100px;text-align:right" for="facebook">Facebook:</label>{{ profile_form.facebook}}</p>
<p style="text-align:center"><label style="width:100px;text-align:right" for="twitter">Twitter:</label>{{ profile_form.twitter}}</p>
<p style="text-align:center"><label style="width:100px;text-align:right" for="instagram">Instagram:</label>{{ profile_form.instagram}}</p>
<p style="text-align:center"><label style="width:100px;text-align:right" for="telegram">Telegram:</label>{{ profile_form.telegram}}</p>

<p style="text-align:center"><a href="/userpage/change_password/">修改密码</a></p>

<button type="submit" class="btn btn-default pull-right">保存资料</button>
</form>
Expand Down
1 change: 1 addition & 0 deletions userpage/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
path('login/', views.userlogin, name='login'),
path('logout/', views.userlogout, name='logout'),
path('register/', views.register, name='register'),
path('change_password/', views.password_change, name='password_change'),
]
20 changes: 19 additions & 1 deletion userpage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from django.contrib.auth import authenticate, login
from django.contrib.auth import logout
from django.contrib.auth.models import User
from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth import update_session_auth_hash

# Create your views here.

Expand Down Expand Up @@ -147,4 +149,20 @@ def register(request):
obj = forms.RegisterForm()
return render(request,'userpage/register.html',{'form':obj,'referer':refer})


@login_required
def password_change(request):
if request.method == 'POST':
form = PasswordChangeForm(user=request.user, data=request.POST)
if form.is_valid():
form.save()
update_session_auth_hash(request, form.user)
print(dir(form))
messages.success(request,'密码修改成功!')
else:
messages.error(request,form.errors)
print(dir(messages))
return redirect('.')
else:
form = PasswordChangeForm(user=request.user)
return render(request,'userpage/change.html',{'form':form})

0 comments on commit 6872930

Please sign in to comment.