mirror of
https://github.com/ajurna/cbwebreader.git
synced 2025-12-06 14:17:19 +00:00
added account page to change password and email address.
This commit is contained in:
@@ -1,6 +1,36 @@
|
||||
from django import forms
|
||||
from comic.models import Setting
|
||||
|
||||
class AccountForm(forms.Form):
|
||||
username = forms.CharField(help_text='Username',
|
||||
required=False,
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'class': 'form-control disabled',
|
||||
'readonly': True,
|
||||
}
|
||||
))
|
||||
email = forms.CharField(help_text='Email Address',
|
||||
widget=forms.TextInput(
|
||||
attrs={
|
||||
'class': 'form-control'
|
||||
}
|
||||
))
|
||||
password1 = forms.CharField(help_text='New Password',
|
||||
required=False,
|
||||
widget=forms.PasswordInput(
|
||||
attrs={
|
||||
'class': 'form-control',
|
||||
}
|
||||
))
|
||||
password2 = forms.CharField(help_text='New Password Confirmation',
|
||||
required=False,
|
||||
widget=forms.PasswordInput(
|
||||
attrs={
|
||||
'class': 'form-control',
|
||||
}
|
||||
))
|
||||
|
||||
|
||||
class SettingsForm(forms.Form):
|
||||
base_dir = forms.CharField(help_text='Base Directory',
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
|
||||
{% block content %}
|
||||
{% if error_message %}
|
||||
<div class="alert alert-danger" role="alert">{{ error_message }}</div>
|
||||
<div class="alert alert-danger" role="alert">{{ error_message|safe }}</div>
|
||||
{% endif %}
|
||||
{% if success_message %}
|
||||
<div class="alert alert-success" role="alert">{{ success_message|safe }}</div>
|
||||
{% endif %}
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
|
||||
@@ -5,6 +5,7 @@ from . import views
|
||||
urlpatterns = [
|
||||
url(r'^$', views.comic_list, name='index'),
|
||||
url(r'^settings/$', views.settings_page, name='settings'),
|
||||
url(r'^account/$', views.account_page, name='account'),
|
||||
url(r'^(?P<comic_path>[\w]+)/$', views.comic_list, name='comic_list'),
|
||||
url(r'^read/(?P<comic_path>[\w]+)/(?P<page>[0-9]+)/$', views.read_comic, name='read_comic'),
|
||||
url(r'^read/(?P<comic_path>[\w]+)/(?P<page>[0-9]+)/img$', views.get_image, name='get_image'),
|
||||
|
||||
@@ -13,6 +13,7 @@ class Menu:
|
||||
"""
|
||||
self.menu_items = OrderedDict()
|
||||
self.menu_items['Browse'] = '/comic/'
|
||||
self.menu_items['Account'] = '/comic/account/'
|
||||
self.menu_items['Settings'] = '/comic/settings/'
|
||||
self.menu_items['Logout'] = '/logout/'
|
||||
self.current_page = page
|
||||
|
||||
@@ -3,10 +3,12 @@ from django.template import RequestContext
|
||||
from django.utils.http import urlsafe_base64_decode
|
||||
from django.shortcuts import render, redirect
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.validators import validate_email
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from comic.models import Setting, ComicBook, ComicStatus
|
||||
from util import generate_breadcrumbs
|
||||
from forms import SettingsForm
|
||||
from forms import SettingsForm, AccountForm
|
||||
from util import Menu
|
||||
from os import path
|
||||
|
||||
@@ -29,6 +31,42 @@ def comic_list(request, comic_path=''):
|
||||
})
|
||||
return render(request, 'comic/comic_list.html', context)
|
||||
|
||||
@login_required
|
||||
def account_page(request):
|
||||
error_message = []
|
||||
success_message = []
|
||||
if request.POST:
|
||||
form = AccountForm(request.POST)
|
||||
if form.is_valid():
|
||||
if form.cleaned_data['password1'] != '':
|
||||
if form.cleaned_data['password1'] == form.cleaned_data['password2']:
|
||||
if len(form.cleaned_data['password1']) < 8:
|
||||
error_message.append('Password is too short')
|
||||
else:
|
||||
success_message.append('password changed')
|
||||
request.user.set_password(form.cleaned_data['password1'])
|
||||
else:
|
||||
error_message.append("Passwords don't match")
|
||||
if form.cleaned_data['email'] != request.user.email:
|
||||
try:
|
||||
validate_email(form.cleaned_data['email'])
|
||||
success_message.append('Email Address updated')
|
||||
request.user.email = form.cleaned_data['email']
|
||||
except ValidationError:
|
||||
error_message.append('Invalid E-mail.')
|
||||
request.user.save()
|
||||
else:
|
||||
form = AccountForm(initial={
|
||||
'username': request.user.username,
|
||||
'email': request.user.email,
|
||||
})
|
||||
context = RequestContext(request, {
|
||||
'form': form,
|
||||
'menu': Menu('Account'),
|
||||
'error_message': '</br>'.join(error_message),
|
||||
'success_message': '</br>'.join(success_message),
|
||||
})
|
||||
return render(request, 'comic/settings_page.html', context)
|
||||
|
||||
@login_required
|
||||
def settings_page(request):
|
||||
|
||||
Reference in New Issue
Block a user