1
/****************************************************************************
3
| Copyright (c) 2007 Novell, Inc.
6
| This program is free software; you can redistribute it and/or
7
| modify it under the terms of version 2 of the GNU General Public License as
8
| published by the Free Software Foundation.
10
| This program is distributed in the hope that it will be useful,
11
| but WITHOUT ANY WARRANTY; without even the implied warranty of
12
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
| GNU General Public License for more details.
15
| You should have received a copy of the GNU General Public License
16
| along with this program; if not, contact Novell, Inc.
18
| To contact Novell about this file by physical or electronic mail,
19
| you may find current contact information at www.novell.com
21
| Author: Mike Lasky (mlasky@novell.com)
22
|***************************************************************************/
25
using System.Collections;
26
using System.ComponentModel;
29
using System.Resources;
31
using System.Web.SessionState;
33
using System.Web.UI.WebControls;
34
using System.Web.UI.HtmlControls;
36
namespace Novell.iFolderWeb.Admin
39
/// Summary description for CreateUser.
41
public class CreateUser : System.Web.UI.Page
46
/// iFolder Connection
48
private iFolderAdmin web;
53
private ResourceManager rm;
57
/// Top navigation panel control.
59
protected TopNavigation TopNav;
63
/// User name edit control.
65
protected TextBox UserName;
68
/// First name edit control.
70
protected TextBox FirstName;
73
/// Last name edit control.
75
protected TextBox LastName;
78
/// Full name edit control.
80
protected TextBox FullName;
83
/// Password edit control.
85
protected TextBox Password;
88
/// Retyped password edit control.
90
protected TextBox RetypedPassword;
94
/// Create user button control.
96
protected Button CreateButton;
99
/// Cancel button control.
101
protected Button CancelButton;
108
/// Gets or sets the referring page.
110
private string ReferringPage
112
get { return ViewState[ "ReferringPage" ] as String; }
113
set { ViewState[ "ReferringPage" ] = value; }
117
/// Enables the create button if all required fields are present.
119
private bool ValidPage
123
return ( ( UserName.Text.Length > 0 ) &&
124
( FirstName.Text.Length > 0 ) &&
125
( LastName.Text.Length > 0 ) &&
126
( FullName.Text.Length > 0 ) &&
127
( Password.Text.Length > 0 ) &&
128
( RetypedPassword.Text.Length > 0 ) );
134
#region Private Methods
137
/// Builds the breadcrumb list for this page.
139
private void BuildBreadCrumbList()
141
TopNav.AddBreadCrumb( GetString( "USERS" ), "Users.aspx" );
142
TopNav.AddBreadCrumb( GetString( "CREATEUSER" ), null );
148
/// <param name="sender"></param>
149
/// <param name="e"></param>
150
private void Page_Load(object sender, System.EventArgs e)
153
web = Session[ "Connection" ] as iFolderAdmin;
156
rm = Application[ "RM" ] as ResourceManager;
160
// Remember the page that we came from.
161
ReferringPage = Page.Request.UrlReferrer.ToString();
163
// Initialize the localized fields.
164
CreateButton.Text = GetString( "CREATE" );
165
CancelButton.Text = GetString( "CANCEL" );
167
// Initialize state variables.
168
SetFocus( UserName );
175
/// <param name="sender"></param>
176
/// <param name="e"></param>
177
private void Page_PreRender(object sender, EventArgs e)
179
// Set the breadcrumb list.
180
BuildBreadCrumbList();
184
/// Sets focus to the specified control.
186
/// <param name="ctrl"></param>
187
private void SetFocus( System.Web.UI.Control ctrl )
189
string s = "<SCRIPT language='javascript'>document.getElementById('" + ctrl.ClientID + "').focus() </SCRIPT>";
190
Page.RegisterStartupScript( "focus", s );
195
#region Protected Methods
198
/// Get a Localized String
200
/// <param name="key"></param>
201
/// <returns></returns>
202
protected string GetString( string key )
204
return rm.GetString( key );
208
/// Event handler that gets called when the cancel button is clicked.
210
/// <param name="source"></param>
211
/// <param name="e"></param>
212
protected void OnCancelButton_Click( object source, EventArgs e )
214
// Return back to the referring page.
215
string url = web.TrimUrl(ReferringPage);
216
Page.Response.Redirect( url, true );
220
/// Event handler that gets called when the create button is clicked.
222
/// <param name="source"></param>
223
/// <param name="e"></param>
224
protected void OnCreateButton_Click( object source, EventArgs e )
228
TopNav.ShowError( GetString( "ALLFIELDSREQUIRED" ) );
232
// Verify that the retyped password matches.
233
if ( Password.Text == RetypedPassword.Text )
240
Guid.NewGuid().ToString(),
247
// Return back to the referring page.
248
string url = web.TrimUrl(ReferringPage);
249
Page.Response.Redirect( url, true );
251
catch ( Exception ex )
253
TopNav.ShowError( GetString( "ERRORCANNOTCREATEUSER" ), ex );
258
TopNav.ShowError( GetString( "PASSWORDSDONOTMATCH" ) );
264
/// Event handler that gets called when the FirstName text box changes.
266
/// <param name="source"></param>
267
/// <param name="e"></param>
268
protected void OnFirstNameChanged( object source, EventArgs e )
274
/// Event handler that gets called when the LastName text box changes.
276
/// <param name="source"></param>
277
/// <param name="e"></param>
278
protected void OnLastNameChanged( object source, EventArgs e )
284
#region Web Form Designer generated code
289
/// <param name="e"></param>
290
override protected void OnInit(EventArgs e)
293
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
295
InitializeComponent();
300
/// Required method for Designer support - do not modify
301
/// the contents of this method with the code editor.
303
private void InitializeComponent()
305
if ( !Page.IsPostBack )
307
// Set the render event to happen only on page load.
308
Page.PreRender += new EventHandler( Page_PreRender );
311
this.Load += new System.EventHandler(this.Page_Load);