mirror of https://github.com/jumpserver/jumpserver
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
945 B
27 lines
945 B
2 years ago
|
from django.utils import timezone
|
||
|
from django.utils.translation import ugettext_lazy as _
|
||
|
|
||
|
from django.db import models
|
||
|
from common.db.models import JMSBaseModel
|
||
|
|
||
|
|
||
|
class TempToken(JMSBaseModel):
|
||
|
username = models.CharField(max_length=128, verbose_name=_("Username"))
|
||
|
secret = models.CharField(max_length=64, verbose_name=_("Secret"))
|
||
|
verified = models.BooleanField(default=False, verbose_name=_("Verified"))
|
||
|
date_verified = models.DateTimeField(null=True, verbose_name=_("Date verified"))
|
||
|
date_expired = models.DateTimeField(verbose_name=_("Date expired"))
|
||
|
|
||
|
class Meta:
|
||
|
verbose_name = _("Temporary token")
|
||
|
|
||
|
@property
|
||
|
def user(self):
|
||
|
from users.models import User
|
||
|
return User.objects.filter(username=self.username).first()
|
||
|
|
||
|
@property
|
||
|
def is_valid(self):
|
||
|
not_expired = self.date_expired and self.date_expired > timezone.now()
|
||
|
return not self.verified and not_expired
|