~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/admin/.svn/text-base/CreateUser.aspx.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 |
3
 
 | Copyright (c) 2007 Novell, Inc.
4
 
 | All Rights Reserved.
5
 
 |
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.
9
 
 |
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.
14
 
 |
15
 
 | You should have received a copy of the GNU General Public License
16
 
 | along with this program; if not, contact Novell, Inc.
17
 
 |
18
 
 | To contact Novell about this file by physical or electronic mail,
19
 
 | you may find current contact information at www.novell.com
20
 
 |
21
 
 | Author: Mike Lasky (mlasky@novell.com)
22
 
 |***************************************************************************/
23
 
 
24
 
using System;
25
 
using System.Collections;
26
 
using System.ComponentModel;
27
 
using System.Data;
28
 
using System.Drawing;
29
 
using System.Resources;
30
 
using System.Web;
31
 
using System.Web.SessionState;
32
 
using System.Web.UI;
33
 
using System.Web.UI.WebControls;
34
 
using System.Web.UI.HtmlControls;
35
 
 
36
 
namespace Novell.iFolderWeb.Admin
37
 
{
38
 
        /// <summary>
39
 
        /// Summary description for CreateUser.
40
 
        /// </summary>
41
 
        public class CreateUser : System.Web.UI.Page
42
 
        {
43
 
                #region Class Members
44
 
 
45
 
                /// <summary>
46
 
                /// iFolder Connection
47
 
                /// </summary>
48
 
                private iFolderAdmin web;
49
 
 
50
 
                /// <summary>
51
 
                /// Resource Manager
52
 
                /// </summary>
53
 
                private ResourceManager rm;
54
 
 
55
 
 
56
 
                /// <summary>
57
 
                /// Top navigation panel control.
58
 
                /// </summary>
59
 
                protected TopNavigation TopNav;
60
 
 
61
 
 
62
 
                /// <summary>
63
 
                /// User name edit control.
64
 
                /// </summary>
65
 
                protected TextBox UserName;
66
 
 
67
 
                /// <summary>
68
 
                /// First name edit control.
69
 
                /// </summary>
70
 
                protected TextBox FirstName;
71
 
 
72
 
                /// <summary>
73
 
                /// Last name edit control.
74
 
                /// </summary>
75
 
                protected TextBox LastName;
76
 
 
77
 
                /// <summary>
78
 
                /// Full name edit control.
79
 
                /// </summary>
80
 
                protected TextBox FullName;
81
 
 
82
 
                /// <summary>
83
 
                /// Password edit control.
84
 
                /// </summary>
85
 
                protected TextBox Password;
86
 
 
87
 
                /// <summary>
88
 
                /// Retyped password edit control.
89
 
                /// </summary>
90
 
                protected TextBox RetypedPassword;
91
 
 
92
 
 
93
 
                /// <summary>
94
 
                /// Create user button control.
95
 
                /// </summary>
96
 
                protected Button CreateButton;
97
 
 
98
 
                /// <summary>
99
 
                /// Cancel button control.
100
 
                /// </summary>
101
 
                protected Button CancelButton;
102
 
 
103
 
                #endregion
104
 
 
105
 
                #region Properties
106
 
 
107
 
                /// <summary>
108
 
                /// Gets or sets the referring page.
109
 
                /// </summary>
110
 
                private string ReferringPage
111
 
                {
112
 
                        get { return ViewState[ "ReferringPage" ] as String; }
113
 
                        set { ViewState[ "ReferringPage" ] = value; }
114
 
                }
115
 
 
116
 
                /// <summary>
117
 
                /// Enables the create button if all required fields are present.
118
 
                /// </summary>
119
 
                private bool ValidPage
120
 
                {
121
 
                        get
122
 
                        {
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 ) );
129
 
                        }
130
 
                }
131
 
 
132
 
                #endregion
133
 
 
134
 
                #region Private Methods
135
 
 
136
 
                /// <summary>
137
 
                ///  Builds the breadcrumb list for this page.
138
 
                /// </summary>
139
 
                private void BuildBreadCrumbList()
140
 
                {
141
 
                        TopNav.AddBreadCrumb( GetString( "USERS" ), "Users.aspx" );
142
 
                        TopNav.AddBreadCrumb( GetString( "CREATEUSER" ), null );
143
 
                }
144
 
 
145
 
                /// <summary>
146
 
                /// Page_Load
147
 
                /// </summary>
148
 
                /// <param name="sender"></param>
149
 
                /// <param name="e"></param>
150
 
                private void Page_Load(object sender, System.EventArgs e)
151
 
                {
152
 
                        // connection
153
 
                        web = Session[ "Connection" ] as iFolderAdmin;
154
 
 
155
 
                        // localization
156
 
                        rm = Application[ "RM" ] as ResourceManager;
157
 
 
158
 
                        if ( !IsPostBack )
159
 
                        {
160
 
                                // Remember the page that we came from.
161
 
                                ReferringPage = Page.Request.UrlReferrer.ToString();
162
 
 
163
 
                                // Initialize the localized fields.
164
 
                                CreateButton.Text = GetString( "CREATE" );
165
 
                                CancelButton.Text = GetString( "CANCEL" );
166
 
 
167
 
                                // Initialize state variables.
168
 
                                SetFocus( UserName );
169
 
                        }
170
 
                }
171
 
 
172
 
                /// <summary>
173
 
                /// Page_PreRender
174
 
                /// </summary>
175
 
                /// <param name="sender"></param>
176
 
                /// <param name="e"></param>
177
 
                private void Page_PreRender(object sender, EventArgs e)
178
 
                {
179
 
                        // Set the breadcrumb list.
180
 
                        BuildBreadCrumbList();
181
 
                }
182
 
 
183
 
                /// <summary>
184
 
                /// Sets focus to the specified control.
185
 
                /// </summary>
186
 
                /// <param name="ctrl"></param>
187
 
                private void SetFocus( System.Web.UI.Control ctrl )
188
 
                {
189
 
                        string s = "<SCRIPT language='javascript'>document.getElementById('" + ctrl.ClientID + "').focus() </SCRIPT>";
190
 
                        Page.RegisterStartupScript( "focus", s );
191
 
                }
192
 
 
193
 
                #endregion
194
 
 
195
 
                #region Protected Methods
196
 
 
197
 
                /// <summary>
198
 
                /// Get a Localized String
199
 
                /// </summary>
200
 
                /// <param name="key"></param>
201
 
                /// <returns></returns>
202
 
                protected string GetString( string key )
203
 
                {
204
 
                        return rm.GetString( key );
205
 
                }
206
 
 
207
 
                /// <summary>
208
 
                /// Event handler that gets called when the cancel button is clicked.
209
 
                /// </summary>
210
 
                /// <param name="source"></param>
211
 
                /// <param name="e"></param>
212
 
                protected void OnCancelButton_Click( object source, EventArgs e )
213
 
                {
214
 
                        // Return back to the referring page.
215
 
                        string url = web.TrimUrl(ReferringPage);
216
 
                        Page.Response.Redirect( url, true );
217
 
                }
218
 
 
219
 
                /// <summary>
220
 
                /// Event handler that gets called when the create button is clicked.
221
 
                /// </summary>
222
 
                /// <param name="source"></param>
223
 
                /// <param name="e"></param>
224
 
                protected void OnCreateButton_Click( object source, EventArgs e )
225
 
                {
226
 
                        if ( !ValidPage )
227
 
                        {
228
 
                                TopNav.ShowError( GetString( "ALLFIELDSREQUIRED" ) );
229
 
                        }
230
 
                        else
231
 
                        {
232
 
                                // Verify that the retyped password matches.
233
 
                                if ( Password.Text == RetypedPassword.Text )
234
 
                                {
235
 
                                        try
236
 
                                        {
237
 
                                                web.CreateUser( 
238
 
                                                        UserName.Text, 
239
 
                                                        Password.Text, 
240
 
                                                        Guid.NewGuid().ToString(), 
241
 
                                                        FirstName.Text, 
242
 
                                                        LastName.Text, 
243
 
                                                        FullName.Text, 
244
 
                                                        String.Empty, 
245
 
                                                        String.Empty );
246
 
 
247
 
                                                // Return back to the referring page.
248
 
                                                string url = web.TrimUrl(ReferringPage);
249
 
                                                Page.Response.Redirect( url, true );
250
 
                                        }
251
 
                                        catch ( Exception ex )
252
 
                                        {
253
 
                                                TopNav.ShowError( GetString( "ERRORCANNOTCREATEUSER" ), ex );
254
 
                                        }
255
 
                                }
256
 
                                else
257
 
                                {
258
 
                                        TopNav.ShowError( GetString( "PASSWORDSDONOTMATCH" ) );
259
 
                                }
260
 
                        }
261
 
                }
262
 
 
263
 
                /// <summary>
264
 
                /// Event handler that gets called when the FirstName text box changes.
265
 
                /// </summary>
266
 
                /// <param name="source"></param>
267
 
                /// <param name="e"></param>
268
 
                protected void OnFirstNameChanged( object source, EventArgs e )
269
 
                {
270
 
 
271
 
                }
272
 
 
273
 
                /// <summary>
274
 
                /// Event handler that gets called when the LastName text box changes.
275
 
                /// </summary>
276
 
                /// <param name="source"></param>
277
 
                /// <param name="e"></param>
278
 
                protected void OnLastNameChanged( object source, EventArgs e )
279
 
                {
280
 
                }
281
 
 
282
 
                #endregion
283
 
 
284
 
                #region Web Form Designer generated code
285
 
 
286
 
                /// <summary>
287
 
                /// OnInit
288
 
                /// </summary>
289
 
                /// <param name="e"></param>
290
 
                override protected void OnInit(EventArgs e)
291
 
                {
292
 
                        //
293
 
                        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
294
 
                        //
295
 
                        InitializeComponent();
296
 
                        base.OnInit(e);
297
 
                }
298
 
                
299
 
                /// <summary>
300
 
                /// Required method for Designer support - do not modify
301
 
                /// the contents of this method with the code editor.
302
 
                /// </summary>
303
 
                private void InitializeComponent()
304
 
                {    
305
 
                        if ( !Page.IsPostBack )
306
 
                        {
307
 
                                // Set the render event to happen only on page load.
308
 
                                Page.PreRender += new EventHandler( Page_PreRender );
309
 
                        }
310
 
 
311
 
                        this.Load += new System.EventHandler(this.Page_Load);
312
 
                }
313
 
 
314
 
                #endregion
315
 
        }
316
 
}