|
@@ -9,12 +9,24 @@ from django.contrib.auth.decorators import login_required
|
9
|
9
|
from django.contrib.auth.forms import AuthenticationForm
|
10
|
10
|
from django.utils.translation import gettext as _
|
11
|
11
|
from .forms import UserRegistrationForm, UserProfileForm
|
|
12
|
+import logging
|
12
|
13
|
from .models import get_userprofile
|
13
|
14
|
from themes import Context
|
14
|
15
|
import users
|
|
16
|
+from users import parameter
|
|
17
|
+
|
|
18
|
+# TODO: Implement password change.
|
|
19
|
+
|
|
20
|
+try:
|
|
21
|
+ from config import APP_NAME as ROOT_LOGGER_NAME
|
|
22
|
+except ImportError:
|
|
23
|
+ ROOT_LOGGER_NAME = 'root'
|
|
24
|
+logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
|
15
|
25
|
|
16
|
26
|
|
17
|
27
|
def password_recovery(request):
|
|
28
|
+ # TODO: Implement password recovery
|
|
29
|
+ messages.error(request, "Password recovery is not yet implemented!")
|
18
|
30
|
return redirect(request.GET.get('next') or '/')
|
19
|
31
|
|
20
|
32
|
|
|
@@ -53,20 +65,25 @@ def profile(request):
|
53
|
65
|
|
54
|
66
|
def register(request):
|
55
|
67
|
context = Context(request) # needs to be executed first because of time mesurement
|
56
|
|
- context_adaption(context, request, _('Register'))
|
57
|
|
- if not request.POST:
|
58
|
|
- form = UserRegistrationForm()
|
59
|
|
- messages.info(request, _('If you already have an account, login <a href="%(url)s">here</a>.') % {'url': users.url_login(request)})
|
60
|
|
- else:
|
61
|
|
- form = UserRegistrationForm(request.POST)
|
62
|
|
- if form.is_valid():
|
63
|
|
- form.save()
|
64
|
|
- messages.success(request, _('Your account has been created! You are able to log in as %(username)s.') % {'username': form.cleaned_data.get('username')})
|
65
|
|
- return redirect('users-login')
|
|
68
|
+ if parameter.get(parameter.USERS_SELF_REGISTRATION):
|
|
69
|
+ context_adaption(context, request, _('Register'))
|
|
70
|
+ if not request.POST:
|
|
71
|
+ form = UserRegistrationForm()
|
|
72
|
+ messages.info(request, _('If you already have an account, login <a href="%(url)s">here</a>.') % {'url': users.url_login(request)})
|
66
|
73
|
else:
|
67
|
|
- messages.error(request, _('Registration failed!'))
|
68
|
|
- context['form'] = form
|
69
|
|
- return render(request, 'users/register.html', context)
|
|
74
|
+ form = UserRegistrationForm(request.POST)
|
|
75
|
+ if form.is_valid():
|
|
76
|
+ form.save()
|
|
77
|
+ messages.success(request, _('Your account has been created! You are able to log in as %(username)s.') %
|
|
78
|
+ {'username': form.cleaned_data.get('username')})
|
|
79
|
+ return redirect('users-login')
|
|
80
|
+ else:
|
|
81
|
+ messages.error(request, _('Registration failed!'))
|
|
82
|
+ context['form'] = form
|
|
83
|
+ return render(request, 'users/register.html', context)
|
|
84
|
+ else:
|
|
85
|
+ messages.info(request, _("Self registration is deactivated. Contact your system administrator."))
|
|
86
|
+ return redirect('users-login')
|
70
|
87
|
|
71
|
88
|
|
72
|
89
|
def login(request):
|
|
@@ -74,7 +91,8 @@ def login(request):
|
74
|
91
|
context_adaption(context, request, _('Login'))
|
75
|
92
|
if not request.POST:
|
76
|
93
|
form = AuthenticationForm()
|
77
|
|
- messages.info(request, _('If you don\'t have an acount, register <a href="%(url)s">here</a>.') % {'url': users.url_register(request)})
|
|
94
|
+ if parameter.get(parameter.USERS_SELF_REGISTRATION):
|
|
95
|
+ messages.info(request, _('If you don\'t have an acount, register <a href="%(url)s">here</a>.') % {'url': users.url_register(request)})
|
78
|
96
|
else:
|
79
|
97
|
form = AuthenticationForm(request, data=request.POST)
|
80
|
98
|
if form.is_valid():
|
|
@@ -84,7 +102,13 @@ def login(request):
|
84
|
102
|
messages.success(request, _('You are now logged in as %(username)s.') % {'username': username})
|
85
|
103
|
return redirect(request.GET.get('next') or '/')
|
86
|
104
|
else:
|
87
|
|
- messages.error(request, _('Login failed! You can do a password recorvery <a href="%(url_recover)s">here</a> or you can register <a href="%(url_register)s">here</a>.') % {'url_register': users.url_register(request), 'url_recover': users.url_password_recovery(request)})
|
|
105
|
+ if parameter.get(parameter.USERS_SELF_REGISTRATION):
|
|
106
|
+ messages.error(request, _('Login failed! You can do a password recorvery <a href="%(url_recover)s">here</a> or you can register <a href="%(url_register)s">here</a>.') %
|
|
107
|
+ {'url_register': users.url_register(request), 'url_recover': users.url_password_recovery(request)})
|
|
108
|
+ else:
|
|
109
|
+ messages.error(request, _('Login failed! You can do a password recorvery <a href="%(url_recover)s">here</a>.') %
|
|
110
|
+ {'url_recover': users.url_password_recovery(request)})
|
|
111
|
+
|
88
|
112
|
context['form'] = form
|
89
|
113
|
return render(request, 'users/login.html', context)
|
90
|
114
|
|