mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-11-02 14:59:02 +00:00
feat: 添加 临时 password (#8035)
* perf: 添加 template password * perf: 修改id * perf: 修改 翻译 * perf: 修改 tmp token * perf: 修改 token Co-authored-by: ibuler <ibuler@qq.com>
This commit is contained in:
26
apps/authentication/backends/token.py
Normal file
26
apps/authentication/backends/token.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from django.utils import timezone
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
||||
from authentication.models import TempToken
|
||||
from .base import JMSModelBackend
|
||||
|
||||
|
||||
class TempTokenAuthBackend(JMSModelBackend):
|
||||
model = TempToken
|
||||
|
||||
def authenticate(self, request, username='', password='', *args, **kwargs):
|
||||
token = self.model.objects.filter(username=username, secret=password).first()
|
||||
if not token:
|
||||
return None
|
||||
if not token.is_valid:
|
||||
raise PermissionDenied('Token is invalid, expired at {}'.format(token.date_expired))
|
||||
|
||||
token.verified = True
|
||||
token.date_verified = timezone.now()
|
||||
token.save()
|
||||
return token.user
|
||||
|
||||
@staticmethod
|
||||
def is_enabled():
|
||||
return settings.AUTH_TEMP_TOKEN
|
||||
Reference in New Issue
Block a user