流程

1.authenticate调用的是_get_backends函数
def authenticate(request=None, **credentials):
for backend, backend_path in _get_backends(return_tuples=True):
pass
2._get_backends,默认使用全局配置
def _get_backends(return_tuples=False):
backends = []
for backend_path in settings.AUTHENTICATION_BACKENDS:
pass
3.global_settings.py 使用django.contrib.auth.backends下的ModelBackend的类

django\conf\global_settings.py

AUTHENTICATION_BACKENDS = ['django.contrib.auth.backends.ModelBackend']
class ModelBackend:
def authenticate(self, request, username=None, password=None, **kwargs):
pass

重写(实现username或email登录验证)

可以在项目的setting中重写设定
AUTHENCICATION_BACLENDS = ['users.views.CustomBackend',]

users下的views.py

from django.contrib.auth.backends import ModelBackend
from .models import UserProfile
from django.db.models import Q class CustomBackend(ModelBackend):
def authenticate(self, request, username=None, password=None, **kwargs):
try:
user = UserProfile.objects.get(Q(username=username)|Q(email=username))
if user.check_password(password):
return user
except Exception as e:
return None
# UserProfile继承AbstractUser

当调用auth中的authenticate将执行上面的方法

from django.contrib.auth import authenticate
def user_login(request):
if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username=username,password=password)
# .......

authenticate的执行流程与重写的更多相关文章

  1. PHP解释器引擎执行流程 - [ PHP内核学习 ]

    catalogue . SAPI接口 . PHP CLI模式解释执行脚本流程 . PHP Zend Complile/Execute函数接口化(Hook Call架构基础) 1. SAPI接口 PHP ...

  2. 追源索骥:透过源码看懂Flink核心框架的执行流程

    li,ol.inline>li{display:inline-block;padding-right:5px;padding-left:5px}dl{margin-bottom:20px}dt, ...

  3. Mysql漂流系列(一):MySQL的执行流程

    MySQL的执行流程 MySQL的执行流程: MySQL的执行流程分析: 1.当我们请求mysql服务器的时候,MySQL前端会有一个监听,请求到了之后,服务器得到相关的SQL语句,执行之前(虚线部分 ...

  4. Spring Security Oauth2 单点登录案例实现和执行流程剖析

    Spring Security Oauth2 OAuth是一个关于授权的开放网络标准,在全世界得到的广泛的应用,目前是2.0的版本.OAuth2在“客户端”与“服务提供商”之间,设置了一个授权层(au ...

  5. Spring Security 案例实现和执行流程剖析

    Spring Security Spring Security 是 Spring 社区的一个顶级项目,也是 Spring Boot 官方推荐使用的安全框架.除了常规的认证(Authentication ...

  6. workerman-todpole 执行流程(3)

    通过前两篇文章的分析: workerman-todpole 执行流程(1) workerman-todpole 执行流程(2) 我们已经详细了解了主进程以及子进程的启动细节,但之前的文章并没有考虑 W ...

  7. workerman-todpole 执行流程(2)

    上一篇文章 workerman-todpole 执行流程(1),我们已经分析完了主进程的执行流程,这篇文章主要分析一下子进程的 run() 流程. 有必要提一下,在 run() 开始之前,其实针对角色 ...

  8. Netty 源码 NioEventLoop(三)执行流程

    Netty 源码 NioEventLoop(三)执行流程 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) 上文提到在启动 N ...

  9. Tomcat笔记:Tomcat的执行流程解析

    Bootstrap的启动 Bootstrap的main方法先new了一个自己的对象(Bootstrap),然后用该对象主要执行了四个方法: init(); setAwait(true); load(a ...

随机推荐

  1. git log filter(六)

    显示前10条提交记录: root@vmuer-VirtualBox:/media/vmuer/share/cmake-uart-server# git log -10 commit b056dacb0 ...

  2. hibernate实现增删改查

    1.需要先创建学生实体: package pers.zhb.domain; public class Student { private int studentno; private String s ...

  3. redis 设置为只读模式

    数据库的只读模式,对于在系统出现重大故障,但是又不影响用户的查询操作还是很重要的 对于redis 设置只读模式需要分不同的场景 master-slave cluster single master-s ...

  4. Xamarin.Forms 开发热加载利器 HotReload 推荐

    https://github.com/AndreiMisiukevich/HotReload

  5. 开源项目 06 NPOI

    using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using System; using S ...

  6. mysql find_in_set 函数 使用方法

    mysql> select * from user; +------+----------+-----------+ | id | name | address | +------+------ ...

  7. Ubuntu 安装MySQL报共享库找不到

    错误信息1: ./mysqld: error : cannot open shared object file: No such file or directory 解决办法:安装改库 # apt-g ...

  8. ubuntu之路——day13 只用python的numpy在较为底层的阶段实现单隐含层神经网络

    首先感谢这位博主整理的Andrew Ng的deeplearning.ai的相关作业:https://blog.csdn.net/u013733326/article/details/79827273 ...

  9. SpringMVC(上)

    一.SpringMVC简介 (1)springMVC概述 Spring MVC属于SpringFrameWork的后续产品,Spring 框架提供了构建 Web 应用程序的全功能 MVC 模块. 使用 ...

  10. Linux Shell:根据指定的文件列表 或 map配置,进行文件位置转移

    读取配置文件,进行文件位置转移 在whenb.csv中指定了需要从/home/root/cf/下移除到/home/root/cf_wh/下文件列表,whenb.csv中包含记录如下: enb- enb ...