一、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'
,
)