88 lines
2.6 KiB
Python
88 lines
2.6 KiB
Python
# Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
from django.db import models
|
|
from django.contrib.auth.models import User
|
|
from django.utils.http import urlencode
|
|
from django.urls import reverse
|
|
|
|
from .utils import gen_secret
|
|
|
|
|
|
class AccountConfirmChallenge(models.Model):
|
|
owned_by = models.OneToOneField(User, on_delete=models.CASCADE)
|
|
public_ref = models.CharField(
|
|
"Public referece to challenge text",
|
|
unique=True,
|
|
max_length=32,
|
|
default=gen_secret,
|
|
editable=False,
|
|
)
|
|
created_at = models.DateTimeField(auto_now_add=True, blank=True)
|
|
|
|
challenge_text = models.CharField(
|
|
"Challenge text",
|
|
unique=True,
|
|
max_length=32,
|
|
default=gen_secret,
|
|
editable=False,
|
|
primary_key=True,
|
|
)
|
|
|
|
def __str__(self):
|
|
return f"{self.challenge_text}"
|
|
|
|
def verification_link(self):
|
|
"""
|
|
Get verification link
|
|
"""
|
|
return reverse("accounts.verify", args=(self.challenge_text,))
|
|
|
|
def pending_url(self):
|
|
return reverse("accounts.verify.pending", args=(self.public_ref,))
|
|
|
|
|
|
class PasswordResetChallenge(models.Model):
|
|
owned_by = models.OneToOneField(User, on_delete=models.CASCADE)
|
|
public_ref = models.CharField(
|
|
"Public referece to challenge text",
|
|
unique=True,
|
|
max_length=32,
|
|
default=gen_secret,
|
|
editable=False,
|
|
)
|
|
created_at = models.DateTimeField(auto_now_add=True, blank=True)
|
|
|
|
challenge_text = models.CharField(
|
|
"Challenge text",
|
|
unique=True,
|
|
max_length=32,
|
|
default=gen_secret,
|
|
editable=False,
|
|
primary_key=True,
|
|
)
|
|
|
|
def __str__(self):
|
|
return f"{self.challenge_text}"
|
|
|
|
def verification_link(self):
|
|
"""
|
|
Get verification link
|
|
"""
|
|
return reverse("accounts.password.reset", args=(self.challenge_text,))
|
|
|
|
def pending_url(self):
|
|
return reverse("accounts.password.reset.resend", args=(self.public_ref,))
|