user-session
changeset 132:dfa1951b5d35 trunk tip
added (working) add_user method
| author | Thomas Jollans <thomas@jollans.com> |
|---|---|
| date | Sat Sep 22 02:02:41 2007 +0200 (2007-09-22) |
| parents | 9d628e766428 |
| children | |
| files | modules/user.py |
line diff
1.1 --- a/modules/user.py Tue Aug 07 02:35:46 2007 +0200 1.2 +++ b/modules/user.py Sat Sep 22 02:02:41 2007 +0200 1.3 @@ -1,6 +1,6 @@ 1.4 # -*- coding: UTF-8 -*- 1.5 1.6 -# Copyright (C) 2006-2007 Thomas Jollans 1.7 +# Copyright (C) 2006 Thomas Jollans 1.8 # 1.9 # This program is free software; you can redistribute it and/or modify 1.10 # it under the terms of the GNU General Public License as published by 1.11 @@ -40,13 +40,7 @@ 1.12 err = req.xlate('u_reg_name_taken') 1.13 else: 1.14 #TODO: proper value checking; CAPTCHA? 1.15 - # fine, now generate the UID 1.16 - id = 1 1.17 - for i in req['user'].users.keys(): 1.18 - if id == i: 1.19 - id += 1 1.20 - req['user'].users[id] = {'name':flds['uname'], 1.21 - 'pass': req['user']._hash_pw()} 1.22 + req['user'].add_user(flds['uname'], flds['pw1']) 1.23 t = req.mk_template('success.atpl') 1.24 t.kw_set_vars( message=req.xlate('u_reg_created') % flds['uname'], 1.25 submessage=req.xlate('_redirect') ) 1.26 @@ -113,6 +107,20 @@ 1.27 raise TypeError("group names must be strings.") 1.28 if name not in self.groups: self.groups.append(name) 1.29 1.30 + def add_user(self, name, passwd=None): 1.31 + if name in (u['name'] for u in self.users.itervalues()): 1.32 + raise AfocValueError("User exists.") 1.33 + id = 1 1.34 + for i in self.users: 1.35 + if id == i: 1.36 + id += 1 1.37 + self.users[id] = {'name': name} 1.38 + if passwd is None: 1.39 + self.users[id]['pass'] = '!' # login impossible. 1.40 + else: 1.41 + self._hash_pw(id, passwd, True) 1.42 + 1.43 + 1.44 def delete_group(self,name): 1.45 """delete an existing group. CANNOT BE UNDONE !""" 1.46 if name in self.groups and name not in ('_admin','_users'):
