Added account page. Allows user to change password. Closes #26
This commit is contained in:
parent
928bbe684e
commit
06cb191554
|
@ -1,5 +1,8 @@
|
|||
from django import forms
|
||||
from django.contrib.auth import authenticate
|
||||
from django.contrib.auth.forms import (
|
||||
PasswordChangeForm as DjangoPasswordChangeForm
|
||||
)
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
|
@ -36,3 +39,7 @@ class LoginForm(forms.Form):
|
|||
)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
class PasswordChangeForm(DjangoPasswordChangeForm):
|
||||
pass
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from django.conf.urls import patterns, url
|
||||
|
||||
from .views import LoginView, LogoutView, UserProfileView
|
||||
from .views import LoginView, LogoutView, UserProfileView, AccountView
|
||||
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
|
@ -14,4 +14,5 @@ urlpatterns = patterns(
|
|||
r'^user/(?P<username>[\w\d\-\.]+)/(?P<section>\w+)/$',
|
||||
UserProfileView.as_view(),
|
||||
name="profile"),
|
||||
url(r'^account/$', AccountView.as_view(), name='account'),
|
||||
)
|
||||
|
|
|
@ -3,12 +3,15 @@ from django.views.generic import View
|
|||
from django.template import RequestContext
|
||||
from django.shortcuts import render_to_response, get_object_or_404
|
||||
from django.contrib.auth import logout
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.http import HttpResponseRedirect, Http404
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth import login
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from .forms import LoginForm
|
||||
from .forms import LoginForm, PasswordChangeForm
|
||||
from .models import User
|
||||
from shelfzilla.apps.manga.models import (
|
||||
UserReadVolume, UserHaveVolume, UserWishlistVolume
|
||||
|
@ -105,3 +108,35 @@ class UserProfileView(View):
|
|||
context = method(request, context, user)
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class AccountView(View):
|
||||
template = 'account/main.html'
|
||||
|
||||
@method_decorator(login_required)
|
||||
def get(self, request):
|
||||
data = {
|
||||
'item': request.user,
|
||||
'form_password': PasswordChangeForm(request.user)
|
||||
}
|
||||
|
||||
ctx = RequestContext(request, data)
|
||||
return render_to_response(self.template, context_instance=ctx)
|
||||
|
||||
@method_decorator(login_required)
|
||||
def post(self, request):
|
||||
form_password = PasswordChangeForm(request.user, data=request.POST)
|
||||
|
||||
if form_password.is_valid():
|
||||
# Do stuff
|
||||
form_password.save()
|
||||
messages.success(request, _('Password changed.'))
|
||||
return HttpResponseRedirect(reverse('account'))
|
||||
|
||||
data = {
|
||||
'item': request.user,
|
||||
'form_password': form_password
|
||||
}
|
||||
|
||||
ctx = RequestContext(request, data)
|
||||
return render_to_response(self.template, context_instance=ctx)
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{% extends '_layout.html'|pjax:request %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block page_title %}{{ block.super }} | {% trans "Account" %}{% endblock %}
|
|
@ -0,0 +1,69 @@
|
|||
{% extends 'account/_layout.html'|pjax:request %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block main_content %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-sm-3 profile-sidebar">
|
||||
<div class="panel panel-primary">
|
||||
<div class="panel-heading text-center">
|
||||
<h1 class="panel-title">{{ item.username }}</h1>
|
||||
</div>
|
||||
<div class="avatar">
|
||||
<img src="{{ item.avatar }}" class="max-width-100" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-9" data-pjax-container="profile">
|
||||
{% comment %}
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h1 class="panel-title">{% trans "Details" %}</h1>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
Details form
|
||||
</div>
|
||||
</div>
|
||||
{% endcomment %}
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h1 class="panel-title">{% trans "Change password" %}</h1>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form class="form-horizontal" role="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% for field in form_password %}
|
||||
<div class="has-error text-right">
|
||||
{% for error in field.errors %}
|
||||
<span class="badge badge-danger">{{ error }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="form-group {% if field.errors %}has-error has-feedback{% endif %}">
|
||||
<label for="input_{{ field.name }}" class="col-sm-4 control-label">
|
||||
{{ field.label }}
|
||||
</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="{{ field.field.widget.input_type }}"
|
||||
class="form-control"
|
||||
id="input_{{ field.name }}"
|
||||
name="{{ field.html_name }}">
|
||||
{% if field.errors %}
|
||||
<span class="glyphicon glyphicon-remove form-control-feedback"></span>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12 text-right">
|
||||
<button type="submit"
|
||||
class="btn btn-primary">
|
||||
{% trans "Change" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -41,13 +41,9 @@
|
|||
</div>
|
||||
<div>
|
||||
{% if request.user.pk == item.pk %}
|
||||
<button class="btn btn-info btn-block">
|
||||
<a href="{% url 'account' %}" class="btn btn-info btn-block">
|
||||
{% trans "Edit my profile" %}
|
||||
</button>
|
||||
<button class="btn btn-info btn-block">
|
||||
<i class="fa fa-cog"></i>
|
||||
{% trans "My preferences" %}
|
||||
</button>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
|
Reference in New Issue