您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
一、ITIL即IT基础架构库(Information Technology Infrastructure Library, ITIL,信息技术基础架构库)由英国政府部门CCTA(Central Computing and Telecommunications Agency)在20世纪80年代末制订,现由英国商务部OGC(Office of Government Commerce)负责管理,主要适用于IT服务管理(ITSM)。ITIL为企业的IT服务管理实践提供了一个客观、严谨、可量化的标准和规范。
二、Django用户自定义认证
1、创建models.py
from
django.db
import
models
import
hashlib
#自己的后台数据库表.account
class
Account(models.Model):
username
=
models.CharField(u
"用户名"
,blank
=
True
,max_length
=
32
)
password
=
models.CharField(u
"密码"
,blank
=
True
,max_length
=
50
)
domain
=
models.CharField(u
"可操作域名"
,blank
=
True
,max_length
=
256
,help_text
=
'填写多个域名,以,号分隔'
)
is_active
=
models.IntegerField(u
"is_active"
,blank
=
True
)
phone
=
models.CharField(u
"电话"
,max_length
=
50
)
mail
=
models.CharField(u
"邮箱"
,max_length
=
50
)
def
__unicode__(
self
):
return
self
.username
def
is_authenticated(
self
):
return
True
def
hashed_password(
self
, password
=
None
):
if
not
password:
return
self
.password
else
:
return
hashlib.md5(password).hexdigest()
def
check_password(
self
, password):
if
self
.hashed_password(password)
=
=
self
.password:
#if password == self.password:
return
True
return
False
class
Meta:
db_table
=
"account"
2、auth.py
rom
django.contrib.auth.models
import
User
from
myauth.models
import
Account
class
MyCustomBackend:
def
authenticate(
self
, username
=
None
, password
=
None
):
try
:
user
=
Account.objects.get(username
=
username)
except
Account.DoesNotExist:
return
None
else
:
if
user.check_password(password):
try
:
django_user
=
User.objects.get(username
=
user.username)
except
User.DoesNotExist:
#当在django中找不到此用户,便创建这个用户
django_user
=
User(username
=
user.username,password
=
user.password)
django_user.is_staff
=
True
django_user.save()
return
django_user
else
:
return
None
def
get_user(
self
, user_id):
try
:
return
User.objects.get(pk
=
user_id)
except
User.DoesNotExist:
return
None
3、把自己创建的表也加入到进去,admin.py
from
myauth.models
import
Account
from
django.contrib
import
admin
admin.site.register(Account)
4、在settings.py中添加认证:
AUTHENTICATION_BACKENDS
=
(
'myauth.auth.MyCustomBackend'
,
)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。