Revision bef3bf46 snf-astakos-app/astakos/im/backends.py
b/snf-astakos-app/astakos/im/backends.py | ||
---|---|---|
61 | 61 |
according to the INVITATIONS_ENABLED setting |
62 | 62 |
(if True returns ``astakos.im.backends.InvitationsBackend`` and if False |
63 | 63 |
returns ``astakos.im.backends.SimpleBackend``). |
64 |
|
|
64 |
|
|
65 | 65 |
If the backend cannot be located ``django.core.exceptions.ImproperlyConfigured`` |
66 | 66 |
is raised. |
67 | 67 |
""" |
... | ... | |
93 | 93 |
""" |
94 | 94 |
self.request = request |
95 | 95 |
self.invitation = get_invitation(request) |
96 |
|
|
96 |
|
|
97 | 97 |
def get_signup_form(self, provider): |
98 | 98 |
""" |
99 |
Returns the form class name
|
|
99 |
Returns the form class name |
|
100 | 100 |
""" |
101 | 101 |
invitation = self.invitation |
102 | 102 |
initial_data = self.get_signup_initial_data(provider) |
... | ... | |
104 | 104 |
main = provider.capitalize() if provider == 'local' else 'ThirdParty' |
105 | 105 |
suffix = 'UserCreationForm' |
106 | 106 |
formclass = '%s%s%s' % (prefix, main, suffix) |
107 |
return globals()[formclass](initial_data, ip=self.request.META['REMOTE_ADDR']) |
|
108 |
|
|
107 |
ip = self.request.META.get('REMOTE_ADDR', |
|
108 |
self.request.META.get('HTTP_X_REAL_IP', None)) |
|
109 |
return globals()[formclass](initial_data, ip=ip) |
|
110 |
|
|
109 | 111 |
def get_signup_initial_data(self, provider): |
110 | 112 |
""" |
111 | 113 |
Returns the necassary registration form depending the user is invited or not |
112 |
|
|
114 |
|
|
113 | 115 |
Throws Invitation.DoesNotExist in case ``code`` is not valid. |
114 | 116 |
""" |
115 | 117 |
request = self.request |
... | ... | |
128 | 130 |
if provider == request.POST.get('provider', ''): |
129 | 131 |
initial_data = request.POST |
130 | 132 |
return initial_data |
131 |
|
|
133 |
|
|
132 | 134 |
def _is_preaccepted(self, user): |
133 | 135 |
""" |
134 | 136 |
If there is a valid, not-consumed invitation code for the specific user |
... | ... | |
141 | 143 |
invitation.consume() |
142 | 144 |
return True |
143 | 145 |
return False |
144 |
|
|
146 |
|
|
145 | 147 |
@transaction.commit_manually |
146 | 148 |
def signup(self, form, admin_email_template_name='im/admin_notification.txt'): |
147 | 149 |
""" |
... | ... | |
149 | 151 |
(has a valid invitation code) the user is activated and if the request |
150 | 152 |
param ``next`` is present redirects to it. |
151 | 153 |
In any other case the method returns the action status and a message. |
152 |
|
|
154 |
|
|
153 | 155 |
The method uses commit_manually decorator in order to ensure the user |
154 | 156 |
will be created only if the procedure has been completed successfully. |
155 | 157 |
""" |
... | ... | |
170 | 172 |
except socket.error, e: |
171 | 173 |
status = messages.ERROR |
172 | 174 |
message = _(e.strerror) |
173 |
|
|
175 |
|
|
174 | 176 |
# rollback in case of error |
175 | 177 |
if status == messages.ERROR: |
176 | 178 |
transaction.rollback() |
... | ... | |
186 | 188 |
""" |
187 | 189 |
def __init__(self, request): |
188 | 190 |
self.request = request |
189 |
|
|
191 |
|
|
190 | 192 |
def get_signup_form(self, provider): |
191 | 193 |
""" |
192 | 194 |
Returns the form class name |
... | ... | |
199 | 201 |
if request.method == 'POST': |
200 | 202 |
if provider == request.POST.get('provider', ''): |
201 | 203 |
initial_data = request.POST |
202 |
return globals()[formclass](initial_data, ip=self.request.META['REMOTE_ADDR']) |
|
203 |
|
|
204 |
ip = self.request.META.get('REMOTE_ADDR', |
|
205 |
self.request.META.get('HTTP_X_REAL_IP', None)) |
|
206 |
return globals()[formclass](initial_data, ip=ip) |
|
207 |
|
|
204 | 208 |
@transaction.commit_manually |
205 | 209 |
def signup(self, form, email_template_name='im/activation_email.txt', admin_email_template_name='im/admin_notification.txt'): |
206 | 210 |
""" |
207 | 211 |
Creates an inactive user account and sends a verification email. |
208 |
|
|
212 |
|
|
209 | 213 |
The method uses commit_manually decorator in order to ensure the user |
210 | 214 |
will be created only if the procedure has been completed successfully. |
211 |
|
|
215 |
|
|
212 | 216 |
** Arguments ** |
213 |
|
|
217 |
|
|
214 | 218 |
``email_template_name`` |
215 | 219 |
A custom template for the verification email body to use. This is |
216 | 220 |
optional; if not specified, this will default to |
217 | 221 |
``im/activation_email.txt``. |
218 |
|
|
222 |
|
|
219 | 223 |
** Templates ** |
220 | 224 |
im/activation_email.txt or ``email_template_name`` keyword argument |
221 |
|
|
225 |
|
|
222 | 226 |
** Settings ** |
223 |
|
|
227 |
|
|
224 | 228 |
* DEFAULT_CONTACT_EMAIL: service support email |
225 | 229 |
* DEFAULT_FROM_EMAIL: from email |
226 | 230 |
""" |
... | ... | |
242 | 246 |
status = messages.ERROR |
243 | 247 |
name = 'strerror' |
244 | 248 |
message = getattr(e, name) if hasattr(e, name) else e |
245 |
|
|
249 |
|
|
246 | 250 |
# rollback in case of error |
247 | 251 |
if status == messages.ERROR: |
248 | 252 |
transaction.rollback() |
Also available in: Unified diff