summaryrefslogtreecommitdiffstats
path: root/forum/authentication/forms.py
diff options
context:
space:
mode:
authorhrcerqueira <hrcerqueira@gmail.com>2010-03-03 16:05:46 +0000
committerhrcerqueira <hrcerqueira@gmail.com>2010-03-03 16:05:46 +0000
commitec71d0c85766da2f9c369d2dc92c83d2a25cd22d (patch)
tree471a930a2e551846902300958dc5435233fd8d0c /forum/authentication/forms.py
parent1d35d25b8ce9f3004eebd10d88757c5921dd686c (diff)
downloadaskbot-ec71d0c85766da2f9c369d2dc92c83d2a25cd22d.tar.gz
askbot-ec71d0c85766da2f9c369d2dc92c83d2a25cd22d.tar.bz2
askbot-ec71d0c85766da2f9c369d2dc92c83d2a25cd22d.zip
Temp login token request (for password recovery and google openid problems)
Utilities to send html emails, a base html email template and template tags to build full urls with domain name and protocol (for html email images and styles) Email validation now uses an improved algorithm Fixed a bug in the user message system
Diffstat (limited to 'forum/authentication/forms.py')
-rwxr-xr-xforum/authentication/forms.py46
1 files changed, 44 insertions, 2 deletions
diff --git a/forum/authentication/forms.py b/forum/authentication/forms.py
index 019c85f3..7fa06b01 100755
--- a/forum/authentication/forms.py
+++ b/forum/authentication/forms.py
@@ -1,7 +1,8 @@
-from forum.utils.forms import NextUrlField, UserNameField, UserEmailField
-from forum.models import EmailFeedSetting, Question
+from forum.utils.forms import NextUrlField, UserNameField, UserEmailField, SetPasswordForm
+from forum.models import EmailFeedSetting, Question, User
from django.contrib.contenttypes.models import ContentType
from django.utils.translation import ugettext as _
+from django.utils.safestring import mark_safe
from django import forms
from forum.forms import EditUserEmailFeedsForm
import logging
@@ -11,6 +12,29 @@ class SimpleRegistrationForm(forms.Form):
username = UserNameField()
email = UserEmailField()
+class TemporaryLoginRequestForm(forms.Form):
+ def __init__(self, data=None):
+ super(TemporaryLoginRequestForm, self).__init__(data)
+ self.user_cache = None
+
+ email = forms.EmailField(
+ required=True,
+ label=_("Your account email"),
+ error_messages={
+ 'required': _("You cannot leave this field blank"),
+ 'invalid': _('please enter a valid email address'),
+ }
+ )
+
+ def clean_email(self):
+ try:
+ user = User.objects.get(email=self.cleaned_data['email'])
+ except:
+ raise forms.ValidationError(_("Sorry, but this email is not on our database."))
+
+ self.user_cache = user
+ return self.cleaned_data['email']
+
class SimpleEmailSubscribeForm(forms.Form):
SIMPLE_SUBSCRIBE_CHOICES = (
@@ -29,3 +53,21 @@ class SimpleEmailSubscribeForm(forms.Form):
else:
email_settings_form = EFF(initial=EFF.NO_EMAIL_INITIAL)
email_settings_form.save(user,save_unbound=True)
+
+class ChangePasswordForm(SetPasswordForm):
+ """ change password form """
+ oldpw = forms.CharField(widget=forms.PasswordInput(attrs={'class':'required'}),
+ label=mark_safe(_('Current password')))
+
+ def __init__(self, data=None, user=None, *args, **kwargs):
+ if user is None:
+ raise TypeError("Keyword argument 'user' must be supplied")
+ super(ChangePasswordForm, self).__init__(data, *args, **kwargs)
+ self.user = user
+
+ def clean_oldpw(self):
+ """ test old password """
+ if not self.user.check_password(self.cleaned_data['oldpw']):
+ raise forms.ValidationError(_("Old password is incorrect. \
+ Please enter the correct password."))
+ return self.cleaned_data['oldpw']