“Autenticação personalizada do Django” Respostas de código

Django Authenticate com e -mail

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

Autenticação personalizada do 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

Autenticação personalizada do 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

Respostas semelhantes a “Autenticação personalizada do Django”

Perguntas semelhantes a “Autenticação personalizada do Django”

Procure respostas de código populares por idioma

Procurar outros idiomas de código