Ejemplo n.º 1
0
def signup(request):
	if request.method == 'POST':
		form = SignupForm(request.POST)
		print(form.data)
		print(form.is_valid())
		if form.is_valid():
			form.save()

			username = form.data['username']
			email = form.data['email']
			print(username,email)
			salt = hashlib.sha1(str(random.random()).encode('utf-8')).hexdigest()[:5]
			activation_key = hashlib.sha1((salt+email).encode('utf-8')).hexdigest()
			key_expires = datetime.datetime.today() + datetime.timedelta(1)

			# Create and save user profile
			user = User.objects.get(email=email)
			new_profile = UserProfile(user=user, activation_key=activation_key,
				key_expires=key_expires)
			new_profile.save()

			# Send email with activation key
			email_subject = 'Account confirmation'
			email_body = "Hi %s, thanks for signing up. To activate your account, click this link within \
			48hours http://127.0.0.1:8000/confirm/%s" % (username, activation_key)
			send_mail(email_subject, email_body, '*****@*****.**',
				[email], fail_silently = False)
			return render(request, 'sign_up_success.html')
		else:
			return render(request, 'confirm_expired.html')
	else:
		return render(request, 'sign_up.html')
Ejemplo n.º 2
0
def signup_view(request):
    form = SignupForm()
    if request.method == 'POST':
        form = SignupForm(request.POST)
        if form.is_valid():
            user = form.save()
            group = Group.objects.get(name='author')
            user.groups.add(group)
            form = SignupForm()
    return render(request, 'blog/signup.html', {'form': form})