Exemple #1
0
def register_user(request):
    form = CustomRegistrationForm(request.POST)
    if form.is_valid():
        form.save()

        username = form.cleaned_data['username']
        email = form.cleaned_data['email']
        phone = form.cleaned_data['phone']
        salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
        activation_key = hashlib.sha1(salt + email).hexdigest()
        key_expires = timezone.make_aware(datetime.datetime.today() + datetime.timedelta(2),
                                          timezone.get_default_timezone())
        # Retrieve user
        user = User.objects.get(username=username)

        # Save profile
        new_profile = UserProfile(user=user, activation_key=activation_key,
                                  key_expires=key_expires, phone_number=phone, username=username)
        new_profile.save()


        # Send email with activation key
        email_subject = 'Account confirmation'
        email_body = "Hi " + username + ", you have successfully registered but just one last step to get started. " \
                     "To activate your account, click this link within 48hours " \
                     + reverse('django_auth.confirm', args=[activation_key]) \
                     + ". You will also receive a message on your phone number " + new_profile.phone_number \
                     + " to confirm your number."
        send_mail(email_subject, email_body, settings.FROM_EMAIL_ADDRESS, [email], fail_silently=False)

        return HttpResponseRedirect(reverse('django_auth.register_success'))
    else:
        return HttpResponseRedirect(reverse('django_auth'))
Exemple #2
0
def register(request):
	if request.method == 'POST': #create new user
		form = CustomRegistrationForm(request.POST)
		user_details_form = UserDetailsForm(request.POST)
		if form.is_valid() and user_details_form.is_valid():
			user = form.save()
			user_details = user_details_form.save(commit=False)
			user_details.user = user
			user_details.save()
			return HttpResponseRedirect("/accounts/user")
	else:
		form = CustomRegistrationForm()
		user_details_form = UserDetailsForm()
	return render(request, "registration/register.html", {
		'form': form,
		'user_details_form':user_details_form,
	})
def user_registration(request):
    context = dict()
    context.update(csrf(request))
    form = CustomRegistrationForm(request.POST or None)
    context['form'] = form

    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password1']
        if form.is_valid():
            form.save()
            logged_in = try_to_login(request, username, password)
            if logged_in is True:
                return HttpResponseRedirect(reverse('blog:my_posts'))
            else:
                context['error_message'] = logged_in

    return render(request, 'register.html', context)
Exemple #4
0
def register(request):
    if request.method == 'POST':  #create new user
        form = CustomRegistrationForm(request.POST)
        user_details_form = UserDetailsForm(request.POST)
        if form.is_valid() and user_details_form.is_valid():
            user = form.save()
            user_details = user_details_form.save(commit=False)
            user_details.user = user
            user_details.save()
            return HttpResponseRedirect("/accounts/user")
    else:
        form = CustomRegistrationForm()
        user_details_form = UserDetailsForm()
    return render(request, "registration/register.html", {
        'form': form,
        'user_details_form': user_details_form,
    })