您好,登錄后才能下訂單哦!
一、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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。