Exemplo n.º 1
0
def register(request):
    '''
	Page for user signup.
	'''
    # Ensure there is nobody logged in.
    if request.user.is_authenticated:
        return redirect('dashboard')

    title = 'Register'
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        # Create the user.
        if form.is_valid():
            form.save()
            # Redirect to login page.
            return redirect('login')
    else:
        # Recreate the form since we aren't posting.
        form = RegistrationForm()

    # Return the form if the form isn't valid or user just entered page.
    return render(request, 'registration/register.html', {
        'form': form,
        'title': title
    })
Exemplo n.º 2
0
def register(request):
	# Ensure there is nobody logged in
	if request.user.is_authenticated:
		return redirect('index')

	title = 'Register'
	form = RegistrationForm(request.POST)

	if request.method =='POST':
		# Create the user
		if form.is_valid():
			user = form.save()
			user.refresh_from_db() #load profile created by register
			user.save()
			user.refresh_from_db()
			# Get username and password to log in with
			username = form.cleaned_data.get('username')
			raw_password = form.cleaned_data.get('password1')
			# Set the profile birth_date to the one given
			profile = Profile.objects.get(user=user)
			profile.birth_date = form.cleaned_data.get('birth_date')
			profile.save()

			# Redirect to login page
			return redirect('login')
	else:
		# Recreate the form since we aren't posting
		form = RegistrationForm()
		# Send the form to the page and render it
		return render(request, 'registration/register.html', {'form':form})

	# Return the form if the form isn't valid but post was specified
	return render(request, 'registration/register.html', {'form':form})
Exemplo n.º 3
0
 def post(self, request, *args, **kwargs):
     form = RegistrationForm(request.POST)
     if form.is_valid():
         new_user = form.save(commit=False)
         new_user.username = form.cleaned_data['username']
         new_user.email = form.cleaned_data['email']
         new_user.name = form.cleaned_data['name']
         new_user.save()
         new_user.set_password(form.cleaned_data['password'])
         new_user.save()
         user = authenticate(username=form.cleaned_data['username'],
                             password=form.cleaned_data['password'])
         login(request, user)
         messages.success(request, 'Welcome in our club')
         return HttpResponseRedirect('/cinema/')
     context = {'form': form}
     return render(request, 'registration.html', context)
Exemplo n.º 4
0
def register(request):
	if request.method == "POST":
		form = RegistrationForm(request.POST)
		if form.is_valid():
			user = form.save(commit=False)
			user.is_active = False
			user.save()
			current_site = get_current_site(request)
			subject = 'Activate Your MySite Account'
			message = render_to_string('main/account_activation_email.html', {
				'user': user,
				'domain': current_site.domain,
				'uid': urlsafe_base64_encode(force_bytes(user.pk)),
				'token': account_activation_token.make_token(user),
			})
			user.email_user(subject, message)
			return redirect('main:account_activation_sent')
	else:
		form = RegistrationForm()
	return render(request = request,
				  template_name = "main/register.html",
				  context={"form":form})