1
2
3
4
5
6
7
8
9
10
11
12
13
14 import transaction
15 from Products.Five.browser import BrowserView
16 from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile
17 from Products.ZenWidgets import messaging
18 from Products.ZenUtils import Ext
19 from Products.CMFCore.utils import getToolByName
22 """There was a problem setting the admin password"""
23
25 """
26 Creates the initial user and sets the admin password.
27 """
28 __call__ = ZopeTwoPageTemplateFile('templates/createuser.pt')
29
30 @Ext.form_action
32 """
33 Handles form submission for setting the admin password and creating
34 an initial user.
35 """
36 response = Ext.FormResponse()
37
38 adminPassword = self.request.form.get("admin-password1")
39 userName = self.request.form.get("username")
40 userPassword = self.request.form.get("password1")
41 emailAddress = self.request.form.get("emailAddress")
42
43 zenUsers = getToolByName(self.context, 'ZenUsers')
44
45
46 try:
47 admin = zenUsers.getUserSettings('admin')
48 admin.manage_editUserSettings(password=adminPassword,
49 sndpassword=adminPassword,
50 oldpassword='zenoss')
51 except:
52 response.error('admin-pass',
53 "There was a problem setting the admin password.")
54
55 if not zenUsers.checkValidId(userName) == True:
56 response.error('username', 'That username already exists.')
57 else:
58 ret = zenUsers.manage_addUser(userName, userPassword,
59 ('Manager',), REQUEST=None, email=emailAddress)
60 if ret is None:
61 response.error('username',
62 'We were unable to add a user at this time.'
63 ' Check your installation.')
64
65 if not response.has_errors():
66
67 acl_users = self.context.getPhysicalRoot().acl_users
68 self.context.acl_users.resetCredentials(
69 self.request, self.request.response)
70
71
72 self.context.dmd._rq = True
73
74
75 response.redirect('qs-step2')
76 return response
77