M
M
max32772019-05-27 12:52:42
Django
max3277, 2019-05-27 12:52:42

How to make authorization in django through VK by email?

I made a custom user model, where authorization in django occurs by email, and not by login.

# users/models.py
from django.contrib.auth.models import AbstractUser
from django.db import models


class CustomUser(AbstractUser):
    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []
    email = models.EmailField(unique=True)

User registration form
# users/forms.py
from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm

from .models import CustomUser

class CustomUserCreationForm(UserCreationForm):
    class Meta(UserCreationForm.Meta):
        model = CustomUser
        fields = ('email',) # new

class CustomUserChangeForm(UserChangeForm):
    class Meta:
        model = CustomUser
        fields = ('email', ) # new

I use VK authorization through django-social-auth. The problem is that not all users have mail on the VK page and an error occurs Duplicate entry '' for key 'users_customuser_email
1. How to force the user to ask for email.
2. Should I link Django users and VK users by email?
3. How to remake the VK authorization backend through mail, and not by login.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question