Mercurial > hg > bitsyblog
comparison bitsyblog/user.py @ 102:bc08a00a7d93
make user creation work again, wip
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 23 Feb 2014 16:50:06 -0800 |
parents | dd4abe56edf7 |
children | 67e01fc5e360 |
comparison
equal
deleted
inserted
replaced
101:83ec14fca36c | 102:bc08a00a7d93 |
---|---|
1 """ | 1 """ |
2 module for bitsyblog users | 2 bitsyblog users |
3 """ | 3 """ |
4 | 4 |
5 import os | 5 import os |
6 import random | 6 import random |
7 import settings | 7 import settings |
21 def __getitem__(self, key): | 21 def __getitem__(self, key): |
22 return self.settings[key] | 22 return self.settings[key] |
23 | 23 |
24 def get(self, key, default=None): | 24 def get(self, key, default=None): |
25 return self.settings.get(key, default) | 25 return self.settings.get(key, default) |
26 | |
26 | 27 |
27 class BitsyUsers(object): | 28 class BitsyUsers(object): |
28 """abstract class for bitsyblog user management""" | 29 """abstract class for bitsyblog user management""" |
29 | 30 |
30 def __iter__(self): return self.users() | 31 def __iter__(self): return self.users() |
46 for user in self.users(): | 47 for user in self.users(): |
47 passwords[user] = self.password(user) | 48 passwords[user] = self.password(user) |
48 return passwords | 49 return passwords |
49 | 50 |
50 ### interface methods to be specified by the child class | 51 ### interface methods to be specified by the child class |
52 | |
51 def new(self, name, password): | 53 def new(self, name, password): |
52 """create a new user""" | 54 """create a new user""" |
53 | 55 |
54 def users(self): | 56 def users(self): |
55 """returns the ids of all users (generator)""" | 57 """returns the ids of all users (generator)""" |
103 retval = [ dict(filename=i, name=i.rsplit('.css',1)[0], | 105 retval = [ dict(filename=i, name=i.rsplit('.css',1)[0], |
104 css=file(os.path.join(css_dir, i)).read()) | 106 css=file(os.path.join(css_dir, i)).read()) |
105 for i in css_files ] | 107 for i in css_files ] |
106 return retval | 108 return retval |
107 | 109 |
110 | |
108 ### interfaces for BitsyUsers | 111 ### interfaces for BitsyUsers |
109 | 112 |
110 def new(self, name, password): | 113 def new(self, name, password): |
111 """create a new user account""" | 114 """create a new user account""" |
115 | |
112 # XXX this shouldn't use HTTP exceptions | 116 # XXX this shouldn't use HTTP exceptions |
117 # instead, the web handler should listen for exceptions | |
118 # and it should raise HTTP exceptions | |
113 | 119 |
114 if name in self.users(): | 120 if name in self.users(): |
115 raise exc.HTTPForbidden("The name %s is already taken" % name).exception | 121 raise exc.HTTPForbidden("The name %s is already taken" % name).exception |
116 | 122 |
117 # characters forbidden in user name | 123 # characters forbidden in user name |
120 if [ i for i in forbidden if i in name ]: | 126 if [ i for i in forbidden if i in name ]: |
121 raise exc.HTTPForbidden("The name '%s' contains forbidden characters [%s]" % (user, forbidden)).exception | 127 raise exc.HTTPForbidden("The name '%s' contains forbidden characters [%s]" % (user, forbidden)).exception |
122 if name in urls: | 128 if name in urls: |
123 raise exc.HTTPForbidden("The name '%s' is already used for a url" % user).exception | 129 raise exc.HTTPForbidden("The name '%s' is already used for a url" % user).exception |
124 | 130 |
131 # create user directory | |
125 home = self.home(name) | 132 home = self.home(name) |
126 os.mkdir(home) | 133 os.mkdir(home) |
127 pw_file = file(self.pw_file(name), 'w') | 134 pw_file = file(self.pw_file(name), 'w') |
128 print >> pw_file, password | 135 print >> pw_file, password |
129 | 136 |