2013-04-23 18:51:17 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
2012-08-28 18:44:51 +02:00
|
|
|
from django import forms
|
2012-09-26 20:08:39 +02:00
|
|
|
from django.core.exceptions import ValidationError
|
2012-11-21 21:14:55 +01:00
|
|
|
from django.utils.safestring import mark_safe
|
2012-12-13 21:08:07 +01:00
|
|
|
from django.contrib.auth.forms import SetPasswordForm
|
2012-11-21 21:14:55 +01:00
|
|
|
|
|
|
|
from humbug import settings
|
2013-03-28 20:20:31 +01:00
|
|
|
from zephyr.models import Realm, get_user_profile_by_email, UserProfile
|
2013-01-10 22:01:33 +01:00
|
|
|
from zephyr.lib.actions import do_change_password
|
2012-09-26 20:08:39 +02:00
|
|
|
|
2013-02-12 20:52:42 +01:00
|
|
|
def is_inactive(value):
|
2012-10-29 19:08:18 +01:00
|
|
|
try:
|
2013-03-28 20:47:22 +01:00
|
|
|
if get_user_profile_by_email(value).is_active:
|
2012-10-29 19:08:18 +01:00
|
|
|
raise ValidationError(u'%s is already active' % value)
|
2013-03-28 20:20:31 +01:00
|
|
|
except UserProfile.DoesNotExist:
|
2012-10-29 19:08:18 +01:00
|
|
|
pass
|
|
|
|
|
2013-07-24 23:41:24 +02:00
|
|
|
SIGNUP_STRING = '<a href="https://zulip.com/signup">Sign up</a> to find out when Zulip is ready for you.'
|
2012-11-21 21:14:55 +01:00
|
|
|
|
|
|
|
def has_valid_realm(value):
|
|
|
|
try:
|
|
|
|
Realm.objects.get(domain=value.split("@")[-1])
|
|
|
|
except Realm.DoesNotExist:
|
|
|
|
raise ValidationError(mark_safe(u'Registration is not currently available for your domain. ' + SIGNUP_STRING))
|
|
|
|
|
|
|
|
def isnt_mit(value):
|
|
|
|
if "@mit.edu" in value:
|
2013-07-10 22:00:47 +02:00
|
|
|
raise ValidationError(mark_safe(u'Zulip for MIT is by invitation only. ' + SIGNUP_STRING))
|
2012-11-21 21:14:55 +01:00
|
|
|
|
2012-08-28 18:44:51 +02:00
|
|
|
class RegistrationForm(forms.Form):
|
2012-09-11 19:20:01 +02:00
|
|
|
full_name = forms.CharField(max_length=100)
|
2012-09-05 16:20:39 +02:00
|
|
|
password = forms.CharField(widget=forms.PasswordInput, max_length=100)
|
2012-10-25 21:04:46 +02:00
|
|
|
terms = forms.BooleanField(required=True)
|
2012-09-28 22:47:05 +02:00
|
|
|
|
2013-01-08 23:26:40 +01:00
|
|
|
class ToSForm(forms.Form):
|
|
|
|
full_name = forms.CharField(max_length=100)
|
|
|
|
terms = forms.BooleanField(required=True)
|
|
|
|
|
2012-09-28 22:47:05 +02:00
|
|
|
class HomepageForm(forms.Form):
|
2013-04-23 23:46:35 +02:00
|
|
|
# This form is sort of important, because it determines whether users
|
|
|
|
# can register for our product. Be careful when modifying the validators.
|
2012-11-21 21:14:55 +01:00
|
|
|
if settings.ALLOW_REGISTER:
|
2013-02-11 19:37:31 +01:00
|
|
|
email = forms.EmailField()
|
2012-11-21 21:14:55 +01:00
|
|
|
else:
|
2013-02-12 20:52:42 +01:00
|
|
|
validators = [has_valid_realm, isnt_mit, is_inactive]
|
2013-02-11 19:37:31 +01:00
|
|
|
email = forms.EmailField(validators=validators)
|
2012-12-13 21:08:07 +01:00
|
|
|
|
|
|
|
class LoggingSetPasswordForm(SetPasswordForm):
|
|
|
|
def save(self, commit=True):
|
2013-03-29 17:39:53 +01:00
|
|
|
do_change_password(self.user, self.cleaned_data['new_password1'],
|
2012-12-13 21:08:07 +01:00
|
|
|
log=True, commit=commit)
|
|
|
|
return self.user
|
2013-05-03 00:26:53 +02:00
|
|
|
|
|
|
|
class CreateBotForm(forms.Form):
|
|
|
|
full_name = forms.CharField(max_length=100)
|
|
|
|
email = forms.EmailField()
|