Revision 176023aa snf-astakos-app/astakos/im/views.py
b/snf-astakos-app/astakos/im/views.py | ||
---|---|---|
1 | 1 |
# Copyright 2011-2012 GRNET S.A. All rights reserved. |
2 |
#
|
|
2 |
# |
|
3 | 3 |
# Redistribution and use in source and binary forms, with or |
4 | 4 |
# without modification, are permitted provided that the following |
5 | 5 |
# conditions are met: |
6 |
#
|
|
6 |
# |
|
7 | 7 |
# 1. Redistributions of source code must retain the above |
8 | 8 |
# copyright notice, this list of conditions and the following |
9 | 9 |
# disclaimer. |
10 |
#
|
|
10 |
# |
|
11 | 11 |
# 2. Redistributions in binary form must reproduce the above |
12 | 12 |
# copyright notice, this list of conditions and the following |
13 | 13 |
# disclaimer in the documentation and/or other materials |
14 | 14 |
# provided with the distribution. |
15 |
#
|
|
15 |
# |
|
16 | 16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS |
17 | 17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | 18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
... | ... | |
25 | 25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
26 | 26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
27 | 27 |
# POSSIBILITY OF SUCH DAMAGE. |
28 |
#
|
|
28 |
# |
|
29 | 29 |
# The views and conclusions contained in the software and |
30 | 30 |
# documentation are those of the authors and should not be |
31 | 31 |
# interpreted as representing official policies, either expressed |
... | ... | |
112 | 112 |
def index(request, login_template_name='im/login.html', profile_template_name='im/profile.html', extra_context={}): |
113 | 113 |
""" |
114 | 114 |
If there is logged on user renders the profile page otherwise renders login page. |
115 |
|
|
115 |
|
|
116 | 116 |
**Arguments** |
117 |
|
|
117 |
|
|
118 | 118 |
``login_template_name`` |
119 | 119 |
A custom login template to use. This is optional; if not specified, |
120 | 120 |
this will default to ``im/login.html``. |
121 |
|
|
121 |
|
|
122 | 122 |
``profile_template_name`` |
123 | 123 |
A custom profile template to use. This is optional; if not specified, |
124 | 124 |
this will default to ``im/profile.html``. |
125 |
|
|
125 |
|
|
126 | 126 |
``extra_context`` |
127 | 127 |
An dictionary of variables to add to the template context. |
128 |
|
|
128 |
|
|
129 | 129 |
**Template:** |
130 |
|
|
130 |
|
|
131 | 131 |
im/profile.html or im/login.html or ``template_name`` keyword argument. |
132 |
|
|
132 |
|
|
133 | 133 |
""" |
134 | 134 |
template_name = login_template_name |
135 | 135 |
formclass = 'LoginForm' |
... | ... | |
146 | 146 |
def invite(request, template_name='im/invitations.html', extra_context={}): |
147 | 147 |
""" |
148 | 148 |
Allows a user to invite somebody else. |
149 |
|
|
149 |
|
|
150 | 150 |
In case of GET request renders a form for providing the invitee information. |
151 | 151 |
In case of POST checks whether the user has not run out of invitations and then |
152 | 152 |
sends an invitation email to singup to the service. |
153 |
|
|
153 |
|
|
154 | 154 |
The view uses commit_manually decorator in order to ensure the number of the |
155 | 155 |
user invitations is going to be updated only if the email has been successfully sent. |
156 |
|
|
156 |
|
|
157 | 157 |
If the user isn't logged in, redirects to settings.LOGIN_URL. |
158 |
|
|
158 |
|
|
159 | 159 |
**Arguments** |
160 |
|
|
160 |
|
|
161 | 161 |
``template_name`` |
162 | 162 |
A custom template to use. This is optional; if not specified, |
163 | 163 |
this will default to ``im/invitations.html``. |
164 |
|
|
164 |
|
|
165 | 165 |
``extra_context`` |
166 | 166 |
An dictionary of variables to add to the template context. |
167 |
|
|
167 |
|
|
168 | 168 |
**Template:** |
169 |
|
|
169 |
|
|
170 | 170 |
im/invitations.html or ``template_name`` keyword argument. |
171 |
|
|
171 |
|
|
172 | 172 |
**Settings:** |
173 |
|
|
173 |
|
|
174 | 174 |
The view expectes the following settings are defined: |
175 |
|
|
175 |
|
|
176 | 176 |
* LOGIN_URL: login uri |
177 | 177 |
* ASTAKOS_DEFAULT_CONTACT_EMAIL: service support email |
178 | 178 |
* ASTAKOS_DEFAULT_FROM_EMAIL: from email |
... | ... | |
180 | 180 |
status = None |
181 | 181 |
message = None |
182 | 182 |
inviter = AstakosUser.objects.get(username = request.user.username) |
183 |
|
|
183 |
|
|
184 | 184 |
if request.method == 'POST': |
185 | 185 |
username = request.POST.get('uniq') |
186 | 186 |
realname = request.POST.get('realname') |
187 |
|
|
187 |
|
|
188 | 188 |
if inviter.invitations > 0: |
189 | 189 |
try: |
190 | 190 |
invite_func(inviter, username, realname) |
... | ... | |
203 | 203 |
status = messages.ERROR |
204 | 204 |
message = _('No invitations left') |
205 | 205 |
messages.add_message(request, status, message) |
206 |
|
|
206 |
|
|
207 | 207 |
sent = [{'email': inv.username, |
208 | 208 |
'realname': inv.realname, |
209 | 209 |
'is_consumed': inv.is_consumed} |
... | ... | |
219 | 219 |
def edit_profile(request, template_name='im/profile.html', extra_context={}): |
220 | 220 |
""" |
221 | 221 |
Allows a user to edit his/her profile. |
222 |
|
|
222 |
|
|
223 | 223 |
In case of GET request renders a form for displaying the user information. |
224 | 224 |
In case of POST updates the user informantion and redirects to ``next`` |
225 | 225 |
url parameter if exists. |
226 |
|
|
226 |
|
|
227 | 227 |
If the user isn't logged in, redirects to settings.LOGIN_URL. |
228 |
|
|
228 |
|
|
229 | 229 |
**Arguments** |
230 |
|
|
230 |
|
|
231 | 231 |
``template_name`` |
232 | 232 |
A custom template to use. This is optional; if not specified, |
233 | 233 |
this will default to ``im/profile.html``. |
234 |
|
|
234 |
|
|
235 | 235 |
``extra_context`` |
236 | 236 |
An dictionary of variables to add to the template context. |
237 |
|
|
237 |
|
|
238 | 238 |
**Template:** |
239 |
|
|
239 |
|
|
240 | 240 |
im/profile.html or ``template_name`` keyword argument. |
241 |
|
|
241 |
|
|
242 | 242 |
**Settings:** |
243 |
|
|
243 |
|
|
244 | 244 |
The view expectes the following settings are defined: |
245 |
|
|
245 |
|
|
246 | 246 |
* LOGIN_URL: login uri |
247 | 247 |
""" |
248 | 248 |
form = ProfileForm(instance=request.user) |
... | ... | |
272 | 272 |
def signup(request, on_failure='im/signup.html', on_success='im/signup_complete.html', extra_context={}, backend=None): |
273 | 273 |
""" |
274 | 274 |
Allows a user to create a local account. |
275 |
|
|
275 |
|
|
276 | 276 |
In case of GET request renders a form for providing the user information. |
277 | 277 |
In case of POST handles the signup. |
278 |
|
|
278 |
|
|
279 | 279 |
The user activation will be delegated to the backend specified by the ``backend`` keyword argument |
280 | 280 |
if present, otherwise to the ``astakos.im.backends.InvitationBackend`` |
281 | 281 |
if settings.ASTAKOS_INVITATIONS_ENABLED is True or ``astakos.im.backends.SimpleBackend`` if not |
282 | 282 |
(see backends); |
283 |
|
|
283 |
|
|
284 | 284 |
Upon successful user creation if ``next`` url parameter is present the user is redirected there |
285 | 285 |
otherwise renders the same page with a success message. |
286 |
|
|
286 |
|
|
287 | 287 |
On unsuccessful creation, renders ``on_failure`` with an error message. |
288 |
|
|
288 |
|
|
289 | 289 |
**Arguments** |
290 |
|
|
290 |
|
|
291 | 291 |
``on_failure`` |
292 | 292 |
A custom template to render in case of failure. This is optional; |
293 | 293 |
if not specified, this will default to ``im/signup.html``. |
294 |
|
|
295 |
|
|
294 |
|
|
295 |
|
|
296 | 296 |
``on_success`` |
297 | 297 |
A custom template to render in case of success. This is optional; |
298 | 298 |
if not specified, this will default to ``im/signup_complete.html``. |
299 |
|
|
299 |
|
|
300 | 300 |
``extra_context`` |
301 | 301 |
An dictionary of variables to add to the template context. |
302 |
|
|
302 |
|
|
303 | 303 |
**Template:** |
304 |
|
|
304 |
|
|
305 | 305 |
im/signup.html or ``on_failure`` keyword argument. |
306 |
im/signup_complete.html or ``on_success`` keyword argument.
|
|
306 |
im/signup_complete.html or ``on_success`` keyword argument. |
|
307 | 307 |
""" |
308 | 308 |
if request.user.is_authenticated(): |
309 | 309 |
return HttpResponseRedirect(reverse('astakos.im.views.index')) |
... | ... | |
344 | 344 |
def send_feedback(request, template_name='im/feedback.html', email_template_name='im/feedback_mail.txt', extra_context={}): |
345 | 345 |
""" |
346 | 346 |
Allows a user to send feedback. |
347 |
|
|
347 |
|
|
348 | 348 |
In case of GET request renders a form for providing the feedback information. |
349 | 349 |
In case of POST sends an email to support team. |
350 |
|
|
350 |
|
|
351 | 351 |
If the user isn't logged in, redirects to settings.LOGIN_URL. |
352 |
|
|
352 |
|
|
353 | 353 |
**Arguments** |
354 |
|
|
354 |
|
|
355 | 355 |
``template_name`` |
356 | 356 |
A custom template to use. This is optional; if not specified, |
357 | 357 |
this will default to ``im/feedback.html``. |
358 |
|
|
358 |
|
|
359 | 359 |
``extra_context`` |
360 | 360 |
An dictionary of variables to add to the template context. |
361 |
|
|
361 |
|
|
362 | 362 |
**Template:** |
363 |
|
|
363 |
|
|
364 | 364 |
im/signup.html or ``template_name`` keyword argument. |
365 |
|
|
365 |
|
|
366 | 366 |
**Settings:** |
367 |
|
|
367 |
|
|
368 | 368 |
* LOGIN_URL: login uri |
369 | 369 |
* ASTAKOS_DEFAULT_CONTACT_EMAIL: List of feedback recipients |
370 | 370 |
""" |
... | ... | |
373 | 373 |
if request.method == 'POST': |
374 | 374 |
if not request.user: |
375 | 375 |
return HttpResponse('Unauthorized', status=401) |
376 |
|
|
376 |
|
|
377 | 377 |
form = FeedbackForm(request.POST) |
378 | 378 |
if form.is_valid(): |
379 | 379 |
subject = _("Feedback from %s alpha2 testing" % SITENAME) |
... | ... | |
383 | 383 |
'message': form.cleaned_data['feedback_msg'], |
384 | 384 |
'data': form.cleaned_data['feedback_data'], |
385 | 385 |
'request': request}) |
386 |
|
|
386 |
|
|
387 | 387 |
try: |
388 | 388 |
send_mail(subject, content, from_email, recipient_list) |
389 | 389 |
message = _('Feedback successfully sent') |
... | ... | |
422 | 422 |
""" |
423 | 423 |
Activates the user identified by the ``auth`` request parameter, sends a welcome email |
424 | 424 |
and renews the user token. |
425 |
|
|
425 |
|
|
426 | 426 |
The view uses commit_manually decorator in order to ensure the user state will be updated |
427 | 427 |
only if the email will be send successfully. |
428 | 428 |
""" |
... | ... | |
432 | 432 |
user = AstakosUser.objects.get(auth_token=token) |
433 | 433 |
except AstakosUser.DoesNotExist: |
434 | 434 |
return HttpResponseBadRequest(_('No such user')) |
435 |
|
|
435 |
|
|
436 | 436 |
user.is_active = True |
437 | 437 |
user.email_verified = True |
438 | 438 |
user.save() |
... | ... | |
460 | 460 |
term = ApprovalTerms.objects.get(id=term_id) |
461 | 461 |
except ApprovalTermDoesNotExist, e: |
462 | 462 |
pass |
463 |
|
|
463 |
|
|
464 | 464 |
if not term: |
465 |
return HttpResponseBadRequest(_('No approval terms found.'))
|
|
465 |
return HttpResponseRedirect(reverse('astakos.im.views.index'))
|
|
466 | 466 |
f = open(term.location, 'r') |
467 | 467 |
terms = f.read() |
468 |
|
|
468 |
|
|
469 | 469 |
if request.method == 'POST': |
470 | 470 |
next = request.POST.get('next') |
471 | 471 |
if not next: |
... | ... | |
489 | 489 |
|
490 | 490 |
@signed_terms_required |
491 | 491 |
def change_password(request): |
492 |
return password_change(request, post_change_redirect=reverse('astakos.im.views.edit_profile')) |
|
492 |
return password_change(request, post_change_redirect=reverse('astakos.im.views.edit_profile')) |
Also available in: Unified diff