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

Source Code for Module ZenWidgets.browser.quickstart.userViews

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2009, Zenoss Inc. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify it 
 7  # under the terms of the GNU General Public License version 2 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
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 
20   
21 -class SetAdminPasswordException(Exception):
22 """There was a problem setting the admin password"""
23
24 -class CreateUserView(BrowserView):
25 """ 26 Creates the initial user and sets the admin password. 27 """ 28 __call__ = ZopeTwoPageTemplateFile('templates/createuser.pt') 29 30 @Ext.form_action
31 - def createUser(self):
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 # Set admin password 46 try: 47 admin = zenUsers.getUserSettings('admin') 48 admin.manage_editUserSettings(password=adminPassword, 49 sndpassword=adminPassword) 50 except: 51 response.error('admin-pass', 52 "There was a problem setting the admin password.") 53 54 if not zenUsers.checkValidId(userName) == True: 55 response.error('username', 'That username already exists.') 56 else: 57 ret = zenUsers.manage_addUser(userName, userPassword, 58 ('Manager',), REQUEST=None, email=emailAddress) 59 if ret is None: 60 response.error('username', 61 'We were unable to add a user at this time.' 62 ' Check your installation.') 63 64 if not response.has_errors(): 65 # Log out, so the form can log us in as the new user 66 acl_users = self.context.getPhysicalRoot().acl_users 67 self.context.acl_users.resetCredentials( 68 self.request, self.request.response) 69 70 # Don't run the quickstart next time 71 self.context.dmd._rq = True 72 73 # Send us on our way 74 response.redirect('qs-step2') 75 return response
76