update login with email
This commit is contained in:
@@ -26,6 +26,12 @@ class ZendeskAdmin:
|
||||
email = os.getenv('ACCESS_CONTROLLER_API_EMAIL')
|
||||
token = os.getenv('ACCESS_CONTROLLER_API_TOKEN')
|
||||
password = os.getenv('ACCESS_CONTROLLER_API_PASSWORD')
|
||||
_instance=None
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if cls._instance is None:
|
||||
cls._instance = super().__new__(cls)
|
||||
return cls._instance
|
||||
|
||||
def __init__(self):
|
||||
self.create_admin()
|
||||
@@ -73,10 +79,7 @@ class ZendeskAdmin:
|
||||
|
||||
def get_user_image(self, email: str) -> str:
|
||||
"""
|
||||
Функция **get_user_image** возвращает аватар пользователя
|
||||
|
||||
:param user_image: Аватар пользователя
|
||||
:type user_image: :class:`img`
|
||||
Функция **get_user_image** возвращает url-ссылку на аватар пользователя
|
||||
"""
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.photo['content_url'] if user.photo else None
|
||||
@@ -86,7 +89,7 @@ class ZendeskAdmin:
|
||||
|
||||
def get_user_org(self, email: str) -> str:
|
||||
user = self.admin.users.search(email).values[0]
|
||||
return user.organization.name
|
||||
return user.organization.name
|
||||
|
||||
def create_admin(self) -> None:
|
||||
"""
|
||||
@@ -140,7 +143,7 @@ def check_user_exist(email: str) -> bool:
|
||||
return ZendeskAdmin().check_user(email)
|
||||
|
||||
|
||||
def get_user_organization(email: str) -> bool:
|
||||
def get_user_organization(email: str) -> str:
|
||||
"""
|
||||
Функция возвращает организацию пользователя
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from django import forms
|
||||
from django.contrib.auth.forms import AuthenticationForm
|
||||
from django_registration.forms import RegistrationFormUniqueEmail
|
||||
|
||||
|
||||
@@ -6,11 +7,7 @@ class CustomRegistrationForm(RegistrationFormUniqueEmail):
|
||||
"""
|
||||
Форма для регистрации :class:`django_registration.forms.RegistrationFormUniqueEmail`
|
||||
с добавлением bootstrap-класса 'form-control'
|
||||
|
||||
:param password_zen: Поле для ввода пароля от Zendesk
|
||||
:type password_zen: :class:`django.forms.CharField`
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
for visible in self.visible_fields():
|
||||
@@ -24,3 +21,21 @@ class CustomRegistrationForm(RegistrationFormUniqueEmail):
|
||||
|
||||
class Meta(RegistrationFormUniqueEmail.Meta):
|
||||
fields = RegistrationFormUniqueEmail.Meta.fields
|
||||
|
||||
|
||||
class CustomAuthenticationForm(AuthenticationForm):
|
||||
"""
|
||||
Форма для авторизации :class:`django.contrib.auth.forms.AuthenticationForm`
|
||||
с изменением поля username на email
|
||||
"""
|
||||
username = forms.CharField(
|
||||
label="Электронная почта",
|
||||
widget=forms.EmailInput(),
|
||||
)
|
||||
error_messages = {
|
||||
'invalid_login':
|
||||
"Пожалуйста, введите правильные электронную почту и пароль. Оба поля "
|
||||
"могут быть чувствительны к регистру."
|
||||
,
|
||||
'inactive': "Аккаунт не активен.",
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
import logging
|
||||
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.forms import PasswordResetForm
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.tokens import default_token_generator
|
||||
from django.contrib.auth.views import LoginView
|
||||
from django.shortcuts import render
|
||||
from django.urls import reverse_lazy
|
||||
from django_registration.backends.one_step.views import RegistrationView
|
||||
from django_registration.views import RegistrationView
|
||||
|
||||
from access_controller.settings import EMAIL_HOST_USER
|
||||
from main.extra_func import check_user_exist, update_profile, get_user_organization
|
||||
from main.forms import CustomRegistrationForm
|
||||
from django_registration.views import RegistrationView
|
||||
from django.contrib.auth.decorators import login_required
|
||||
import logging
|
||||
|
||||
from main.forms import CustomRegistrationForm, CustomAuthenticationForm
|
||||
|
||||
|
||||
class CustomRegistrationView(RegistrationView):
|
||||
@@ -89,3 +88,10 @@ def main_page(request):
|
||||
logger = logging.getLogger('main.index')
|
||||
logger.info('Index page opened')
|
||||
return render(request, 'pages/index.html')
|
||||
|
||||
|
||||
class CustomLoginView(LoginView):
|
||||
"""
|
||||
Отображение страницы авторизации пользователя
|
||||
"""
|
||||
form_class = CustomAuthenticationForm
|
||||
|
||||
Reference in New Issue
Block a user