aboutsummaryrefslogtreecommitdiff
path: root/okupy
diff options
context:
space:
mode:
authorPavlos Ratis <dastergon@gentoo.org>2013-09-04 20:13:06 +0300
committerPavlos Ratis <dastergon@gentoo.org>2013-09-04 20:13:06 +0300
commit43849e628b9647b28f2f3debdfcea3f3bc09a390 (patch)
tree58c4dfadc14f102aa3b434d4b368945ddc87066e /okupy
parentadd support for user settings (diff)
downloadidentity.gentoo.org-43849e628b9647b28f2f3debdfcea3f3bc09a390.tar.gz
identity.gentoo.org-43849e628b9647b28f2f3debdfcea3f3bc09a390.tar.bz2
identity.gentoo.org-43849e628b9647b28f2f3debdfcea3f3bc09a390.zip
move password and email settings to another page
Diffstat (limited to 'okupy')
-rw-r--r--okupy/accounts/forms.py10
-rw-r--r--okupy/accounts/urls.py2
-rw-r--r--okupy/accounts/views.py88
-rw-r--r--okupy/templates/base.html2
-rw-r--r--okupy/templates/settings-email.html45
-rw-r--r--okupy/templates/settings-password.html35
6 files changed, 168 insertions, 14 deletions
diff --git a/okupy/accounts/forms.py b/okupy/accounts/forms.py
index 37c05d0..01a342a 100644
--- a/okupy/accounts/forms.py
+++ b/okupy/accounts/forms.py
@@ -68,11 +68,13 @@ class ProfileSettingsForm(forms.Form):
max_length=100, label='First Name', required=False)
last_name = forms.CharField(
max_length=100, label='Last Name', required=False)
- email = forms.EmailField(max_length=254, label='Email', help_text='A valid email address, please.', required=False)
birthday = forms.DateField(
input_formats='%m/%d/%Y', label='Birthday (format: month/day/year)', required=False)
timezone = forms.ChoiceField(
choices=[(x, x) for x in pytz.common_timezones])
+
+
+class PasswordSettingsForm(forms.Form):
old_password = forms.CharField(max_length=30, widget=forms.PasswordInput(
), label='Old Password', required=False)
new_password = forms.CharField(max_length=30, widget=forms.PasswordInput(
@@ -80,7 +82,7 @@ class ProfileSettingsForm(forms.Form):
new_password_verify = forms.CharField(max_length=30, widget=forms.PasswordInput(), label='Repeat New Password', required=False)
def clean(self):
- cleaned_data = super(ProfileSettingsForm, self).clean()
+ cleaned_data = super(PasswordSettingsForm, self).clean()
new_password = cleaned_data.get('new_password')
new_password_verify = cleaned_data.get('new_password_verify')
old_password = cleaned_data.get('old_password')
@@ -94,6 +96,10 @@ class ProfileSettingsForm(forms.Form):
return cleaned_data
+class EmailSettingsForm(forms.Form):
+ email = forms.EmailField(max_length=254, label='Add Email', help_text='A valid email address, please.', required=False)
+
+
class ContactSettingsForm(forms.Form):
website = forms.URLField(label='Website', required=False)
im = forms.CharField(max_length=100, label='IM', required=False)
diff --git a/okupy/accounts/urls.py b/okupy/accounts/urls.py
index d5e37c9..9212089 100644
--- a/okupy/accounts/urls.py
+++ b/okupy/accounts/urls.py
@@ -15,6 +15,8 @@ accounts_urlpatterns = patterns(
url(r'^contact-settings/$', v.contact_settings, name="contact-settings"),
url(r'^gentoo-dev-settings/$', v.gentoo_dev_settings, name="gentoo-dev-settings"),
url(r'^profile-settings/$', v.profile_settings, name="profile-settings"),
+ url(r'^password-settings/$', v.password_settings, name="password-settings"),
+ url(r'^email-settings/$', v.email_settings, name="email-settings"),
url(r'^signup/$', v.signup),
url(r'^activate/(?P<token>[a-zA-Z0-9-_]+)/$', v.activate),
url(r'^otp-setup/$', v.otp_setup),
diff --git a/okupy/accounts/views.py b/okupy/accounts/views.py
index da48634..2db9981 100644
--- a/okupy/accounts/views.py
+++ b/okupy/accounts/views.py
@@ -28,7 +28,9 @@ from urlparse import urljoin
from okupy import OkupyError
from okupy.accounts.forms import (LoginForm, OpenIDLoginForm, SSLCertLoginForm,
OTPForm, SignupForm, SiteAuthForm,
- StrongAuthForm, ProfileSettingsForm, ContactSettingsForm, GentooAccountSettingsForm)
+ StrongAuthForm, ProfileSettingsForm,
+ ContactSettingsForm, EmailSettingsForm,
+ GentooAccountSettingsForm, PasswordSettingsForm)
from okupy.accounts.models import LDAPUser, OpenID_Attributes, Queue
from okupy.accounts.openid_store import DjangoDBOpenIDStore
from okupy.common.ldap_helpers import (get_bound_ldapuser,
@@ -380,12 +382,8 @@ def profile_settings(request):
if profile_settings.is_valid():
try:
#birthday = profile_settings.cleaned_data['birthday']
- email = profile_settings.cleaned_data['email']
first_name = profile_settings.cleaned_data['first_name']
last_name = profile_settings.cleaned_data['last_name']
- new_password = profile_settings.cleaned_data['new_password']
- new_password_verify = profile_settings.cleaned_data['new_password_verify']
- old_password = profile_settings.cleaned_data['old_password']
if user_profile_info.first_name != first_name:
user_profile_info.first_name = first_name
@@ -400,9 +398,38 @@ def profile_settings(request):
if user_profile_info.birthday != birthday:
user_profile_info.birthday = birthday
"""
- if user_profile_info.email != email:
- user_profile_info.email.pop()
- user_profile_info.email.append(email)
+ try:
+ user_profile_info.save()
+ except IntegrityError:
+ pass
+ except ldap.TYPE_OR_VALUE_EXISTS:
+ pass
+ except Exception as error:
+ logger.critical(error, extra=log_extra_data(request))
+ logger_mail.exception(error)
+ raise OkupyError("Can't contact LDAP server")
+ else:
+ profile_settings = ProfileSettingsForm()
+
+ return render(request, 'settings-profile.html', {
+ 'profile_settings': profile_settings,
+ 'user_profile_info': user_profile_info,
+ })
+
+
+@strong_auth_required
+@otp_required
+def password_settings(request):
+ """ Password settings """
+ user_profile_info = get_bound_ldapuser(request)
+ password_settings = None
+ if request.method == "POST":
+ password_settings = PasswordSettingsForm(request.POST)
+ if password_settings.is_valid():
+ try:
+ new_password = password_settings.cleaned_data['new_password']
+ new_password_verify = password_settings.cleaned_data['new_password_verify']
+ old_password = password_settings.cleaned_data['old_password']
if old_password and (new_password == new_password_verify):
for hash in list(user_profile_info.password):
@@ -426,10 +453,46 @@ def profile_settings(request):
logger_mail.exception(error)
raise OkupyError("Can't contact LDAP server")
else:
- profile_settings = ProfileSettingsForm()
+ password_settings = PasswordSettingsForm()
- return render(request, 'settings-profile.html', {
- 'profile_settings': profile_settings,
+ return render(request, 'settings-password.html', {
+ 'password_settings': password_settings,
+ 'user_profile_info': user_profile_info,
+ })
+
+
+@strong_auth_required
+@otp_required
+def email_settings(request):
+ """ Email Settings """
+ user_profile_info = get_bound_ldapuser(request)
+ email_settings = None
+ if request.method == "POST":
+ email_settings = EmailSettingsForm(request.POST)
+ if email_settings.is_valid():
+ try:
+ email = email_settings.cleaned_data['email']
+
+ if request.POST.get('delete'):
+ user_profile_info.email.remove(email)
+ else:
+ user_profile_info.email.append(email)
+
+ try:
+ user_profile_info.save()
+ except IntegrityError:
+ pass
+ except ldap.TYPE_OR_VALUE_EXISTS:
+ pass
+ except Exception as error:
+ logger.critical(error, extra=log_extra_data(request))
+ logger_mail.exception(error)
+ raise OkupyError("Can't contact LDAP server")
+ else:
+ email_settings = EmailSettingsForm()
+
+ return render(request, 'settings-email.html', {
+ 'email_settings': email_settings,
'user_profile_info': user_profile_info,
})
@@ -525,7 +588,8 @@ def gentoo_dev_settings(request):
if user_profile_info.is_retired or user_profile_info.gentoo_retire_date:
gentoo_retire_date = gentoo_account_settings.cleaned_data['gentoo_retire_date']
if user_profile_info.gentoo_retire_date != gentoo_retire_date:
- user_profile_info.gentoo_retire_date.append(gentoo_retire_date)
+ user_profile_info.gentoo_retire_date.append(
+ gentoo_retire_date)
try:
user_profile_info.save()
diff --git a/okupy/templates/base.html b/okupy/templates/base.html
index 0fc8c3a..d8f1b1e 100644
--- a/okupy/templates/base.html
+++ b/okupy/templates/base.html
@@ -67,6 +67,8 @@
<li><a href="{% url 'index' %}" title="View Profile">View Profile</a></li>
<li><a href="{% url 'profile-settings' %}" title="Edit Profile">Edit Profile</a></li>
<li><a href="{% url 'contact-settings' %}" title="Contact Settings">Contact Settings</a></li>
+ <li><a href="{% url 'password-settings' %}" title="Change Password">Change Password</a></li>
+ <li><a href="{% url 'email-settings' %}" title="Email Settings">Email Settings</a></li>
<li><a href="{% url 'gentoo-dev-settings' %}" title="Gentoo Account Settings">Gentoo Account Settings</a></li>
<li><a href="#" title="Invite others">Invite</a></li>
<li><a href="{% url 'logout' %}" title="Logout">Logout</a></li>
diff --git a/okupy/templates/settings-email.html b/okupy/templates/settings-email.html
new file mode 100644
index 0000000..7f0af1d
--- /dev/null
+++ b/okupy/templates/settings-email.html
@@ -0,0 +1,45 @@
+{% extends "base.html" %}
+
+{% block content %}
+<div id="pageRow" class="container">
+ <div class="row">
+ <div id="page" class="span10">
+ <div>
+ <h1>Email Settings</h1>
+ <h3>Manage your emails.</h3>
+ <div class="form well">
+ {{ email_settings.errors }}
+ {{ email_settings.non_field_errors }}
+ <div class="row-fluid ">
+ <table class="table">
+ <thead>
+ <tr>
+ <th>Email</th>
+ <th> </th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for mail in user_profile_info.email%}
+ <form action="." method="POST">{% csrf_token %}
+ <tr>
+ <td><input type="hidden" name="email" value="{{ mail }}" />{{mail}}</td>
+ <td><input class="btn" type="submit" name="delete" value="Delete" /></td>
+ </tr>
+ </form>
+ {% endfor %}
+ </tbody>
+ </table>
+ <form action="." method="POST">{% csrf_token %}
+ {{ email_settings.email.label_tag }}
+ <input name="email" type="text" /> {{ email_settings.email.errors|striptags }}
+ <div class="row-fluid buttons">
+ <input class="btn btn-primary" type="submit" value="Add email" />
+ </div>
+ </form>
+ </div>
+ </div>
+ </div>
+ </div>
+{% endblock %}
+
+{# vim:se fileencoding=utf8 et ts=4 sts=4 sw=4 ft=htmldjango : #}
diff --git a/okupy/templates/settings-password.html b/okupy/templates/settings-password.html
new file mode 100644
index 0000000..3e427b9
--- /dev/null
+++ b/okupy/templates/settings-password.html
@@ -0,0 +1,35 @@
+{% extends "base.html" %}
+
+{% block content %}
+<div id="pageRow" class="container">
+ <div class="row">
+ <div id="page" class="span10">
+ <div>
+ <h1>Change Password</h1>
+ <h3>Change your password.</h3>
+ <div class="form well">
+ <form action="." method="POST">{% csrf_token %}
+ {{ password_settings.errors }}
+ {{ password_settings.non_field_errors }}
+ <div class="row-fluid">
+ {{ password_settings.old_password.label_tag }}
+ {{ password_settings.old_password }} {{ password_settings.old_password.non_field_errors|striptags }}
+ </div>
+ <div class="row-fluid">
+ {{ password_settings.new_password.label_tag }}
+ {{ password_settings.new_password }} {{ password_settings.new_password.errors|striptags }}
+ </div>
+ <div class="row-fluid">
+ {{ password_settings.new_password_verify.label_tag }}
+ {{ password_settings.new_password_verify }} {{ password_settings.new_password_verify.errors|striptags }}
+ </div>
+ <div class="row-fluid buttons">
+ <input class="btn btn-primary" type="submit" value="Update Password" />
+ </div>
+ </form>
+ </div>
+ </div>
+ </div>
+{% endblock %}
+
+{# vim:se fileencoding=utf8 et ts=4 sts=4 sw=4 ft=htmldjango : #}