Fix password reset, Fix docker env
This commit is contained in:
parent
0d1ff6ad04
commit
a0503af5ef
@ -1,7 +1,12 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.contrib.auth.forms import PasswordResetForm
|
||||||
|
|
||||||
from .models import LdapUser, LdapGroup
|
from .models import LdapUser, LdapGroup
|
||||||
from django.forms import modelformset_factory
|
from django.forms import modelformset_factory
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class AddLDAPUserForm(forms.Form):
|
class AddLDAPUserForm(forms.Form):
|
||||||
@ -67,3 +72,21 @@ UserFormset = modelformset_factory(
|
|||||||
fields=('dn',),
|
fields=('dn',),
|
||||||
extra=1
|
extra=1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
UserModel = get_user_model()
|
||||||
|
|
||||||
|
|
||||||
|
class LdapPasswordResetForm(PasswordResetForm):
|
||||||
|
def get_users(self, email):
|
||||||
|
"""Given an email, return matching user(s) who should receive a reset.
|
||||||
|
This allows subclasses to more easily customize the default policies
|
||||||
|
that prevent inactive users and users with unusable passwords from
|
||||||
|
resetting their password.
|
||||||
|
"""
|
||||||
|
logger.debug('Pasword reset get users')
|
||||||
|
active_users = UserModel._default_manager.filter(**{
|
||||||
|
'%s__iexact' % UserModel.get_email_field_name(): email,
|
||||||
|
'is_active': True,
|
||||||
|
})
|
||||||
|
logger.debug((u for u in active_users))
|
||||||
|
return (u for u in active_users)
|
||||||
|
|||||||
@ -411,3 +411,5 @@ class LdapPasswordChangeView(PasswordChangeView):
|
|||||||
LdapUser.base_dn = LdapUser.ROOT_DN
|
LdapUser.base_dn = LdapUser.ROOT_DN
|
||||||
LdapUser.password_reset(user, password)
|
LdapUser.password_reset(user, password)
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|||||||
DOMAIN = os.environ['DOMAIN']
|
DOMAIN = os.environ['DOMAIN']
|
||||||
SITE_NAME = os.environ['SITE_NAME']
|
SITE_NAME = os.environ['SITE_NAME']
|
||||||
SECRET_KEY = os.environ['SECRET_KEY']
|
SECRET_KEY = os.environ['SECRET_KEY']
|
||||||
DEBUG = os.environ.get('DEBUG', 'False') =='TRUE'
|
DEBUG = os.environ.get('DEBUG', 'False') =='True'
|
||||||
ALLOWED_HOSTS = os.environ['ALLOWED_HOSTS'].split()
|
ALLOWED_HOSTS = os.environ['ALLOWED_HOSTS'].split()
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
@ -176,8 +176,8 @@ else:
|
|||||||
EMAIL_TIMEOUT = 15
|
EMAIL_TIMEOUT = 15
|
||||||
EMAIL_HOST = os.environ['EMAIL_HOST']
|
EMAIL_HOST = os.environ['EMAIL_HOST']
|
||||||
EMAIL_PORT = int(os.environ['EMAIL_PORT'])
|
EMAIL_PORT = int(os.environ['EMAIL_PORT'])
|
||||||
EMAIL_USE_TLS = os.environ.get('EMAIL_USE_TLS', 'False') == 'TRUE'
|
EMAIL_USE_TLS = os.environ.get('EMAIL_USE_TLS', 'False') == 'True'
|
||||||
# EMAIL_USE_SSL = os.environ.get('EMAIL_USE_SSL', 'False') == 'TRUE'
|
EMAIL_USE_SSL = os.environ.get('EMAIL_USE_SSL', 'False') == 'True'
|
||||||
|
|
||||||
DEFAULT_FROM_EMAIL = os.environ['DEFAULT_FROM_EMAIL']
|
DEFAULT_FROM_EMAIL = os.environ['DEFAULT_FROM_EMAIL']
|
||||||
SERVER_EMAIL = os.environ['SERVER_EMAIL']
|
SERVER_EMAIL = os.environ['SERVER_EMAIL']
|
||||||
|
|||||||
@ -17,6 +17,7 @@ from django.contrib import admin
|
|||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from django.contrib.auth import views as auth_views
|
from django.contrib.auth import views as auth_views
|
||||||
from django.contrib.auth.decorators import user_passes_test
|
from django.contrib.auth.decorators import user_passes_test
|
||||||
|
from account_manager.forms import LdapPasswordResetForm
|
||||||
from .views import about
|
from .views import about
|
||||||
|
|
||||||
login_forbidden = user_passes_test(lambda u: u.is_anonymous(), '/')
|
login_forbidden = user_passes_test(lambda u: u.is_anonymous(), '/')
|
||||||
@ -24,10 +25,11 @@ login_forbidden = user_passes_test(lambda u: u.is_anonymous(), '/')
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', include('account_manager.urls')),
|
path('', include('account_manager.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('accounts/login/', auth_views.LoginView.as_view(redirect_authenticated_user=True), name='login'),
|
|
||||||
path('about/', about, name='about'),
|
path('about/', about, name='about'),
|
||||||
|
path('accounts/login/', auth_views.LoginView.as_view(redirect_authenticated_user=True), name='login'),
|
||||||
path('accounts/password_reset/',
|
path('accounts/password_reset/',
|
||||||
auth_views.PasswordResetView.as_view(html_email_template_name='registration/password_reset_email.html'),
|
auth_views.PasswordResetView.as_view(html_email_template_name='registration/password_reset_email.html',
|
||||||
|
form_class=LdapPasswordResetForm),
|
||||||
name='password_reset'),
|
name='password_reset'),
|
||||||
path('accounts/', include('django.contrib.auth.urls')),
|
path('accounts/', include('django.contrib.auth.urls')),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user