1Forms 2===== 3 4The following forms can be overridden as needed in order to: 5 6- Add extra fields for extra required information 7- Override save to add extra functionality on save 8 9Overriding Save 10--------------- 11 12If you decide to add fields to a form, you will need to 13manually save the custom fields' data. 14 15ACCOUNT_FORMS 16------------- 17 18Default Settings:: 19 20 ACCOUNT_FORMS = { 21 'login': 'allauth.account.forms.LoginForm', 22 'signup': 'allauth.account.forms.SignupForm', 23 'add_email': 'allauth.account.forms.AddEmailForm', 24 'change_password': 'allauth.account.forms.ChangePasswordForm', 25 'set_password': 'allauth.account.forms.SetPasswordForm', 26 'reset_password': 'allauth.account.forms.ResetPasswordForm', 27 'reset_password_from_key': 'allauth.account.forms.ResetPasswordKeyForm', 28 'disconnect': 'allauth.socialaccount.forms.DisconnectForm', 29 } 30 31login (``allauth.account.forms.LoginForm``) 32******************************************* 33 34Used on `account_login <views.html#login-account-login>`__ view. 35 36``save`` is not called, you need to override ``login`` 37:: 38 39 from allauth.account.forms import LoginForm 40 class MyCustomLoginForm(LoginForm): 41 42 def login(self, *args, **kwargs): 43 44 # Add your own processing here. 45 46 # You must return the original result. 47 return super(MyCustomLoginForm, self).login(*args, **kwargs) 48 49You have access to the following: 50 51- ``self.user`` is the User object that is logging in. 52 53``settings.py``:: 54 55 ACCOUNT_FORMS = {'login': 'mysite.forms.MyCustomLoginForm'} 56 57signup (``allauth.account.forms.SignupForm``) 58********************************************* 59 60Used on `account_signup <views.html#signup-account-signup>`__ view. 61 62:: 63 64 from allauth.account.forms import SignupForm 65 class MyCustomSignupForm(SignupForm): 66 67 def save(self, request): 68 69 # Ensure you call the parent class's save. 70 # .save() returns a User object. 71 user = super(MyCustomSignupForm, self).save(request) 72 73 # Add your own processing here. 74 75 # You must return the original result. 76 return user 77 78``settings.py``:: 79 80 ACCOUNT_FORMS = {'signup': 'mysite.forms.MyCustomSignupForm'} 81 82add_email (``allauth.account.forms.AddEmailForm``) 83************************************************** 84 85Used on `account_email <views.html#e-mails-management-account-email>`__ view. 86 87:: 88 89 from allauth.account.forms import AddEmailForm 90 class MyCustomAddEmailForm(AddEmailForm): 91 92 def save(self): 93 94 # Ensure you call the parent class's save. 95 # .save() returns an allauth.account.models.EmailAddress object. 96 email_address_obj = super(MyCustomAddEmailForm, self).save() 97 98 # Add your own processing here. 99 100 # You must return the original result. 101 return email_address_obj 102 103You have access to the following: 104 105- ``self.user`` is the User object that is logged in. 106 107``settings.py``:: 108 109 ACCOUNT_FORMS = {'add_email': 'mysite.forms.MyCustomAddEmailForm'} 110 111change_password (``allauth.account.forms.ChangePasswordForm``) 112************************************************************** 113 114Used on `account_change_password <views.html#password-management>`__ view. 115 116:: 117 118 from allauth.account.forms import ChangePasswordForm 119 class MyCustomChangePasswordForm(ChangePasswordForm): 120 121 def save(self): 122 123 # Ensure you call the parent class's save. 124 # .save() does not return anything 125 super(MyCustomChangePasswordForm, self).save() 126 127 # Add your own processing here. 128 129You have access to the following: 130 131- ``self.user`` is the User object that is logged in. 132 133``settings.py``:: 134 135 ACCOUNT_FORMS = {'change_password': 'mysite.forms.MyCustomChangePasswordForm'} 136 137set_password (``allauth.account.forms.SetPasswordForm``) 138******************************************************** 139 140Used on `account_set_password <views.html#password-management>`__ view. 141 142:: 143 144 from allauth.account.forms import SetPasswordForm 145 class MyCustomSetPasswordForm(SetPasswordForm): 146 147 def save(self): 148 149 # Ensure you call the parent class's save. 150 # .save() does not return anything 151 super(MyCustomSetPasswordForm, self).save() 152 153 # Add your own processing here. 154 155You have access to the following: 156 157- ``self.user`` is the User object that is logged in. 158 159``settings.py``:: 160 161 ACCOUNT_FORMS = {'set_password': 'mysite.forms.MyCustomSetPasswordForm'} 162 163reset_password (``allauth.account.forms.ResetPasswordForm``) 164************************************************************ 165 166Used on `account_reset_password <views.html#password-reset-account-reset-password>`__ view. 167 168:: 169 170 from allauth.account.forms import ResetPasswordForm 171 class MyCustomSetPasswordForm(ResetPasswordForm): 172 173 def save(self): 174 175 # Ensure you call the parent class's save. 176 # .save() returns a string containing the email address supplied 177 email_address = super(MyCustomResetPasswordForm, self).save() 178 179 # Add your own processing here. 180 181 # Ensure you return the original result 182 return email_address 183 184You have access to the following: 185 186- ``self.users`` is a list of all possible User objects with matching email address. 187 188``settings.py``:: 189 190 ACCOUNT_FORMS = {'reset_password': 'mysite.forms.MyCustomResetPasswordForm'} 191 192reset_password_from_key (``allauth.account.forms.ResetPasswordKeyForm``) 193************************************************************************ 194 195Used on `account_reset_password <views.html#password-reset-account-reset-password>`__ view. 196 197:: 198 199 from allauth.account.forms import ResetPasswordKeyForm 200 class MyCustomResetPasswordKeyForm(ResetPasswordKeyForm): 201 202 def save(self): 203 204 # Add your own processing here. 205 206 # Ensure you call the parent class's save. 207 # .save() does not return anything 208 super(MyCustomResetPasswordKeyForm, self).save() 209 210You have access to the following: 211 212- ``self.user`` is the User object. 213 214``settings.py``:: 215 216 ACCOUNT_FORMS = {'reset_password_from_key': 'mysite.forms.MyCustomResetPasswordKeyForm'} 217 218SOCIALACCOUNT_FORMS 219------------------- 220 221Default Settings:: 222 223 SOCIALACCOUNT_FORMS = { 224 'login': 'allauth.socialaccount.forms.DisconnectForm', 225 'signup': 'allauth.socialaccount.forms.SignupForm', 226 } 227 228signup (``allauth.socialaccount.forms.SignupForm``) 229*************************************************** 230 231Used on socialaccount_signup view used when someone initially signs up 232with a social account and needs to create an account. 233 234:: 235 236 from allauth.socialaccount.forms import SignupForm 237 class MyCustomSocialSignupForm(SignupForm): 238 239 def save(self): 240 241 # Ensure you call the parent class's save. 242 # .save() returns a User object. 243 user = super(MyCustomSocialSignupForm, self).save() 244 245 # Add your own processing here. 246 247 # You must return the original result. 248 return user 249 250You have access to the following: 251 252- ``self.socialaccount`` 253 254``settings.py``:: 255 256 SOCIALACCOUNT_FORMS = {'signup': 'mysite.forms.MyCustomSocialSignupForm'} 257 258disconnect (``allauth.socialaccount.forms.DisconnectForm``) 259*********************************************************** 260 261Used on socialaccount_connections view, used when removing a social account. 262 263:: 264 265 from allauth.socialaccount.forms import DisconnectForm 266 class MyCustomSocialDisconnectForm(DisconnectForm): 267 268 def save(self): 269 270 # Add your own processing here if you do need access to the 271 # socialaccount being deleted. 272 273 # Ensure you call the parent class's save. 274 # .save() does not return anything 275 super(MyCustomSocialDisconnectForm, self).save() 276 277 # Add your own processing here if you don't need access to the 278 # socialaccount being deleted. 279 280You have access to the following: 281 282- ``self.request`` is the request object 283- ``self.accounts`` is a list containing all of the user's SocialAccount objects. 284- ``self.cleaned_data['account']`` contains the socialaccount being deleted. ``.save()`` 285 issues the delete. So if you need access to the socialaccount beforehand, move your 286 code before ``.save()``. 287 288``settings.py``:: 289 290 SOCIALACCOUNT_FORMS = {'disconnect': 'mysite.forms.MyCustomSocialDisconnectForm'} 291