Package Products :: Package ZenWidgets :: Package browser :: Package quickstart :: Module userViews
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenWidgets.browser.quickstart.userViews

 1  ############################################################################## 
 2  #  
 3  # Copyright (C) Zenoss, Inc. 2009, all rights reserved. 
 4  #  
 5  # This content is made available according to terms specified in 
 6  # License.zenoss under the directory where your Zenoss product is installed. 
 7  #  
 8  ############################################################################## 
 9   
10   
11  import logging 
12  log = logging.getLogger("zen.widgets.userviews") 
13   
14  from Products.Five.browser import BrowserView 
15  from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile 
16  from Products.ZenUtils import Ext 
17  from Products.CMFCore.utils import getToolByName 
18 19 -class SetAdminPasswordException(Exception):
20 """There was a problem setting the admin password"""
21
22 -class CreateUserView(BrowserView):
23 """ 24 Creates the initial user and sets the admin password. 25 """ 26 __call__ = ZopeTwoPageTemplateFile('templates/createuser.pt') 27 28 @Ext.form_action
29 - def createUser(self):
30 """ 31 Handles form submission for setting the admin password and creating 32 an initial user. 33 """ 34 response = Ext.FormResponse() 35 36 adminPassword = self.request.form.get("admin-password1") 37 userName = self.request.form.get("username") 38 userPassword = self.request.form.get("password1") 39 emailAddress = self.request.form.get("emailAddress") 40 41 zenUsers = getToolByName(self.context, 'ZenUsers') 42 43 # Set admin password 44 try: 45 admin = zenUsers.getUserSettings('admin') 46 admin.manage_editUserSettings(password=adminPassword, 47 sndpassword=adminPassword, 48 roles=('ZenManager', 'Manager'), 49 oldpassword='zenoss') 50 except Exception: 51 log.exception("Failed to set admin password") 52 response.error('admin-password1', 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 # Log out, so the form can log us in as the new user 67 acl_users = self.context.getPhysicalRoot().acl_users 68 self.context.acl_users.resetCredentials( 69 self.request, self.request.response) 70 71 # Don't run the quickstart next time 72 self.context.dmd._rq = True 73 74 # Send us on our way 75 response.redirect('qs-step2') 76 return response
77