Example #1
0
def register(request):
	if not request.user.is_authenticated():
		if request.method == 'POST':
			form = RegistrationForm(request.POST)
			if form.is_valid():
				username = form.cleaned_data['username']
				password = form.cleaned_data['password']
				password_repeat = form.cleaned_data['password_repeat']
				email = form.cleaned_data['email']
				if password == password_repeat:
					if User.objects.filter(username=username).exists():
						form._errors['username'] = ErrorList([u'Username already exists.'])
					else:
						user = User.objects.create_user(username, email, password)
						user.get_profile().gravatar = email
						user.save()
						return redirect(reverse('home_index'), context_instance=RequestContext(request))
				else:
					messages.error(request, 'Passwords do not match.')
		else:
			form = RegistrationForm()
	else:
		return redirect(reverse('home_index'), context_instance=RequestContext(request))

	return render_to_response(
		'auth/register.html',
		{ 'form': form, },
		context_instance=RequestContext(request)
	)
Example #2
0
def register(request):
    """
    This view handles user registration
    """

    if request.method == 'POST':  # If the form has been submitted...
        form = RegistrationForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            # Create user and send activation mail

            # Create user
            user = User.objects.create_user(form.cleaned_data.get('username'),
                                            form.cleaned_data.get('email'),
                                            form.cleaned_data.get('password'))

            user.is_staff = False
            user.is_active = False
            user.save()

            # Fill profile
            profile = user.get_profile()

            # Generate activation key
            email_key = user.username + uuid.uuid4().hex
            profile.activation_key = email_key
            profile.key_expires = datetime.datetime.now() + datetime.timedelta(days=2)

            # Save Profile
            profile.save()

            # Send activation mail
            text = get_template('mail/activation.txt')
            html = get_template('mail/activation.haml')

            mail_context = Context({'username': form.cleaned_data.get('username'), 'activation_key': email_key})

            text_content = text.render(mail_context)
            html_content = html.render(mail_context)

            message = EmailMultiAlternatives('Welcome to Element43!',
                                             text_content, settings.DEFAULT_FROM_EMAIL,
                                             [form.cleaned_data.get('email')])

            message.attach_alternative(html_content, "text/html")
            message.send()

            # Add success message
            messages.success(request, """Your account has been created and an e-mail message containing your activation
                                         key has been sent to the address you specified. You have to activate your
                                         account within the next 48 hours.""")
            # Redirect home
            return HttpResponseRedirect(reverse('home'))
    else:
        form = RegistrationForm()  # An unbound form

    rcontext = RequestContext(request, {})
    return render_to_response('register.haml', {'form': form}, rcontext)
Example #3
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            User.objects.create_user(
                username=form.cleaned_data['email'],
                first_name=form.cleaned_data['first_name'],
                email=form.cleaned_data['email'],
                password=form.cleaned_data['password2'],
            )
            return redirect('/')
    else:
        form = RegistrationForm()
    return render(request, 'auth/register.html', {
        'form': form
    })
Example #4
0
def register(request):
    """
    This view handles user registration
    """

    if request.method == 'POST':  # If the form has been submitted...
        form = RegistrationForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            # Create user and send activation mail

            # Create user
            user = User.objects.create_user(form.cleaned_data.get('username'),
                                            form.cleaned_data.get('email'),
                                            form.cleaned_data.get('password'))

            user.is_staff = False
            user.is_active = False
            user.save()

            # Fill profile
            profile = user.get_profile()

            # Generate activation key
            email_key = user.username + uuid.uuid4().hex
            profile.activation_key = email_key
            profile.key_expires = datetime.datetime.now() + datetime.timedelta(
                days=2)

            # Save Profile
            profile.save()

            # Send activation mail
            text = get_template('mail/activation.txt')
            html = get_template('mail/activation.haml')

            mail_context = Context({
                'username':
                form.cleaned_data.get('username'),
                'activation_key':
                email_key
            })

            text_content = text.render(mail_context)
            html_content = html.render(mail_context)

            message = EmailMultiAlternatives('Welcome to Element43!',
                                             text_content,
                                             settings.DEFAULT_FROM_EMAIL,
                                             [form.cleaned_data.get('email')])

            message.attach_alternative(html_content, "text/html")
            message.send()

            # Add success message
            messages.success(
                request,
                """Your account has been created and an e-mail message containing your activation
                                         key has been sent to the address you specified. You have to activate your
                                         account within the next 48 hours.""")
            # Redirect home
            return HttpResponseRedirect(reverse('home'))
    else:
        form = RegistrationForm()  # An unbound form

    rcontext = RequestContext(request, {})
    return render_to_response('register.haml', {'form': form}, rcontext)