forked from ptahproject/devel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start3.py
70 lines (54 loc) · 2.03 KB
/
start3.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
""" This is an example of security and URI resolver in 1 module. """
import cgi
from paste.httpserver import serve
from zope import interface
from memphis import view
import ptah
import ptah_cms
# login name is a ptah.uri.Uri which means its prefixed with a scheme.
# this is login, bobdobbs whose prefix is user+example.
# the default Ptah implementation is ptah.crowd.provider, scheme `user+crowd`
USERS = {'user+example:bobdobbs':'aliens'}
SCHEME = 'user+example'
# Close your eyes.. checkers is hardwired?!
# Let's labotomize it.. oh wait, cant do it here ;-( must do it in __main__
#from ptah import authentication
#authentication.checkers = []
class User(object):
def __init__(self, login):
self.uri = '%s:%s' % (SCHEME, login)
self.password = USERS.get(self.uri)
self.login = login
self.name = login
@classmethod
def get(cls, login):
login = login.split(':',1)[-1]
if USERS.get('%s:%s' % (SCHEME, login)):
return User(login)
getByLogin = getById = get
class UserProvider(object):
interface.implements(ptah.IAuthProvider)
def authenticate(self, creds):
login, password = creds['login'], creds['password']
user = User.get(login)
if user is not None:
return user
def getPrincipalByLogin(self, login):
return User(login)
# registration
@ptah.resolver('user+example', 'An example principal resolver')
def getPrincipal(uri):
return User.get(uri)
ptah.registerProvider('example', UserProvider())
if __name__ == '__main__':
""" need to point to your settings.ini file in make_wsgi_app call.
http://localhost:8080/show_models is url dispatch function.
http://localhost:8080/list_children is traverser on context
$resource_url/show_info on either folder or content.
"""
#import ptah, will fix
import repoze.tm
app = ptah.make_wsgi_app({'settings':r'./ptah.ini'})
from ptah import authentication
authentication.checkers = []
serve(repoze.tm.TM(app), host='0.0.0.0')