authenticate的执行流程与重写
流程
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的执行流程与重写的更多相关文章
- PHP解释器引擎执行流程 - [ PHP内核学习 ]
catalogue . SAPI接口 . PHP CLI模式解释执行脚本流程 . PHP Zend Complile/Execute函数接口化(Hook Call架构基础) 1. SAPI接口 PHP ...
- 追源索骥:透过源码看懂Flink核心框架的执行流程
li,ol.inline>li{display:inline-block;padding-right:5px;padding-left:5px}dl{margin-bottom:20px}dt, ...
- Mysql漂流系列(一):MySQL的执行流程
MySQL的执行流程 MySQL的执行流程: MySQL的执行流程分析: 1.当我们请求mysql服务器的时候,MySQL前端会有一个监听,请求到了之后,服务器得到相关的SQL语句,执行之前(虚线部分 ...
- Spring Security Oauth2 单点登录案例实现和执行流程剖析
Spring Security Oauth2 OAuth是一个关于授权的开放网络标准,在全世界得到的广泛的应用,目前是2.0的版本.OAuth2在“客户端”与“服务提供商”之间,设置了一个授权层(au ...
- Spring Security 案例实现和执行流程剖析
Spring Security Spring Security 是 Spring 社区的一个顶级项目,也是 Spring Boot 官方推荐使用的安全框架.除了常规的认证(Authentication ...
- workerman-todpole 执行流程(3)
通过前两篇文章的分析: workerman-todpole 执行流程(1) workerman-todpole 执行流程(2) 我们已经详细了解了主进程以及子进程的启动细节,但之前的文章并没有考虑 W ...
- workerman-todpole 执行流程(2)
上一篇文章 workerman-todpole 执行流程(1),我们已经分析完了主进程的执行流程,这篇文章主要分析一下子进程的 run() 流程. 有必要提一下,在 run() 开始之前,其实针对角色 ...
- Netty 源码 NioEventLoop(三)执行流程
Netty 源码 NioEventLoop(三)执行流程 Netty 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) 上文提到在启动 N ...
- Tomcat笔记:Tomcat的执行流程解析
Bootstrap的启动 Bootstrap的main方法先new了一个自己的对象(Bootstrap),然后用该对象主要执行了四个方法: init(); setAwait(true); load(a ...
随机推荐
- hibernate的API
程序源码: import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transa ...
- Mysql 创建只读账户
mysql 创建只读账户: 1.查询所有账号信息 SELECT DISTINCT a.`User`,a.`Host`,a.password_expired,a.password_last_change ...
- 开源项目 10 CSV
using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using Syst ...
- vue-cli3整体迁移至服务端渲染nuxtjs
vue项目与nuxt.js实在有着太多的不同,例如项目结构变化很大,router.js没了,vuex store写法有变化,router钩子没了等等.老项目毕竟也有一些体量,这么折腾我可接受不了,不过 ...
- SPA和MVVM设计思想
Vue基础篇设计模式SPAMVVMVue简介Vue的页面基本使用Vue的全局环境配置基本交互 插值表达式基础指令 v-text v-html v-pre v-once v-cloak v-on MVV ...
- 第09组 团队Git现场编程实战
组长博客链接 1.团队分工 团队成员 分工明细 王耀鑫 博客撰写,数据处理 陈志荣 前端界面,前端功能实现 陈超颖 前端界面,前端功能实现 沈梓耀 前端界面,前端功能实现 林明镇 数据处理 滕佳 前端 ...
- docker_基础用法
1. docker architecture 2. 命令
- 第07组 Beta冲刺(3/5)
队名:摇光 队长:杨明哲 组长博客:求戳 作业博客:求再戳 队长:杨明哲 过去两天完成了哪些任务 文字/口头描述:代码编辑器,目前没什么进展 展示GitHub当日代码/文档签入记录:(组内共用,已询问 ...
- Calcite分析 - RelTrait
RelTrait 表示RelNode的物理属性 由RelTraitDef代表RelTrait的类型 /** * RelTrait represents the manifestation of a r ...
- 日期正则表达式yyyyMMdd
日期校验yyyyMMdd, 包括闰月等校验. package com.xgcd; import java.util.regex.Matcher; import java.util.regex.Patt ...