2 // System.Web.UI.WebControls.LoginView class
5 // Sebastien Pouliot <sebastien@ximian.com>
6 // Konstantin Triger <kostat@mainsoft.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.ComponentModel;
34 using System.Security.Permissions;
36 namespace System.Web.UI.WebControls {
39 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
40 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
42 [DefaultEvent ("ViewChanged")]
43 [DefaultProperty ("CurrentView")]
44 [Designer ("System.Web.UI.Design.WebControls.LoginViewDesigner," + Consts.AssemblySystem_Design)]
45 [ParseChildren (true)]
46 [PersistChildren (false)]
48 public class LoginView : Control, INamingContainer {
50 private static readonly object viewChangedEvent = new object ();
51 private static readonly object viewChangingEvent = new object ();
53 private ITemplate anonymousTemplate;
54 private ITemplate loggedInTemplate;
55 private bool isAuthenticated;
57 private RoleGroupCollection coll;
68 [PersistenceMode (PersistenceMode.InnerProperty)]
69 [TemplateContainer (typeof (LoginView))]
70 public virtual ITemplate AnonymousTemplate {
71 get { return anonymousTemplate; }
72 set { anonymousTemplate = value; }
75 public override ControlCollection Controls {
77 EnsureChildControls();
83 public override bool EnableTheming {
84 get { return theming; }
85 set { theming = value; }
90 [PersistenceMode (PersistenceMode.InnerProperty)]
91 [TemplateContainer (typeof (LoginView))]
92 public virtual ITemplate LoggedInTemplate {
93 get { return loggedInTemplate; }
94 set { loggedInTemplate = value; }
98 [MergableProperty (false)]
99 [PersistenceMode (PersistenceMode.InnerProperty)]
101 public RoleGroupCollection RoleGroups {
104 coll = new RoleGroupCollection ();
110 public override string SkinID {
111 get { return base.SkinID; }
112 set { base.SkinID = value; }
115 bool IsAuthenticated {
117 if (Page != null && !Page.IsPostBack)
118 isAuthenticated = Page.Request.IsAuthenticated;
120 return isAuthenticated;
124 [MonoTODO("Handle RoleGroups")]
125 protected internal override void CreateChildControls ()
128 Control c = new Control();
130 LoggedInTemplate.InstantiateIn (c);
132 AnonymousTemplate.InstantiateIn (c);
137 public override void DataBind ()
139 EventArgs args = EventArgs.Empty;
140 OnDataBinding (args);
141 EnsureChildControls ();
145 [EditorBrowsable (EditorBrowsableState.Never)]
146 public override void Focus ()
148 // LAMESPEC: throw new InvalidOperationException ();
149 throw new NotSupportedException ();
152 protected internal override void LoadControlState (object savedState)
154 if (savedState == null) {
155 base.LoadControlState (savedState);
159 Pair pair = (Pair)savedState;
160 base.LoadControlState (pair.First);
161 isAuthenticated = (bool)pair.Second;
164 protected internal override void OnInit (EventArgs e)
168 Page.RegisterRequiresControlState(this);
171 protected internal override void OnPreRender (EventArgs e)
173 base.OnPreRender (e);
174 isAuthenticated = IsAuthenticated;
175 EnsureChildControls ();
178 protected virtual void OnViewChanged (EventArgs e)
180 EventHandler h = (EventHandler)Events [viewChangedEvent];
185 protected virtual void OnViewChanging (EventArgs e)
187 EventHandler h = (EventHandler)Events [viewChangingEvent];
192 protected internal override void Render(HtmlTextWriter writer) {
193 EnsureChildControls();
194 base.Render (writer);
197 protected internal override object SaveControlState ()
199 object baseState = base.SaveControlState ();
201 return new Pair (baseState, isAuthenticated);
206 [MonoTODO ("for design-time usage - no more details available")]
207 protected override void SetDesignModeState (IDictionary data)
209 base.SetDesignModeState (data);
215 public event EventHandler ViewChanged {
216 add { Events.AddHandler (viewChangedEvent, value); }
217 remove { Events.RemoveHandler (viewChangedEvent, value); }
220 public event EventHandler ViewChanging {
221 add { Events.AddHandler (viewChangingEvent, value); }
222 remove { Events.RemoveHandler (viewChangingEvent, value); }