26 lines
942 B
Python
26 lines
942 B
Python
from django.contrib.auth.hashers import check_password, make_password
|
|
from django.db import models
|
|
|
|
from apps.core.models import SingletonConfiguration
|
|
|
|
|
|
class PhoneContactApiKey(SingletonConfiguration):
|
|
"""One database-managed credential for the read-only Phone contact feed."""
|
|
|
|
key_hash = models.CharField(max_length=128, editable=False)
|
|
is_active = models.BooleanField(default=True, verbose_name="فعال")
|
|
updated_at = models.DateTimeField(auto_now=True, verbose_name="آخرین تغییر")
|
|
|
|
class Meta:
|
|
verbose_name = "کلید API مخاطبان Phone"
|
|
verbose_name_plural = "کلید API مخاطبان Phone"
|
|
|
|
def set_key(self, raw_key):
|
|
self.key_hash = make_password(raw_key)
|
|
|
|
def accepts(self, raw_key):
|
|
return bool(self.is_active and self.key_hash and check_password(raw_key, self.key_hash))
|
|
|
|
def __str__(self):
|
|
return "کلید API مخاطبان Phone"
|