diff --git a/account/cbase_members.py b/account/cbase_members.py
index eddbebd..5845382 100644
--- a/account/cbase_members.py
+++ b/account/cbase_members.py
@@ -32,7 +32,13 @@ class MemberValues(object):
self._new = copy.deepcopy(self._old)
def get(self, key, default=None):
- value = self._new.get(key, default)[0]
+ value_list = self._new.get(key, default)
+ if value_list:
+ value = value_list[0]
+ else:
+ value = default
+
+ # Decode
if value == 'TRUE':
return True
elif value == 'FALSE':
@@ -78,6 +84,12 @@ class MemberValues(object):
result = l.modify_s(dn, mod_attrs)
print "result is: ", result
+ def to_dict(self):
+ result = {}
+ for key, value in self._new.items():
+ result[key] = self.get(key)
+ return result
+
def _get_bind_dn(self):
"""
Adds the uid=userid, to the base dn and returns that.
diff --git a/account/forms.py b/account/forms.py
index 376002b..ce32ab5 100644
--- a/account/forms.py
+++ b/account/forms.py
@@ -32,7 +32,7 @@ class WlanPresenceForm(forms.Form):
help_text=_('Enable WiFi presence?'))
-class PaswordForm(forms.Form):
+class PasswordForm(forms.Form):
password1 = forms.CharField(max_length=255, widget=forms.PasswordInput,
help_text=_('New password'))
password2 = forms.CharField(max_length=255, widget=forms.PasswordInput,
@@ -43,6 +43,14 @@ class RFIDForm(forms.Form):
rfid = forms.CharField(max_length=255, help_text=_('Your RFID'))
+class SIPPinForm(forms.Form):
+ sippin = forms.CharField(max_length=255, help_text=_('Your SIP PIN'))
+
+
class NRF24Form(forms.Form):
nrf24 = forms.CharField(max_length=255,
help_text=_('Your NRF24 identification'))
+
+
+class CLabPinForm(forms.Form):
+ c_lab_pin = GastroPinField(help_text=_('Your c-lab PIN'))
\ No newline at end of file
diff --git a/account/templates/clabpin.html b/account/templates/clabpin.html
new file mode 100644
index 0000000..13213ef
--- /dev/null
+++ b/account/templates/clabpin.html
@@ -0,0 +1,23 @@
+{% extends "form_base.html" %}
+{% load i18n %}
+{% load crispy_forms_tags %}
+
+{% block form_title %}{% trans "c-lab PIN"%}{% endblock %}
+
+{% block form_description %}
+
{% blocktrans %}Change your c-lab PIN to access the c-lab in the basement.{% endblocktrans %}
+{% endblock %}
+
+{% block form_fields %}
+ {{ form.non_field_errors }}
+
-
-
-
Gastro-Pin
- {% if message %}
-
{{ message }}
- {% endif %}
-
+{% block form_title %}{% trans "Gastro PIN"%}{% endblock %}
+
+{% block form_description %}
+
+
{% blocktrans %}Change your Gastro PIN to access the vending machines.
+ To use unlock member prices, press the A button then enter
+ your numeric user ID{% endblocktrans %}
+ {{ member.uidNumber }}
+ {% blocktrans %}and your Gastro PIN.{% endblocktrans %}
+{% endblock %}
+
+{% block form_fields %}
+ {{ form.non_field_errors }}
+
-{% endblock %}
+
+{% endblock form_fields %}
\ No newline at end of file
diff --git a/account/templates/login.html b/account/templates/login.html
index 8d90e55..8539c65 100644
--- a/account/templates/login.html
+++ b/account/templates/login.html
@@ -1,4 +1,6 @@
{% extends "base.html" %}
+{% load i18n %}
+{% load crispy_forms_tags %}
{% block body %}
@@ -7,13 +9,22 @@
-
+
+
+ Copyright © 2013 by c-base e.V.
+
{% endblock body %}
diff --git a/account/templates/member_base.html b/account/templates/member_base.html
new file mode 100644
index 0000000..67bfd7d
--- /dev/null
+++ b/account/templates/member_base.html
@@ -0,0 +1,47 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block body %}
+
+
+ {% block container %}{% endblock container %}
+
+
+
+ Copyright © 2013 by c-base e.V.
+
+
+{% endblock body %}
diff --git a/account/templates/password.html b/account/templates/password.html
new file mode 100644
index 0000000..f81d9a9
--- /dev/null
+++ b/account/templates/password.html
@@ -0,0 +1,23 @@
+{% extends "form_base.html" %}
+{% load i18n %}
+{% load crispy_forms_tags %}
+
+{% block form_title %}{% trans "Password"%}{% endblock %}
+
+{% block form_description %}
+
{% blocktrans %}You can change your password here.{% endblocktrans %}
+{% endblock %}
+
+{% block form_fields %}
+ {{ form.non_field_errors }}
+
+ {% csrf_token %}
+ {{ form|crispy }}
+
+
+
+ {% trans "Save"%}
+
+
+
+{% endblock form_fields %}
\ No newline at end of file
diff --git a/account/templates/sippin.html b/account/templates/sippin.html
new file mode 100644
index 0000000..b894a1d
--- /dev/null
+++ b/account/templates/sippin.html
@@ -0,0 +1,23 @@
+{% extends "form_base.html" %}
+{% load i18n %}
+{% load crispy_forms_tags %}
+
+{% block form_title %}{% trans "SIP PIN"%}{% endblock %}
+
+{% block form_description %}
+
{% blocktrans %}The SIP PIN is your access to the c-base SIP server for voice telephony.{% endblocktrans %}
+{% endblock %}
+
+{% block form_fields %}
+ {{ form.non_field_errors }}
+
+ {% csrf_token %}
+ {{ form|crispy }}
+
+
+
+ {% trans "Save"%}
+
+
+
+{% endblock form_fields %}
\ No newline at end of file
diff --git a/account/templates/start.html b/account/templates/start.html
new file mode 100644
index 0000000..c2b7861
--- /dev/null
+++ b/account/templates/start.html
@@ -0,0 +1,51 @@
+{% extends "member_base.html" %}
+{% load i18n %}
+
+{% block container %}
+
+
+
{% trans "Welcome to the c-base member interface" %}
+
{% blocktrans %}Here you can change
+ some parameters of your c-base member account.{% endblocktrans %}
+
+
{% trans "Basic information about your account" %}
+
+
+
+ {% trans "Your user ID:" %}
+ {{ member.uid }}
+ {% trans "Numeric user ID:" %}
+ {{ member.uidNumber }}
+ {% blocktrans %}The numeric user ID can be used to login with
+ the vending machines and network connected combination
+ locks.{% endblocktrans %}
+
+ {% trans "Your c-base e-mail address:" %}
+ {{ member.mail }}
+
+
+
+
{% trans "Management information" %}
+
+
+ {% trans "Name:" %}
+ {{ member.displayName }}
+
+
+ {% trans "External e-mail address:" %}
+ {{ member.externalEmail }}
+ {% blocktrans %}The external e-mail address is used by the
+ board of c-base to reach you in cases where your c-base
+ address (see above) is not working. To change your
+ externe e-mail address please contact the c-base board
+ (vorstand@c-base.org ).{% endblocktrans %}
+
+
+ {% trans "Your c-base member account balance:" %}
+ {% trans "Check balance" %}
+
+
+
+
+
+{% endblock container %}
\ No newline at end of file
diff --git a/account/urls.py b/account/urls.py
index 755e7f5..cb721bd 100644
--- a/account/urls.py
+++ b/account/urls.py
@@ -3,11 +3,15 @@ from django.conf.urls import patterns, url
urlpatterns = patterns(
'',
- url(r'^login/$', 'account.views.auth_login', name="auth_login"),
+ url(r'^login/$', 'account.views.auth_login', name="cbase_auth_login"),
url(r'^logout/$', 'account.views.auth_logout', name="auth_logout"),
url(r'^gastropin/$', 'account.views.gastropin', name='gastropin'),
url(r'^wlan_presence/$', 'account.views.wlan_presence', name='wlan_presence'),
url(r'^rfid/$', 'account.views.rfid', name='rfid'),
- url(r'^nrf24/$', 'account.views.nrf24', name='rfid'),
+ url(r'^nrf24/$', 'account.views.nrf24', name='nrf24'),
+ url(r'^password/$', 'account.views.password', name='password'),
+ url(r'^sippin/$', 'account.views.sippin', name='sippin'),
+ url(r'^clabpin/$', 'account.views.clabpin', name='clabpin'),
+ url(r'^$', 'account.views.home', name="home"),
url(r'^groups/(?P
[^/]+)/', 'account.views.groups_list'),
)
\ No newline at end of file
diff --git a/account/views.py b/account/views.py
index 4dd1fa2..222e886 100644
--- a/account/views.py
+++ b/account/views.py
@@ -12,10 +12,34 @@ from django.contrib.auth.models import Group
from django.shortcuts import render
from django.utils.translation import ugettext as _
-from forms import GastroPinForm, WlanPresenceForm, LoginForm, PaswordForm, \
- RFIDForm, NRF24Form
+from forms import GastroPinForm, WlanPresenceForm, LoginForm, PasswordForm, \
+ RFIDForm, NRF24Form, SIPPinForm, CLabPinForm
from cbase_members import MemberValues, retrieve_member
+
+def landingpage(request):
+ if request.user.is_authenticated():
+ return HttpResponseRedirect('/account')
+ form = LoginForm()
+ is_ceymaster = is_admin = False
+ if 'ceymaster' in [g.name for g in request.user.groups.all()]:
+ is_ceymaster = True
+ if 'ldap_admins' in [g.name for g in request.user.groups.all()]:
+ is_admin = True
+ groups = Group.objects.all()
+ admins = Group.objects.get(name="ldap_admins").user_set.all()
+
+ # values = get_user_values(request.user.username, request.session['ldap_password'])
+ #return render_to_response("dashboard.html", locals())
+ return render(request, 'base.html', {'form': form, 'admins': admins})
+
+@login_required
+def home(request):
+ member = retrieve_member(request)
+ context = {'member': member.to_dict()}
+ print context
+ return render(request, 'start.html', context)
+
def auth_login(request):
redirect_to = request.GET.get('next', '') or '/'
if request.method == 'POST':
@@ -44,6 +68,7 @@ def auth_login(request):
return render_to_response('login.html',
RequestContext(request, locals()))
+@login_required
def auth_logout(request):
redirect_to = request.GET.get('next', '') or '/'
logout(request)
@@ -51,19 +76,6 @@ def auth_logout(request):
response.delete_cookie('sessionkey')
return response
-def landingpage(request):
- is_ceymaster = is_admin = False
- if 'ceymaster' in [g.name for g in request.user.groups.all()]:
- is_ceymaster = True
- if 'ldap_admins' in [g.name for g in request.user.groups.all()]:
- is_admin = True
- groups = Group.objects.all()
- admins = Group.objects.get(name="ldap_admins").user_set.all()
- if request.user.is_authenticated():
- # values = get_user_values(request.user.username, request.session['ldap_password'])
- return render_to_response("dashboard.html", locals())
- return render_to_response("base.html", locals())
-
@login_required(redirect_field_name="/" ,login_url="/account/login/")
def groups_list(request, group_name):
group = get_object_or_404(Group, name=group_name)
@@ -76,24 +88,13 @@ def groups_list(request, group_name):
@login_required
def gastropin(request):
- if request.method == 'POST':
- form = GastroPinForm(request.POST)
- if form.is_valid():
- user = request.user
- user_profile = user.get_profile()
- user_profile.gastropin = form.cleaned_data['gastropin']
- user_profile.save()
- return render(request, 'gastropin.html',
- {'message': _('Your Gastro-PIN was changed. Thank you!'),
- 'form:': form})
- else:
- return render(request, 'gastropin.html', {'form:': form})
-
- else:
- form = GastroPinForm()
-
- return render(request, 'gastropin.html', {'form': form})
+ return set_ldap_field(request, GastroPinForm,
+ [('gastropin', 'gastropin')], 'gastropin.html')
+@login_required
+def sippin(request):
+ return set_ldap_field(request, SIPPinForm, [('sippin', 'sippin')],
+ 'sippin.html')
def set_ldap_field(request, form_type, field_names, template_name):
"""
@@ -112,15 +113,17 @@ def set_ldap_field(request, form_type, field_names, template_name):
member.save()
new_form = form_type(initial=initial)
return render(request, template_name,
- {'message': _('Your changes have been saved. Thank you!'),
- 'form': new_form})
+ {'message': _('Your changes have been saved. Thank you!'),
+ 'form': new_form, 'member': member.to_dict()})
else:
- return render(request, template_name, {'form:': form})
+ return render(request, template_name,
+ {'form:': form, 'member': member.to_dict()})
else:
for form_field, ldap_field in field_names:
initial[form_field] = member.get(ldap_field)
form = form_type(initial=initial)
- return render(request, template_name, {'form': form})
+ return render(request, template_name,
+ {'form': form, 'member': member.to_dict()})
@login_required
def wlan_presence(request):
@@ -135,4 +138,13 @@ def rfid(request):
def nrf24(request):
return set_ldap_field(request, NRF24Form, [('nrf24', 'nrf24')], 'nrf24.html')
+@login_required
+def password(request):
+ return set_ldap_field(request, PasswordForm, [('password1', 'password')],
+ 'password.html')
+
+@login_required
+def clabpin(request):
+ return set_ldap_field(request, CLabPinForm, [('c_lab_pin', 'c-labPIN')],
+ 'clabpin.html')
diff --git a/cbmi/templates/base.html b/cbmi/templates/base.html
index e237b80..da75bb4 100644
--- a/cbmi/templates/base.html
+++ b/cbmi/templates/base.html
@@ -1,4 +1,6 @@
{% load i18n %}
+{% load crispy_forms_tags %}
+
@@ -36,10 +38,12 @@
-
+ {% trans "c-base Member Interface" %}
- c-base member-interface {% if request.user.is_authenticated %}-> {{ request.user.username }}{% endif %}
+
+ {% if request.user.is_authenticated %}
+ {{ request.user.username }}{% endif %}
@@ -64,33 +68,18 @@
{% block body %}
-
{% block container %}
-
+
c-base member-interface
- Auf dieser Seite kann jedes Member seine LDAP-Daten editieren und u.A. sein Passwort neu setzen.
+ {% blocktrans %}On this website any member can view and
+ edit their data stored in the LDAP directory of
+ c-base.{% endblocktrans %}
- neumember können sich ihr initiales passwort mit einem der folgenden member setzen:
+ {% blocktrans %}If you are a new member and don't have a
+ password yet, please contact one of the following people:{% endblocktrans %}
{% for admin in admins %}
{{ admin}}
@@ -98,8 +87,27 @@
+
+
+
Login
+
+ {% csrf_token %}
+ {{ form|crispy }}
+
+
+ {% trans "Sign in" %}
+
+
+
+
+
{% endblock container %}
+
+
+ Copyright © 2013 by c-base e.V.
+
{% endblock body %}
diff --git a/cbmi/urls.py b/cbmi/urls.py
index 10bebbb..e52b3b9 100644
--- a/cbmi/urls.py
+++ b/cbmi/urls.py
@@ -11,6 +11,6 @@ urlpatterns = patterns('',
url(r'account/', include('account.urls')),
- url(r'^$', 'account.views.landingpage'),
+ url(r'^$', 'account.views.landingpage', name="landingpage"),
)