Z
Z
zelsky2016-08-22 17:45:54
Django
zelsky, 2016-08-22 17:45:54

CustomUser model auth not working?

del deldeldeldeldeldeldeldeldeldeldeldeldeldeldeldeldeldeldeldeldeldeldeldeldeldeldel

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
werevolff, 2016-08-22
@zelsky

def login(request):

    defaults = {
        'authentication_form': CustomAuthForm,
        'template_name': 'accounts/login.html',
        }
    if request.user.is_anonymous():
        return auth_login(request, **defaults)
    elif request.user.is_owner():
        return redirect('/asdasdasd')

    return auth_login(request, **defaults)

Reading the code:
1. Login function
2. If the user is anonymous, login.
3. If the user is not anonymous and the is_owner() method returns True, redirect.
4. In all other cases - log in.
Accordingly, the is_owner() check occurs only if the user is authorized and tries to enter the login page. Now about the errors:
1. It is not clear why the standard authentication function is twitching.
2. I don't think the meaning of the is_owner check makes sense at all.
3. It can be simplified to the form:
def login(request):
    defaults = {
        'authentication_form': CustomAuthForm,
        'template_name': 'accounts/login.html',
        }
    if not request.user.is_authenticated() and request.user.is_owner():
        return redirect('/asdasdasd')
    return auth_login(request, **defaults)

Now about the question:
The user logged in and entered a login / password. He was transferred to the standard Django authorization View (in other words, this view is not needed at all: all it does is redirect ), so he entered without any checks for the owner.
To solve the problem, you need to write your own login view.
PS What strange users have appeared at my beloved Django lately. It's already breathtaking.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question