CMDB 知識點

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







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章