Listing 2: The New User Folder Class ExtendedUser
1. class ExtendedUserFolder(User.UserFolder):
2. """ user folder for managing ExtendedUsers """
3. meta_type='Extended User Folder'
4. ## these variables need to be in the new class so they are used in the
5. ## correct context and won't be taken from the base class and consequently
6. ## from the wrong directory
7. _mainUser=DTMLFile('dtml/mainUser', globals())
8. _add_User=DTMLFile('dtml/addUser', globals())
9. _editUser=DTMLFile('dtml/editUser', globals())
10. def _addUser(self,name,password,confirm,roles,domains,REQUEST=None):
11. if not name:
12. return MessageDialog(
13. title ='Illegal value',
14. message='A username must be specified',
15. action ='manage_main')
16. if not password or not confirm:
17. if not domains:
18. return MessageDialog(
19. title ='Illegal value',
20. message='Password and confirmation must be specified',
21. action ='manage_main')
22. if self.getUser(name) or (self._emergency_user and
23. name == self._emergency_user.getUserName()):
24. return MessageDialog(
25. title ='Illegal value',
26. message='A user with the specified name already exists',
27. action ='manage_main')
28. if (password or confirm) and (password != confirm):
29. return MessageDialog(
30. title ='Illegal value',
31. message='Password and confirmation do not match',
32. action ='manage_main')
33. if not roles: roles=[]
34. if not domains: domains=[]
35. if domains and not self.domainSpecValidate(domains):
36. return MessageDialog(
37. title ='Illegal value',
38. message='Illegal domain specification',
39. action ='manage_main')
40. self._doAddUser(name, password, roles, domains, email=REQUEST['email'])
41. if REQUEST: return self._mainUser(self, REQUEST)
42. def _changeUser(self,name,password,confirm,roles,domains,REQUEST=None):
43. if password == 'password' and confirm == 'pconfirm':
44. # Protocol for editUser.dtml to indicate unchanged password
45. password = confirm = None
46. if not name:
47. return MessageDialog(
48. title ='Illegal value',
49. message='A username must be specified',
50. action ='manage_main')
51. if password == confirm == '':
52. if not domains:
53. return MessageDialog(
54. title ='Illegal value',
55. message='Password and confirmation must be specified',
56. action ='manage_main')
57. if not self.getUser(name):
58. return MessageDialog(
59. title ='Illegal value',
60. message='Unknown user',
61. action ='manage_main')
62. if (password or confirm) and (password != confirm):
63. return MessageDialog(
64. title ='Illegal value',
65. message='Password and confirmation do not match',
66. action ='manage_main')
67. if not roles: roles=[]
68. if not domains: domains=[]
69. if domains and not self.domainSpecValidate(domains):
70. return MessageDialog(
71. title ='Illegal value',
72. message='Illegal domain specification',
73. action ='manage_main')
74. self._doChangeUser(name, password, roles, domains, email=REQUEST['email'])
75. if REQUEST: return self._mainUser(self, REQUEST)
76. def _doAddUser(self, name, password, roles, domains, **kw):
77. """Create a new user"""
78. email=kw['email']
79. if password is not None and self.encrypt_passwords:
80. password = self._encryptPassword(password)
81. self.data[name]=ExtendedUser(name,password,roles,domains,email)
82. def _doChangeUser(self, name, password, roles, domains, **kw):
83. user=self.data[name]
84. email=kw['email']
85. if password is not None:
86. if self.encrypt_passwords:
87. password = self._encryptPassword(password)
88. user.__=password
89. user.roles=roles
90. user.domains=domains
91. user.email=email
92. self.data[name]=user
|