0

I'm building a Django site where a user can register and do some stuff. After registering, the email should be confirmed.

Here is how a user is confirmed: in my database, i added a table called account_emailaddress. The verified column, in this table, will give 0 when the email address is not confirmed and 1 when it is confirmed.

Now, i have a template, this template should throw an error when the email address is equal to 0.

Is this doable at all? I don't know where to put my feet to do this, so can someone guide to me an approach to do this? I'm not using a custom user model edited by me, but the Django user model.

Here is what the template looks like:

I'm assuming i need to sort this in my template's file, by adding an if statement like the one below:

{% block content %}
{% if email_is_confirmed %}
<style>

</style>

<body>

<p> CONFIRMED </p>

<div> <p>Here goes a bunch of features</p> </div>       



</body>

{% else %}

<p> Your email is not confirmed </p>
{% endif %}
{% endblock %}
Jack022
  • 867
  • 6
  • 30
  • 91

1 Answers1

1

You don't say how your account_emailaddress table is linked to your user, whether it has a foreign key to the user table, or a column of an email address. I'll assume it's a one-to-one linked to the user. In which case, in a template, you can access the logged in user's object as user, and access the linked table as with any Django lookup, so e.g. user.account_emailaddress.verified (or whatever you have set the related_name to). In the template that would be:

{% if user.account_emailaddress.verified %}

You might also want to investigate packages such as django-verified-email-field or django-user-accounts.

M Somerville
  • 4,499
  • 30
  • 38
  • Hey! To handle the registration part i'm using Django-Allauth. I already tried your solution, but i always get the error 'email not confirmed', even when the email IS confirmed, so there must be some logical error somewhere – Jack022 Jun 08 '19 at 12:35
  • Right, okay, that information would have been very useful to know first! :) That makes it very different, because one user can have multiple email addresses with allauth and then you don't know if any/all are verified. You want to see https://stackoverflow.com/questions/54467321/how-to-tell-if-users-email-address-has-been-verified-using-django-allauth-res and associated answers. – M Somerville Jun 08 '19 at 13:04
  • I'm sorry for not telling it previously! Next time i'll provide it in my question. Thank you for your time and help! – Jack022 Jun 08 '19 at 13:10