Compare commits

...

2 Commits

Author SHA1 Message Date
PCoder eabf24946b Add nameko config 2019-02-23 13:20:55 +01:00
PCoder aec394fc20 Nameko related changes 2019-02-23 12:39:53 +01:00
5 changed files with 31 additions and 16 deletions

View File

@ -138,6 +138,17 @@ AUTH_LDAP_USER_ATTR_MAP = {
"email": "mail"
}
# Config to be passed to ClusterRpcProxy
NAMEKO_CONFIG = {
'AMQP_URL': 'amqp://127.0.0.1:5672/'
}
# Number of proxies to create
# Each proxy is a single threaded standalone ClusterRpcProxy
NAMEKO_POOL_SIZE = 4
# Set timeout for RPC
NAMEKO_TIMEOUT = 15 # timeout 15 seconds
LOGGING = {
'disable_existing_loggers': False,
'version': 1,

View File

@ -1,5 +1,5 @@
# The different URLs this service does use
from django.urls import path
#from django.conf.urls import url
from django.conf.urls import url
from django.contrib import admin
@ -7,14 +7,14 @@ from django.contrib import admin
from .views import Register, ChangeData, ChangePassword, ResetPassword, DeleteAccount, Index, LogOut, ResetRequest
urlpatterns = [
path('register/', Register.as_view(), name="register"),
path('changedata/', ChangeData.as_view(), name="change_data"),
path('resetpassword/', ResetPassword.as_view(), name="reset_password"),
path('changepassword/', ChangePassword.as_view(), name="change_password"),
path('deleteaccount/', DeleteAccount.as_view(), name="account_delete"),
path('index/', Index.as_view(), name="index"),
path('logout/', LogOut.as_view(), name="logout"),
path('reset/<str:user>/<str:token>/', ResetRequest.as_view()),
path('reset/', ResetRequest.as_view(), name="reset"),
path('', Index.as_view(), name="index"),
url('register/', Register.as_view(), name="register"),
url('changedata/', ChangeData.as_view(), name="change_data"),
url('resetpassword/', ResetPassword.as_view(), name="reset_password"),
url('changepassword/', ChangePassword.as_view(), name="change_password"),
url('deleteaccount/', DeleteAccount.as_view(), name="account_delete"),
url('index/', Index.as_view(), name="index"),
url('logout/', LogOut.as_view(), name="logout"),
url('reset/<str:user>/<str:token>/', ResetRequest.as_view()),
url('reset/', ResetRequest.as_view(), name="reset"),
url('', Index.as_view(), name="index"),
]

View File

@ -10,6 +10,7 @@ from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.core.mail import EmailMessage
from .models import ResetToken
from .forms import LoginForm
from django_nameko import get_pool
# Imports for the extra stuff not in django
@ -224,11 +225,12 @@ class ResetPassword(View):
return render(request, 'resetpassword.html')
def post(self, request):
l = LDAP()
urlname = 'reset_password'
service = 'send a password reset request'
user = request.POST.get('user')
# First, check if the user exists
if not check_user_exists(user):
if not l.check_user_exists(user):
return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': 'The user does not exist.' } )
# user exists, so try to get email
with get_pool().next() as rpc:
@ -250,7 +252,7 @@ class ResetPassword(View):
# getting epoch for the time now in UTC to spare us headache with timezones
creationtime = int(datetime.utcnow().timestamp())
# Construct the data for the email
email_from = 'Userservice at ungleich <%s>' % config['EMAIL']['EMAILFROM']
email_from = 'Userservice at ungleich <%s>' % 'support@ungleich.ch'
to = ['%s <%s>' % (user, email)]
subject = 'Password reset request for %s' % user
link = self.build_reset_link(user, creationtime)
@ -421,13 +423,14 @@ class DeleteAccount(View):
# Reads the filled out form
def post(self, request):
l = LDAP()
# Variables for error page
urlname = 'account_delete'
service = 'delete an account'
# Does the user exist?
username = request.POST.get('username')
if not check_user_exists(username):
if not l.check_user_exists(username):
return render(request, 'error.html', { 'urlname': urlname, 'service': service, 'error': 'Unknown user.' } )
# Do user and password match?

View File

@ -346,5 +346,5 @@ class Log(object):
def event_handler_ldap(self, payload):
f = open(self.ldaplog, mode='a', encoding='utf-8')
f.write(payload)
f.close
f.close()

View File

@ -1,6 +1,7 @@
django
django==1.11.20
django-auth-ldap
python-ldap
django-bootstrap3
django-filter==2.1.0
python-decouple
git+https://github.com/pcoder/django-nameko.git#egg=django-nameko