root / snf-pithos-app / pithos / api / login.py @ b2d77f0e
History | View | Annotate | Download (2.2 kB)
1 | 2e662088 | Antony Chazapis | # Copyright 2011-2012 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | 0a8bf8fb | Antony Chazapis | #
|
3 | 0a8bf8fb | Antony Chazapis | # Redistribution and use in source and binary forms, with or
|
4 | 0a8bf8fb | Antony Chazapis | # without modification, are permitted provided that the following
|
5 | 0a8bf8fb | Antony Chazapis | # conditions are met:
|
6 | 0a8bf8fb | Antony Chazapis | #
|
7 | 0a8bf8fb | Antony Chazapis | # 1. Redistributions of source code must retain the above
|
8 | 0a8bf8fb | Antony Chazapis | # copyright notice, this list of conditions and the following
|
9 | 0a8bf8fb | Antony Chazapis | # disclaimer.
|
10 | 0a8bf8fb | Antony Chazapis | #
|
11 | 0a8bf8fb | Antony Chazapis | # 2. Redistributions in binary form must reproduce the above
|
12 | 0a8bf8fb | Antony Chazapis | # copyright notice, this list of conditions and the following
|
13 | 0a8bf8fb | Antony Chazapis | # disclaimer in the documentation and/or other materials
|
14 | 0a8bf8fb | Antony Chazapis | # provided with the distribution.
|
15 | 0a8bf8fb | Antony Chazapis | #
|
16 | 0a8bf8fb | Antony Chazapis | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | 0a8bf8fb | Antony Chazapis | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | 0a8bf8fb | Antony Chazapis | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | 0a8bf8fb | Antony Chazapis | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | 0a8bf8fb | Antony Chazapis | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | 0a8bf8fb | Antony Chazapis | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | 0a8bf8fb | Antony Chazapis | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | 0a8bf8fb | Antony Chazapis | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | 0a8bf8fb | Antony Chazapis | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | 0a8bf8fb | Antony Chazapis | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | 0a8bf8fb | Antony Chazapis | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | 0a8bf8fb | Antony Chazapis | # POSSIBILITY OF SUCH DAMAGE.
|
28 | 0a8bf8fb | Antony Chazapis | #
|
29 | 0a8bf8fb | Antony Chazapis | # The views and conclusions contained in the software and
|
30 | 0a8bf8fb | Antony Chazapis | # documentation are those of the authors and should not be
|
31 | 0a8bf8fb | Antony Chazapis | # interpreted as representing official policies, either expressed
|
32 | 0a8bf8fb | Antony Chazapis | # or implied, of GRNET S.A.
|
33 | 0a8bf8fb | Antony Chazapis | |
34 | 0a8bf8fb | Antony Chazapis | import logging |
35 | 0a8bf8fb | Antony Chazapis | |
36 | 0a8bf8fb | Antony Chazapis | from django.http import HttpResponseNotFound, HttpResponseRedirect |
37 | a903e505 | Antony Chazapis | from django.utils.http import urlencode |
38 | 0a8bf8fb | Antony Chazapis | from django.conf import settings |
39 | 0a8bf8fb | Antony Chazapis | |
40 | 0a8bf8fb | Antony Chazapis | |
41 | 0a8bf8fb | Antony Chazapis | logger = logging.getLogger(__name__) |
42 | 0a8bf8fb | Antony Chazapis | |
43 | 0a8bf8fb | Antony Chazapis | |
44 | 0a8bf8fb | Antony Chazapis | def redirect_to_login_service(request): |
45 | 0a8bf8fb | Antony Chazapis | users = settings.AUTHENTICATION_USERS |
46 | 0a8bf8fb | Antony Chazapis | host = settings.AUTHENTICATION_HOST |
47 | 0a8bf8fb | Antony Chazapis | if users is not None or host is None: |
48 | 4732ed31 | Antony Chazapis | return HttpResponseNotFound()
|
49 | 0a8bf8fb | Antony Chazapis | |
50 | 0a8bf8fb | Antony Chazapis | if request.is_secure():
|
51 | 4732ed31 | Antony Chazapis | proto = 'https://'
|
52 | 0a8bf8fb | Antony Chazapis | else:
|
53 | 4732ed31 | Antony Chazapis | proto = 'http://'
|
54 | 4732ed31 | Antony Chazapis | next = request.GET.get('next', '') |
55 | 4732ed31 | Antony Chazapis | params = {'next': next} |
56 | 4732ed31 | Antony Chazapis | renew = 'renew' in request.GET |
57 | 4732ed31 | Antony Chazapis | if renew:
|
58 | 4732ed31 | Antony Chazapis | params['renew'] = True |
59 | a903e505 | Antony Chazapis | uri = proto + host + '/login?' + urlencode(params)
|
60 | 4732ed31 | Antony Chazapis | return HttpResponseRedirect(uri) |