コード例 #1
0
ファイル: views.py プロジェクト: rpalexis/aruca_auf_org
def password_change(request,
                    template_name='registration/password_change_form.html',
                    post_change_redirect=None,
                    password_change_form=PasswordChangeForm):
    if post_change_redirect is None:
        post_change_redirect = url(
            'django.contrib.auth.views.password_change_done'
        )
    if request.method == "POST":
        form = password_change_form(user=request.user, data=request.POST)
        if form.is_valid():
            form.save()

            # Mot de passe pour LDAP
            username = request.user.email
            authldap, created = \
                    AuthLDAP.objects.get_or_create(username=username)
            password = form.cleaned_data.get('new_password1')
            authldap.ldap_hash = create_ldap_hash(password)
            authldap.save()

            return redirect(post_change_redirect)
    else:
        form = password_change_form(user=request.user)
    return render(request, template_name, {'form': form})
コード例 #2
0
ファイル: views.py プロジェクト: rpalexis/aruca_auf_org
def login(request, template_name='registration/login.html',
          redirect_field_name=REDIRECT_FIELD_NAME):
    "The Django login view, but using a custom form."
    redirect_to = request.REQUEST.get(redirect_field_name, '')

    if request.method == "POST":
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            # Light security check -- make sure redirect_to isn't garbage.
            if not redirect_to or ' ' in redirect_to:
                redirect_to = settings.LOGIN_REDIRECT_URL

            # Mot de passe pour LDAP
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            authldap, created = \
                    AuthLDAP.objects.get_or_create(username=username)
            if created or not check_ldap_hash(authldap.ldap_hash, password):
                authldap.ldap_hash = create_ldap_hash(password)
                authldap.save()

            # Okay, security checks complete. Log the user in.
            auth_login(request, form.get_user())

            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()

            return redirect(redirect_to)

    else:
        form = AuthenticationForm(request)
    request.session.set_test_cookie()

    if Site._meta.installed:
        current_site = Site.objects.get_current()
    else:
        current_site = RequestSite(request)

    return render(request, template_name, {
        'form': form,
        redirect_field_name: redirect_to,
        'site': current_site,
        'site_name': current_site.name,
    })