Beispiel #1
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if not form.is_valid():
            messages.add_message(
                request, messages.ERROR,
                'There was some problems while creating your account. Please review some fields before submiting again.'
            )
            context = RequestContext(request, {'form': form})
            return render_to_response('auth/signup.html', context)
        else:
            username = form.cleaned_data.get('username')
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')
            User.objects.create_user(username=username,
                                     password=password,
                                     email=email)
            user = authenticate(username=username, password=password)
            login(request, user)
            messages.add_message(request, messages.SUCCESS,
                                 'Your account were successfully created.')
            return HttpResponseRedirect('/' + username + '/')
    else:
        context = RequestContext(request, {'form': SignUpForm()})
        return render_to_response('auth/signup.html', context)
Beispiel #2
0
def signupview(request):
    html = "signup.html"
    if request.method == "POST":
        form = SignUpForm(request.POST)
        if form.is_valid:
            form.save()
            return HttpResponseRedirect(reverse('login'))
    else:
        form = SignUpForm()
    context = {'form': form}
    return render(request, html, context)
Beispiel #3
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        print(form.field_order)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('home')
        else:
            return render(request, 'auth/signup.html', {'form': form})
    else:
        form = SignUpForm()
        print(form.as_table())
    return render(request, 'auth/signup.html', {'form': form})
Beispiel #4
0
def signup():
	forms = SignUpForm()
	if request.method=='POST' and forms.validate_on_submit():
		if forms.check_user_exists() == False:
			user = User(username = forms.username.data, name = forms.name.data)
			user.set_password(forms.password.data)
			db.session.add(user)
			db.session.commit()
			return redirect(url_for('login'))	
	else:		
		print(forms.errors)

	return render_template('signup.html', title = 'SignUp', form = forms)