|
@@ -11,7 +11,7 @@ from django.contrib.auth.models import User
|
11
|
11
|
from django.utils.encoding import force_str
|
12
|
12
|
from django.utils.http import urlsafe_base64_decode
|
13
|
13
|
from django.utils.translation import gettext as _
|
14
|
|
-from .forms import UserRegistrationForm, UserProfileForm, UserActivationForm
|
|
14
|
+from .forms import UserRegistrationForm, UserProfileForm, UserActivationForm, UserPasswordChangeForm
|
15
|
15
|
import logging
|
16
|
16
|
from .models import get_userprofile
|
17
|
17
|
from themes import Context
|
|
@@ -28,37 +28,28 @@ def password_recovery(request):
|
28
|
28
|
return redirect(request.GET.get('next') or '/')
|
29
|
29
|
|
30
|
30
|
|
31
|
|
-def profile_post_actions(request, context):
|
32
|
|
- if request.POST:
|
33
|
|
- form = context.get('form_userprofile')
|
34
|
|
- if form.is_valid():
|
35
|
|
- form.save()
|
36
|
|
- return redirect(request.GET.get('next') or '/')
|
37
|
|
-
|
38
|
|
-
|
39
|
|
-def profile_pre_actions(request, context, form_to_be_used=UserProfileForm):
|
40
|
|
- profile = get_userprofile(request.user)
|
41
|
|
- if request.POST:
|
42
|
|
- form = form_to_be_used(request.POST, instance=profile)
|
43
|
|
- else:
|
44
|
|
- form = form_to_be_used(instance=profile)
|
45
|
|
- context['form_userprofile'] = form
|
46
|
|
-
|
47
|
|
-
|
48
|
31
|
@login_required
|
49
|
32
|
def profile(request):
|
50
|
33
|
context = Context(request) # needs to be executed first because of time mesurement
|
51
|
|
- profile_pre_actions(request, context)
|
52
|
|
- response = profile_post_actions(request, context)
|
53
|
|
- if response is not None:
|
54
|
|
- return response
|
|
34
|
+ profile = get_userprofile(request.user)
|
|
35
|
+ if request.POST:
|
|
36
|
+ form_userprofile = UserProfileForm(request.POST, instance=profile)
|
|
37
|
+ form_userchange = UserPasswordChangeForm(request)
|
|
38
|
+ if form_userprofile.is_valid() and form_userchange.is_valid():
|
|
39
|
+ form_userprofile.save()
|
|
40
|
+ form_userchange.save()
|
|
41
|
+ return redirect(request.GET.get('next') or '/')
|
55
|
42
|
else:
|
56
|
|
- context_adaption(
|
57
|
|
- context,
|
58
|
|
- request,
|
59
|
|
- _('Profile for %(username)s') % {'username': request.user.username},
|
60
|
|
- )
|
61
|
|
- return render(request, 'users/profile.html', context=context)
|
|
43
|
+ form_userprofile = UserProfileForm(instance=profile)
|
|
44
|
+ form_userchange = UserPasswordChangeForm(request)
|
|
45
|
+ context_adaption(
|
|
46
|
+ context,
|
|
47
|
+ request,
|
|
48
|
+ _('Profile for %(username)s') % {'username': request.user.username},
|
|
49
|
+ form_userprofile=form_userprofile,
|
|
50
|
+ form_userchange=form_userchange,
|
|
51
|
+ )
|
|
52
|
+ return render(request, 'users/profile.html', context=context)
|
62
|
53
|
|
63
|
54
|
|
64
|
55
|
def register(request):
|
|
@@ -108,8 +99,13 @@ def login(request):
|
108
|
99
|
return redirect(request.GET.get('next') or '/')
|
109
|
100
|
else:
|
110
|
101
|
username = form.cleaned_data.get('username')
|
111
|
|
- user = User.objects.get(username=username)
|
112
|
|
- if user.is_active:
|
|
102
|
+ try:
|
|
103
|
+ user = User.objects.get(username=username)
|
|
104
|
+ except User.DoesNotExist:
|
|
105
|
+ is_active = True
|
|
106
|
+ else:
|
|
107
|
+ is_active = user.is_active
|
|
108
|
+ if is_active:
|
113
|
109
|
if parameter.get(parameter.USERS_SELF_REGISTRATION):
|
114
|
110
|
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>.') %
|
115
|
111
|
{'url_register': users.url_register(request), 'url_recover': users.url_password_recovery(request)})
|
|
@@ -153,20 +149,30 @@ def validate(request, uidb64, token):
|
153
|
149
|
myuser = None
|
154
|
150
|
|
155
|
151
|
if myuser is not None and generate_token.check_token(myuser, token):
|
156
|
|
- # Store mail validation to user profile
|
157
|
|
- profile = get_userprofile(myuser)
|
158
|
|
- profile.mail_validated = True
|
159
|
|
- profile.save()
|
160
|
|
- if not parameter.get(parameter.USERS_ADMIN_ACTIVATION):
|
161
|
|
- # Activate user
|
162
|
|
- myuser.is_active = True
|
|
152
|
+ up = get_userprofile(myuser)
|
|
153
|
+ if up.mail_pending:
|
|
154
|
+ # change of email-address
|
|
155
|
+ myuser.email = up.mail_pending
|
163
|
156
|
myuser.save()
|
164
|
|
- messages.success(request, _("Your Account has been activated."))
|
165
|
|
- return redirect('users-login')
|
166
|
|
- else:
|
167
|
|
- emails.send_activation_mail(myuser, request)
|
168
|
|
- messages.success(request, _("Your Email has been validated. Wait for the administrator to activate your account"))
|
|
157
|
+ up.mail_pending = None
|
|
158
|
+ up.save()
|
|
159
|
+ messages.success(request, _("Your new email address is now active."))
|
169
|
160
|
return redirect("/")
|
|
161
|
+ else:
|
|
162
|
+ # Store mail validation to user profile
|
|
163
|
+ profile = get_userprofile(myuser)
|
|
164
|
+ profile.mail_validated = True
|
|
165
|
+ profile.save()
|
|
166
|
+ if not parameter.get(parameter.USERS_ADMIN_ACTIVATION):
|
|
167
|
+ # Activate user
|
|
168
|
+ myuser.is_active = True
|
|
169
|
+ myuser.save()
|
|
170
|
+ messages.success(request, _("Your Account has been activated."))
|
|
171
|
+ return redirect('users-login')
|
|
172
|
+ else:
|
|
173
|
+ emails.send_activation_mail(myuser, request)
|
|
174
|
+ messages.success(request, _("Your Email has been validated. Wait for the administrator to activate your account"))
|
|
175
|
+ return redirect("/")
|
170
|
176
|
else:
|
171
|
177
|
context_adaption(
|
172
|
178
|
context,
|