“Niestandardowe uwierzytelnianie Django” Kod odpowiedzi

Django uwierzytelnianie z e -mailem

from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend

class EmailBackend(ModelBackend):
    def authenticate(self, request, username=None, password=None, **kwargs):
        UserModel = get_user_model()
        try:
            user = UserModel.objects.get(email=username)
        except UserModel.DoesNotExist:
            return None
        else:
            if user.check_password(password):
                return user
        return None
Tony Chanel

Niestandardowe uwierzytelnianie Django

def getLogin(request):
    if request.user.is_authenticated:
        return redirect('index')
    else:
        if request.method == "POST":
            user = request.POST.get('user')
            password = request.POST.get('pass')
            auth = authenticate(request, username=user, password=password)
            if auth is not None:
                login(request, auth)
                return redirect('index')
        return render(request, "login.html")
Coding with Nasir

Niestandardowe uwierzytelnianie Django

<form action="" method="POST">
    <div class="form-group">
        <label for="email" class="active">Email address</label>
        <input type="email" name="email" class="form-control" id="email" placeholder="Enter email">
        <div class="email-mg"></div>
    </div>
    <div class="form-group">
        <label for="password" class="active">Password</label>
        <input type="password" name="password" class="form-control" id="password" placeholder="Password">
        <div class="pass-mg"></div>
    </div>
    <button type="submit" class="btn btn-primary btn-block waves-effect waves-light" id="loginBtn">Log in</button>
</form>
Coding with Nasir

Odpowiedzi podobne do “Niestandardowe uwierzytelnianie Django”

Pytania podobne do “Niestandardowe uwierzytelnianie Django”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu