from django.conf import settings from django.contrib.auth import login, authenticate from django.http import HttpResponseRedirect from django.shortcuts import render from .forms import SignUpForm from .ldap_funcs import create_user def signup(request): if request.method == 'POST': form = SignUpForm(request.POST) if form.is_valid(): username = form.cleaned_data.get('username') raw_password = form.cleaned_data.get('password1') first_name = form.cleaned_data.get('first_name') last_name = form.cleaned_data.get('last_name') email = form.cleaned_data.get('email') create_user(username, raw_password, first_name, last_name, email) form.save() user = authenticate(username=username, password=raw_password) login(request, user, backend='django_auth_ldap.backend.LDAPBackend') return HttpResponseRedirect(settings.LOGIN_REDIRECT_URL) else: form = SignUpForm() return render(request, 'users/signup.html', {'form': form}) # def signup(request): # return HttpResponseRedirect("https://account.ungleich.ch/register/")