mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-06-28 09:50:05 +00:00
registration and verify abuse WIP
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m27s
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m27s
This commit is contained in:
@ -2,10 +2,12 @@
|
||||
This is the models module for api.
|
||||
"""
|
||||
|
||||
from datetime import timedelta
|
||||
from django.contrib.auth.models import AbstractUser
|
||||
from django.db import models
|
||||
from .managers import CustomUserManager
|
||||
from django.utils import timezone
|
||||
import pyotp
|
||||
|
||||
|
||||
class User(AbstractUser):
|
||||
@ -34,6 +36,22 @@ class User(AbstractUser):
|
||||
objects = CustomUserManager()
|
||||
|
||||
|
||||
class TemporaryUser(User):
|
||||
otp_secret = models.CharField(max_length=50, default=pyotp.random_base32)
|
||||
otp_verified = models.BooleanField(default=False)
|
||||
|
||||
def generate_otp(self):
|
||||
totp = pyotp.TOTP(self.otp_secret, interval=300)
|
||||
return totp.now()
|
||||
|
||||
def verify_otp(self, otp):
|
||||
totp = pyotp.TOTP(self.otp_secret, interval=300)
|
||||
return totp.verify(otp)
|
||||
|
||||
def is_expired(self):
|
||||
return self.created_at < timezone.now() - timedelta(minutes=5)
|
||||
|
||||
|
||||
class Atoll(models.Model):
|
||||
name = models.CharField(max_length=255, unique=True)
|
||||
created_at = models.DateTimeField(default=timezone.now)
|
||||
|
Reference in New Issue
Block a user