summaryrefslogtreecommitdiff
path: root/yaksh/forms.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2017-04-28 17:14:43 +0530
committerGitHub2017-04-28 17:14:43 +0530
commitb285378b2eca29e7125bf9474cd57c973a202f37 (patch)
tree726da35ba55acacfde255e31bdc2233600f75395 /yaksh/forms.py
parent2694fd6dd4d37a1a6570792e234998feef21edca (diff)
parent624e752684125aa525d9b3643cbd7c9b7ba61682 (diff)
downloadonline_test-b285378b2eca29e7125bf9474cd57c973a202f37.tar.gz
online_test-b285378b2eca29e7125bf9474cd57c973a202f37.tar.bz2
online_test-b285378b2eca29e7125bf9474cd57c973a202f37.zip
Merge pull request #273 from adityacp/email_verification
Email verification during registration
Diffstat (limited to 'yaksh/forms.py')
-rw-r--r--yaksh/forms.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/yaksh/forms.py b/yaksh/forms.py
index d56fb04..5dd56a2 100644
--- a/yaksh/forms.py
+++ b/yaksh/forms.py
@@ -5,7 +5,7 @@ from yaksh.models import get_model_class, Profile, Quiz, Question, TestCase, Cou
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
-
+from django.conf import settings
from taggit.managers import TaggableManager
from taggit.forms import TagField
from django.forms.models import inlineformset_factory
@@ -18,6 +18,7 @@ except ImportError:
from string import punctuation, digits
import datetime
import pytz
+from .email_verification import generate_activation_key
languages = (
("select", "Select Language"),
@@ -117,6 +118,12 @@ class UserRegisterForm(forms.Form):
return c_pwd
+ def clean_email(self):
+ user_email = self.cleaned_data['email']
+ if User.objects.filter(email=user_email).exists():
+ raise forms.ValidationError("This email already exists")
+ return user_email
+
def save(self):
u_name = self.cleaned_data["username"]
u_name = u_name.lower()
@@ -135,9 +142,17 @@ class UserRegisterForm(forms.Form):
new_profile.department = cleaned_data["department"]
new_profile.position = cleaned_data["position"]
new_profile.timezone = cleaned_data["timezone"]
+ if settings.IS_DEVELOPMENT:
+ new_profile.is_email_verified = True
+ else:
+ new_profile.activation_key = generate_activation_key(new_user.username)
+ new_profile.key_expiry_time = datetime.datetime.strftime(
+ datetime.datetime.now() + \
+ datetime.timedelta(minutes=20),
+ "%Y-%m-%d %H:%M:%S"
+ )
new_profile.save()
-
- return u_name, pwd
+ return u_name, pwd, new_user.email, new_profile.activation_key
class UserLoginForm(forms.Form):
@@ -318,4 +333,3 @@ class QuestionPaperForm(forms.ModelForm):
class Meta:
model = QuestionPaper
fields = ['shuffle_questions']
-