2022-06-10 17:04:57 +00:00
|
|
|
# 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/>.
|
|
|
|
|
2022-06-10 11:52:54 +00:00
|
|
|
from django.db import models
|
2022-06-10 17:04:57 +00:00
|
|
|
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,
|
|
|
|
)
|
2022-06-11 10:39:47 +00:00
|
|
|
created_at = models.DateTimeField(auto_now_add=True, blank=True)
|
2022-06-10 17:04:57 +00:00
|
|
|
|
|
|
|
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}"
|
2022-06-10 11:52:54 +00:00
|
|
|
|
2022-06-10 17:04:57 +00:00
|
|
|
def verification_link(self):
|
|
|
|
"""
|
|
|
|
Get verification link
|
|
|
|
"""
|
|
|
|
return reverse("accounts.verify", args=(self.challenge_text,))
|
2022-06-10 17:35:18 +00:00
|
|
|
|
|
|
|
def pending_url(self):
|
|
|
|
return reverse("accounts.verify.pending", args=(self.public_ref,))
|