File: forms.rst

package info (click to toggle)
django-allauth 65.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,672 kB
  • sloc: python: 34,411; javascript: 3,070; xml: 849; makefile: 235; sh: 8
file content (213 lines) | stat: -rw-r--r-- 5,244 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
Forms
=====

Login
*****

*Path*:
  ``allauth.account.forms.LoginForm``
*Used on*:
  `account_login <views.html#login-account-login>`__ view.

Example override::

    from allauth.account.forms import LoginForm
    class MyCustomLoginForm(LoginForm):

        def login(self, *args, **kwargs):

            # Add your own processing here.

            # You must return the original result.
            return super(MyCustomLoginForm, self).login(*args, **kwargs)

You have access to the following:

- ``self.user`` is the User object that is logging in.

``settings.py``::

    ACCOUNT_FORMS = {'login': 'mysite.forms.MyCustomLoginForm'}

Signup
******

*Path*:
  ``allauth.account.forms.SignupForm``
*Used on*:
  `account_signup <views.html#signup-account-signup>`__ view.

Example override::

    from allauth.account.forms import SignupForm
    class MyCustomSignupForm(SignupForm):

        def save(self, request):

            # Ensure you call the parent class's save.
            # .save() returns a User object.
            user = super(MyCustomSignupForm, self).save(request)

            # Add your own processing here.

            # You must return the original result.
            return user

``settings.py``::

    ACCOUNT_FORMS = {'signup': 'mysite.forms.MyCustomSignupForm'}


Add Email
*********

*Path*:
  ``allauth.account.forms.AddEmailForm``
*Used on*:
   `account_email <views.html#emails-management-account-email>`__ view.

Example override::

    from allauth.account.forms import AddEmailForm
    class MyCustomAddEmailForm(AddEmailForm):

        def save(self, request):

            # Ensure you call the parent class's save.
            # .save() returns an allauth.account.models.EmailAddress object.
            email_address_obj = super(MyCustomAddEmailForm, self).save(request)

            # Add your own processing here.

            # You must return the original result.
            return email_address_obj

You have access to the following:

- ``self.user`` is the User object that is logged in.

``settings.py``::

    ACCOUNT_FORMS = {'add_email': 'mysite.forms.MyCustomAddEmailForm'}


Change Password
***************

*Path*:
  ``allauth.account.forms.ChangePasswordForm``
*Used on*:
  `account_change_password <views.html#password-management>`__ view.

Example override::

    from allauth.account.forms import ChangePasswordForm
    class MyCustomChangePasswordForm(ChangePasswordForm):

        def save(self):

            # Ensure you call the parent class's save.
            # .save() does not return anything
            super(MyCustomChangePasswordForm, self).save()

            # Add your own processing here.

You have access to the following:

- ``self.user`` is the User object that is logged in.

``settings.py``::

    ACCOUNT_FORMS = {'change_password': 'mysite.forms.MyCustomChangePasswordForm'}


Set Password
************

*Path*:
  ``allauth.account.forms.SetPasswordForm``
*Used on*:
  `account_set_password <views.html#password-management>`__ view.

Example override::

    from allauth.account.forms import SetPasswordForm
    class MyCustomSetPasswordForm(SetPasswordForm):

        def save(self):

            # Ensure you call the parent class's save.
            # .save() does not return anything
            super(MyCustomSetPasswordForm, self).save()

            # Add your own processing here.

You have access to the following:

- ``self.user`` is the User object that is logged in.

``settings.py``::

    ACCOUNT_FORMS = {'set_password': 'mysite.forms.MyCustomSetPasswordForm'}

Reset Password
**************

*Path*:
  ``allauth.account.forms.ResetPasswordForm``
*Used on*:
  `account_reset_password <views.html#password-reset-account-reset-password>`__ view.

Example override::

    from allauth.account.forms import ResetPasswordForm
    class MyCustomResetPasswordForm(ResetPasswordForm):

        def save(self, request):

            # Ensure you call the parent class's save.
            # .save() returns a string containing the email address supplied
            email_address = super(MyCustomResetPasswordForm, self).save(request)

            # Add your own processing here.

            # Ensure you return the original result
            return email_address

You have access to the following:

- ``self.users`` is a list of all possible User objects with matching email address.

``settings.py``::

    ACCOUNT_FORMS = {'reset_password': 'mysite.forms.MyCustomResetPasswordForm'}


Reset Password From Key
***********************

*Path*:
  ``allauth.account.forms.ResetPasswordKeyForm``
*Used on*:
  `account_reset_password <views.html#password-reset-account-reset-password>`__ view.

Example override::

    from allauth.account.forms import ResetPasswordKeyForm
    class MyCustomResetPasswordKeyForm(ResetPasswordKeyForm):

        def save(self):

            # Add your own processing here.

            # Ensure you call the parent class's save.
            # .save() does not return anything
            super(MyCustomResetPasswordKeyForm, self).save()

You have access to the following:

- ``self.user`` is the User object.

``settings.py``::

    ACCOUNT_FORMS = {'reset_password_from_key': 'mysite.forms.MyCustomResetPasswordKeyForm'}