-
Notifications
You must be signed in to change notification settings - Fork 3
/
tauthhandler.py
37 lines (25 loc) · 1008 Bytes
/
tauthhandler.py
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
#!/usr/bin/env python
'''Module contains TAuthHandler class for handling own torrent add server
authentification.
'''
import tanyhandler
import auth
class TAuthHandler(tanyhandler.IHandler):
'''Class for handling inner authentification in download server.
It should be in page_template.auth_path in handlers dictionary.
'''
def process(self, body=None, browser=None):
'''Checks if user entered correct password and answers.
body parameter is used to get 'uname' and 'password'.
If data is correct, user gets cookie, HTTP 401 otherwise.
'''
if not auth.check_user(body['uname'], body['passwd']):
status = 401
return status, None, None
(cookie, expires) = auth.make_cookie(body['uname'])
status = 301
headers = {
'Set-Cookie': 'ID=%s ; expires=%s' % (cookie, expires.strftime('%a, %d %b %Y %H:%M:%S GMT')),
'Location': '/'
}
return status, headers, None