Switching Username to Email in Django Authentication | Django User Model Customization

  Рет қаралды 8,919

Pyplane

Pyplane

Күн бұрын

Пікірлер: 12
@rangabharath4253
@rangabharath4253 Жыл бұрын
Awesome as always 🥳🎉
@Pyplane
@Pyplane Жыл бұрын
Thanks Ranga 🙌💪
@parham6676
@parham6676 2 ай бұрын
If I'm understanding this correctly, you had to pass a username in order to create a superuser, but I want to delete username alltogether and only use email.
@JorgeRamirez01
@JorgeRamirez01 Жыл бұрын
Thanks for the tutorial! What happens if you want to implement this approach on an existing project? I see that in this video you deleted the database, but what happens if you can't do that? Is there another way? Or recreating the database is the only way to do it? Thanks!
@Pyplane
@Pyplane Жыл бұрын
I did it because it is the easiest way. If you change the user model on an existing project you most likely will get errors. If you decide to do it be sure to backup your data. Good luck!
@faizannazir5596
@faizannazir5596 Жыл бұрын
User._meta.get_field('username')._unique = False User._meta.get_field('email')._unique = True User.USERNAME_FIELD = 'email' User.REQUIRED_FIELDS.remove('email') User.REQUIRED_FIELDS.append('username') class AppUser(User): department = models.CharField(max_length=50) picture = models.ImageField() db_picture = models.BinaryField(verbose_name="Image_db",editable=True,null=True,blank=True) date_of_birth = models.DateField(validators=[validate_at_least_18_years_old]) joining_date = models.DateField(validators=[validate_not_after_today]) customBackend from django.contrib.auth.backends import BaseBackend from django.contrib.auth.models import User class EmailBackend(BaseBackend): def authenticate(self, request, email=None, password=None, **kwargs): try: user = User.objects.get(email=email) if user.check_password(password): return user except User.DoesNotExist: return None def get_user(self, user_id): try: return User.objects.get(pk=user_id) except User.DoesNotExist: return None # change to custom backend in settings AUTHENTICATION_BACKENDS = [ 'myapp.backends.EmailBackend', 'django.contrib.auth.backends.ModelBackend', ]
@UserHuge
@UserHuge 7 ай бұрын
You should write a custom migration to move your users from the old model/table to the new one. Ideally test it aside on a copy of your prod db.
@bastianvalero4612
@bastianvalero4612 Жыл бұрын
Hi! If you were to create a project of an eCommerce and separate the Normal users from sellers would you do it with abstractbaseuser or you would create a usermanager(BaseUserManager) and then create the normaluser(abstractuser) and seller(abstractuser)? cuz both would have different GUIs and functionalities, Last question, If the website was planned to be scaled in the future and wanted to have jwt auth or oAuth 2.0 would the path be similar or how it would be? Also, do you have a video on this topic? If so I'd apprecciate the link, and sorry for so many questions, but I recently started to read this same docummentation and was wondering these things. Thank you
@murtalaisyakuabdulhamid9115
@murtalaisyakuabdulhamid9115 Жыл бұрын
You are the best 😂😂
@faizannazir5596
@faizannazir5596 Жыл бұрын
we can also inherit from USER model
@eugene_mountainland
@eugene_mountainland Жыл бұрын
thanks a lot)
@Pyplane
@Pyplane Жыл бұрын
Glad you liked it 🙌
Custom User Model with email login (DJANGO)
39:21
CodingWithMitch
Рет қаралды 47 М.
Vampire SUCKS Human Energy 🧛🏻‍♂️🪫 (ft. @StevenHe )
0:34
Alan Chikin Chow
Рет қаралды 138 МЛН
-5+3은 뭔가요? 📚 #shorts
0:19
5 분 Tricks
Рет қаралды 13 МЛН
Custom User Model | Explore Django
14:01
Code With Stein
Рет қаралды 42 М.
Django Starter with Allauth and Htmx
43:09
Andreas Jud
Рет қаралды 10 М.
User registration and authentication in Django
58:35
Cloud With Django
Рет қаралды 38 М.
Login and Logout - Django Wednesdays ECommerce 7
20:33
Codemy.com
Рет қаралды 17 М.
Django Login Form and User Authentication
17:01
Dave Gray
Рет қаралды 19 М.
programming projects that taught me how to code
9:49
isak
Рет қаралды 314 М.
Стыдные вопросы про Китай / вДудь
3:07:50
вДудь
Рет қаралды 2,3 МЛН