|
@@ -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):
|
|
@@ -158,20 +149,30 @@ def validate(request, uidb64, token):
|
158
|
149
|
myuser = None
|
159
|
150
|
|
160
|
151
|
if myuser is not None and generate_token.check_token(myuser, token):
|
161
|
|
- # Store mail validation to user profile
|
162
|
|
- profile = get_userprofile(myuser)
|
163
|
|
- profile.mail_validated = True
|
164
|
|
- profile.save()
|
165
|
|
- if not parameter.get(parameter.USERS_ADMIN_ACTIVATION):
|
166
|
|
- # Activate user
|
167
|
|
- 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
|
168
|
156
|
myuser.save()
|
169
|
|
- messages.success(request, _("Your Account has been activated."))
|
170
|
|
- return redirect('users-login')
|
171
|
|
- else:
|
172
|
|
- emails.send_activation_mail(myuser, request)
|
173
|
|
- 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."))
|
174
|
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("/")
|
175
|
176
|
else:
|
176
|
177
|
context_adaption(
|
177
|
178
|
context,
|