|
|
@@ -5,11 +5,19 @@ from django.contrib.auth.forms import AuthenticationForm
|
|
5
|
5
|
from django.utils.translation import ugettext_lazy as _
|
|
6
|
6
|
from django.core.exceptions import ObjectDoesNotExist
|
|
7
|
7
|
from django import forms
|
|
|
8
|
+from django.db.models import get_model
|
|
8
|
9
|
from django.contrib.auth.models import User
|
|
|
10
|
+from django.contrib.auth import forms as auth_forms
|
|
9
|
11
|
from django.conf import settings
|
|
10
|
12
|
from django.core import validators
|
|
|
13
|
+from django.utils.http import int_to_base36
|
|
|
14
|
+from django.contrib.sites.models import get_current_site
|
|
|
15
|
+from django.contrib.auth.tokens import default_token_generator
|
|
11
|
16
|
|
|
12
|
|
-from oscar.core.loading import get_profile_class
|
|
|
17
|
+from oscar.core.loading import get_profile_class, get_class
|
|
|
18
|
+
|
|
|
19
|
+Dispatcher = get_class('customer.utils', 'Dispatcher')
|
|
|
20
|
+CommunicationEventType = get_model('customer', 'communicationeventtype')
|
|
13
|
21
|
|
|
14
|
22
|
|
|
15
|
23
|
def generate_username():
|
|
|
@@ -21,6 +29,54 @@ def generate_username():
|
|
21
|
29
|
return uname
|
|
22
|
30
|
|
|
23
|
31
|
|
|
|
32
|
+class PasswordResetForm(auth_forms.PasswordResetForm):
|
|
|
33
|
+ communication_type_code = "PASSWORD_RESET"
|
|
|
34
|
+
|
|
|
35
|
+ def save(self, subject_template_name='registration/password_reset_subject.txt',
|
|
|
36
|
+ email_template_name='registration/password_reset_email.html',
|
|
|
37
|
+ use_https=False, token_generator=default_token_generator,
|
|
|
38
|
+ from_email=None, request=None, **kwargs):
|
|
|
39
|
+ """
|
|
|
40
|
+ Generates a one-use only link for resetting password and sends to the
|
|
|
41
|
+ user.
|
|
|
42
|
+ """
|
|
|
43
|
+ for user in self.users_cache:
|
|
|
44
|
+ current_site = get_current_site(request)
|
|
|
45
|
+ ctx = {
|
|
|
46
|
+ 'email': user.email,
|
|
|
47
|
+ 'domain': current_site.domain,
|
|
|
48
|
+ 'site_name': current_site.name,
|
|
|
49
|
+ 'uid': int_to_base36(user.id),
|
|
|
50
|
+ 'token': token_generator.make_token(user),
|
|
|
51
|
+ 'protocol': use_https and 'https' or 'http',
|
|
|
52
|
+ 'site': current_site,
|
|
|
53
|
+ }
|
|
|
54
|
+ self.send_reset_email(user, ctx)
|
|
|
55
|
+
|
|
|
56
|
+ def send_reset_email(self, user, extra_context=None):
|
|
|
57
|
+ code = self.communication_type_code
|
|
|
58
|
+ ctx = {
|
|
|
59
|
+ 'user': user,
|
|
|
60
|
+ 'static_base_url': getattr(settings, 'OSCAR_STATIC_BASE_URL', None)
|
|
|
61
|
+ }
|
|
|
62
|
+
|
|
|
63
|
+ if extra_context:
|
|
|
64
|
+ ctx.update(extra_context)
|
|
|
65
|
+
|
|
|
66
|
+ try:
|
|
|
67
|
+ event_type = CommunicationEventType.objects.get(code=code)
|
|
|
68
|
+ except CommunicationEventType.DoesNotExist:
|
|
|
69
|
+ # No event in database, attempt to find templates for this type
|
|
|
70
|
+ messages = CommunicationEventType.objects.get_and_render(code, ctx)
|
|
|
71
|
+ else:
|
|
|
72
|
+ # Create order event
|
|
|
73
|
+ messages = event_type.get_messages(ctx)
|
|
|
74
|
+
|
|
|
75
|
+ if messages and messages['body']:
|
|
|
76
|
+ dispatcher = Dispatcher()
|
|
|
77
|
+ dispatcher.dispatch_user_messages(user, messages)
|
|
|
78
|
+
|
|
|
79
|
+
|
|
24
|
80
|
class EmailAuthenticationForm(AuthenticationForm):
|
|
25
|
81
|
"""
|
|
26
|
82
|
Extends the standard django AuthenticationForm, to support 75 character
|