From 4c7f5e6d2b48242e8c3cc97e30df9a8506b9e333 Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 16 May 2017 17:56:40 +0530 Subject: Change forms.py, views.py, send_emails.py, models.py - Alter activation_key field in Profile model - Change get_activation_key function in send_mail to create secret_key of fixed length - Change forms.py to get updated activation_key - Change views.py to save activation_key --- yaksh/forms.py | 3 ++- yaksh/models.py | 2 +- yaksh/send_emails.py | 3 +-- yaksh/views.py | 7 ++++++- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/yaksh/forms.py b/yaksh/forms.py index 3459be9..c09566f 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -150,7 +150,8 @@ class UserRegisterForm(forms.Form): new_profile.key_expiry_time = timezone.now() + \ timezone.timedelta(minutes=20) new_profile.save() - return u_name, pwd, new_user.email, new_profile.activation_key + user_activation_key = Profile.objects.get(user=new_user).activation_key + return u_name, pwd, new_user.email, user_activation_key class UserLoginForm(forms.Form): diff --git a/yaksh/models.py b/yaksh/models.py index 565bb23..79732cc 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -293,7 +293,7 @@ class Profile(models.Model): choices=[(tz, tz) for tz in pytz.common_timezones] ) is_email_verified = models.BooleanField(default=False) - activation_key = models.CharField(max_length=40, blank=True, null=True) + activation_key = models.CharField(max_length=255, blank=True, null=True) key_expiry_time = models.DateTimeField(blank=True, null=True) def get_user_dir(self): diff --git a/yaksh/send_emails.py b/yaksh/send_emails.py index 8983024..24215dd 100644 --- a/yaksh/send_emails.py +++ b/yaksh/send_emails.py @@ -5,7 +5,6 @@ except ImportError: from string import ascii_letters as letters from string import digits, punctuation import hashlib -from random import randint from textwrap import dedent import smtplib @@ -18,7 +17,7 @@ from django.core.mail import send_mass_mail, send_mail def generate_activation_key(username): """ Generate hashed secret key for email activation """ chars = letters + digits + punctuation - secret_key = get_random_string(randint(10, 40), chars) + secret_key = get_random_string(20, chars) return hashlib.sha256((secret_key + username).encode('utf-8')).hexdigest() diff --git a/yaksh/views.py b/yaksh/views.py index c7af5cc..7db0366 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -1543,7 +1543,10 @@ def new_activation(request, email=None): user.profile.key_expiry_time = timezone.now() + \ timezone.timedelta(minutes=20) user.profile.save() - success, msg = send_user_mail(user.email, user.profile.activation_key) + new_user_data = User.objects.get(email=email) + success, msg = send_user_mail(new_user_data.email, + new_user_data.profile.activation_key + ) if success: context['activation_msg'] = msg else: @@ -1555,6 +1558,8 @@ def new_activation(request, email=None): context_instance=ci) def update_email(request): + context = {} + ci = RequestContext(request) if request.method == "POST": email = request.POST.get('email') username = request.POST.get('username') -- cgit From 1c397982f99a7c69461afacb72b6a536aecf224b Mon Sep 17 00:00:00 2001 From: adityacp Date: Tue, 16 May 2017 18:01:53 +0530 Subject: Change activation_key field length in Profile model --- .../migrations/0007_alter_profile_activation_key.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 yaksh/migrations/0007_alter_profile_activation_key.py diff --git a/yaksh/migrations/0007_alter_profile_activation_key.py b/yaksh/migrations/0007_alter_profile_activation_key.py new file mode 100644 index 0000000..bbada8c --- /dev/null +++ b/yaksh/migrations/0007_alter_profile_activation_key.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.5 on 2017-05-16 12:31 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('yaksh', '0006_release_0_6_0'), + ] + + operations = [ + migrations.AlterField( + model_name='profile', + name='activation_key', + field=models.CharField(blank=True, max_length=255, null=True), + ), + ] -- cgit From e6ab47d2ea99b703e3c261ad5e7b6785f6f8d5d5 Mon Sep 17 00:00:00 2001 From: adityacp Date: Wed, 17 May 2017 15:39:11 +0530 Subject: Change user registration form to get activation_key --- yaksh/forms.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/yaksh/forms.py b/yaksh/forms.py index c09566f..3459be9 100644 --- a/yaksh/forms.py +++ b/yaksh/forms.py @@ -150,8 +150,7 @@ class UserRegisterForm(forms.Form): new_profile.key_expiry_time = timezone.now() + \ timezone.timedelta(minutes=20) new_profile.save() - user_activation_key = Profile.objects.get(user=new_user).activation_key - return u_name, pwd, new_user.email, user_activation_key + return u_name, pwd, new_user.email, new_profile.activation_key class UserLoginForm(forms.Form): -- cgit