]> TLD Linux GIT Repositories - tld-ftp-admin.git/blob - modules/user.py
- non-integer releases are ok in TLD
[tld-ftp-admin.git] / modules / user.py
1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3 from __future__ import print_function
4
5 import Cookie, time, ftpio
6
7 UserNotLoggedIn="UserNotLoggedIn"
8
9 class User:
10     def __init__(self, cookies, options):
11         self.loggedin=False
12         ftpio.connect('wwwiface')
13         if 'ftpsessid' in cookies and cookies['ftpsessid']:
14             self.login=ftpio.login_cookie(cookies['ftpsessid'])
15             if self.login:
16                 self.loggedin=True
17
18         if 'action' in options:
19             if options['action'] == 'register':
20                 self.checkloginpass(options)
21             elif options['action'] == 'logout':
22                 self.logout()
23
24     def checkloginpass(self, options):
25         if 'login' not in options or 'pass' not in options:
26             return
27         self.cookie=ftpio.login_passwd(options['login'], options['pass'])
28         if self.cookie:
29             self.login=options['login']
30             self.loggedin=True
31             C = Cookie.SimpleCookie()
32             C['ftpsessid']=self.cookie
33             #C['ftpsessid']['expires']=time.strftime(
34                                         #"%a, %d-%b-%y %H:%M:%S GMT",
35                                         #time.gmtime(time.time()+86400))
36             print(C)
37
38     def logout(self):
39         self.loggedin=False
40         ftpio.logout()
41         C = Cookie.SimpleCookie()
42         C['ftpsessid']=''
43         C['ftpsessid']['expires']=time.strftime("%a, %d-%b-%y %H:%M:%S GMT",
44                                     time.gmtime(time.time()-31536000))
45         print(C)
46