Django allauth using E-mail as unique identifier but also not


#1

So I’m wondering, nowadays it is normal to use your email address to login into an ecommerce website and make a purchase, or buy an airplane ticket. We could do this both as a guest as well as a registered user.

This makes me wonder;

  • Can we use ‘email’ as a unique identifier through django-allauth; Yes we can
  • To make it possible to place an order as guest, we should not create a unique constrain on the ‘email’ field. (otherwise the same guest could not place an order twice); We could

But can we do both? Use the ‘email’ as a unique identifier but also remove the unique constrained on the same field?


(Vitor Freitas) #2

You would have to remove the constraint at database level and control it on your application

So the database won’t complain if it receive a duplicated email address, but then in your code you control this in the form validations and adding those rules in the business logic

But I would just have an additional field, a flag like is_guest and silently create an account, without password. Just the email address. Then if the person tries to buy something again, you can reuse the same internal account. If at some point this person decides to have an account on your website, you simply convert the guest account into a regular account and let the user set a password.