From 0f8c85a92f63fc67227a93b53d51b20a6236e188 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sat, 24 Jan 2009 22:46:26 -0800 Subject: [PATCH] Added the OpenIdMobileTextBox ASP.NET control. --- .gitignore | 4 + src/DotNetOpenAuth/DotNetOpenAuth.csproj | 2 + .../OpenId/Interop/OpenIdRelyingPartyShim.cs | 4 +- .../{OpenIdTextBox.cs => OpenIdMobileTextBox.cs} | 425 ++------------------- .../OpenId/RelyingParty/OpenIdTextBox.cs | 7 +- 5 files changed, 36 insertions(+), 406 deletions(-) copy src/DotNetOpenAuth/OpenId/RelyingParty/{OpenIdTextBox.cs => OpenIdMobileTextBox.cs} (66%) diff --git a/.gitignore b/.gitignore index f6e988f..be67a21 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ drops StyleCop.Cache *.LDF *~ +PrecompiledWeb +*.suo +*.cache +*.user diff --git a/src/DotNetOpenAuth/DotNetOpenAuth.csproj b/src/DotNetOpenAuth/DotNetOpenAuth.csproj index fa2b65e..4844153 100644 --- a/src/DotNetOpenAuth/DotNetOpenAuth.csproj +++ b/src/DotNetOpenAuth/DotNetOpenAuth.csproj @@ -59,6 +59,7 @@ 3.0 + 3.5 @@ -272,6 +273,7 @@ + diff --git a/src/DotNetOpenAuth/OpenId/Interop/OpenIdRelyingPartyShim.cs b/src/DotNetOpenAuth/OpenId/Interop/OpenIdRelyingPartyShim.cs index 51feb69..b16bd7e 100644 --- a/src/DotNetOpenAuth/OpenId/Interop/OpenIdRelyingPartyShim.cs +++ b/src/DotNetOpenAuth/OpenId/Interop/OpenIdRelyingPartyShim.cs @@ -41,7 +41,7 @@ namespace DotNetOpenAuth.OpenId.Interop { /// An authentication request object that describes the HTTP response to /// send to the user agent to initiate the authentication. /// - /// Thrown if no OpenID endpoint could be found. + /// Thrown if no OpenID endpoint could be found. string CreateRequest(string userSuppliedIdentifier, string realm, string returnToUrl); /// @@ -86,7 +86,7 @@ namespace DotNetOpenAuth.OpenId.Interop { /// An authentication request object that describes the HTTP response to /// send to the user agent to initiate the authentication. /// - /// Thrown if no OpenID endpoint could be found. + /// Thrown if no OpenID endpoint could be found. [SuppressMessage("Microsoft.Usage", "CA2234:PassSystemUriObjectsInsteadOfStrings", Justification = "COM requires primitive types")] public string CreateRequest(string userSuppliedIdentifier, string realm, string returnToUrl) { OpenIdRelyingParty rp = new OpenIdRelyingParty(null); diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdMobileTextBox.cs similarity index 66% copy from src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs copy to src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdMobileTextBox.cs index 25088ab..6c9da66 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdMobileTextBox.cs @@ -1,52 +1,36 @@ //----------------------------------------------------------------------- -// +// // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- -[assembly: System.Web.UI.WebResource(DotNetOpenAuth.OpenId.RelyingParty.OpenIdTextBox.EmbeddedLogoResourceName, "image/gif")] - -#pragma warning disable 0809 // marking inherited, unsupported properties as obsolete to discourage their use +[assembly: System.Web.UI.WebResource(DotNetOpenAuth.OpenId.RelyingParty.OpenIdMobileTextBox.EmbeddedLogoResourceName, "image/gif")] namespace DotNetOpenAuth.OpenId.RelyingParty { using System; - using System.Collections.Generic; - using System.Collections.Specialized; using System.ComponentModel; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; - using System.Net; using System.Text.RegularExpressions; - using System.Web; using System.Web.Security; using System.Web.UI; - using System.Web.UI.WebControls; + using System.Web.UI.MobileControls; using DotNetOpenAuth.Configuration; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Extensions.SimpleRegistration; /// - /// An ASP.NET control that provides a minimal text box that is OpenID-aware. + /// An ASP.NET control for mobile devices that provides a minimal text box that is OpenID-aware. /// - /// - /// This control offers greater UI flexibility than the - /// control, but requires more work to be done by the hosting web site to - /// assemble a complete login experience. - /// [DefaultProperty("Text"), ValidationProperty("Text")] - [ToolboxData("<{0}:OpenIdTextBox runat=\"server\" />")] - public class OpenIdTextBox : CompositeControl, IEditableTextControl, ITextControl { + [ToolboxData("<{0}:OpenIdMobileTextBox runat=\"server\" />")] + public class OpenIdMobileTextBox : TextBox { /// /// The name of the manifest stream containing the /// OpenID logo that is placed inside the text box. /// - internal const string EmbeddedLogoResourceName = Util.DefaultNamespace + ".OpenId.RelyingParty.openid_login.gif"; - - /// - /// Default value for property. - /// - protected const short TabIndexDefault = 0; + internal const string EmbeddedLogoResourceName = OpenIdTextBox.EmbeddedLogoResourceName; /// /// Default value of . @@ -125,16 +109,6 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { private const string RequestFullNameViewStateKey = "RequestFullName"; /// - /// The viewstate key to use for the property. - /// - private const string PresetBorderViewStateKey = "PresetBorder"; - - /// - /// The viewstate key to use for the property. - /// - private const string ShowLogoViewStateKey = "ShowLogo"; - - /// /// The viewstate key to use for the property. /// private const string UsePersistentCookieViewStateKey = "UsePersistentCookie"; @@ -174,16 +148,6 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { #region Property defaults /// - /// The default value for the property. - /// - private const int ColumnsDefault = 40; - - /// - /// The default value for the property. - /// - private const int MaxLengthDefault = 40; - - /// /// The default value for the property. /// private const bool EnableRequestProfileDefault = true; @@ -204,36 +168,16 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { private const bool StatelessDefault = false; /// - /// The default value for the property. - /// - private const bool ShowLogoDefault = true; - - /// - /// The default value for the property. - /// - private const bool PresetBorderDefault = true; - - /// /// The default value for the property. /// private const string PolicyUrlDefault = ""; /// - /// The default value for the property. - /// - private const string CssClassDefault = "openid"; - - /// /// The default value for the property. /// private const string ReturnToUrlDefault = ""; /// - /// The default value for the property. - /// - private const string TextDefault = ""; - - /// /// The default value for the property. /// private const string RealmUrlDefault = "~/"; @@ -291,22 +235,13 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { private const string UsePersistentCookieCallbackKey = "OpenIdTextBox_UsePersistentCookie"; /// - /// The text in the text box before the text box is instantiated. + /// Initializes a new instance of the class. /// - private string text = TextDefault; - - /// - /// The text box itself. - /// - private TextBox wrappedTextBox; - - /// - /// Initializes a new instance of the class. - /// - public OpenIdTextBox() { - this.InitializeControls(); + public OpenIdMobileTextBox() { } + #region Events + /// /// Fired upon completion of a successful login. /// @@ -331,39 +266,11 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { [Description("Fired when an Immediate authentication attempt fails, and the Provider suggests using non-Immediate mode.")] public event EventHandler SetupRequired; - #region IEditableTextControl Members - - /// - /// Occurs when the content of the text changes between posts to the server. - /// - public event EventHandler TextChanged { - add { this.WrappedTextBox.TextChanged += value; } - remove { this.WrappedTextBox.TextChanged -= value; } - } - #endregion #region Properties /// - /// Gets or sets the content of the text box. - /// - [Bindable(true), DefaultValue(""), Category(AppearanceCategory)] - [Description("The content of the text box.")] - public string Text { - get { - return this.WrappedTextBox != null ? this.WrappedTextBox.Text : this.text; - } - - set { - this.text = value; - if (this.WrappedTextBox != null) { - this.WrappedTextBox.Text = value; - } - } - } - - /// /// Gets or sets the OpenID of the relying party web site. /// [SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", MessageId = "System.Uri", Justification = "Using Uri.ctor for validation.")] @@ -457,36 +364,6 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { } /// - /// Gets or sets the CSS class assigned to the text box. - /// - [Bindable(true), DefaultValue(CssClassDefault), Category(AppearanceCategory)] - [Description("The CSS class assigned to the text box.")] - public override string CssClass { - get { return this.WrappedTextBox.CssClass; } - set { this.WrappedTextBox.CssClass = value; } - } - - /// - /// Gets or sets a value indicating whether to show the OpenID logo in the text box. - /// - [Bindable(true), DefaultValue(ShowLogoDefault), Category(AppearanceCategory)] - [Description("The visibility of the OpenID logo in the text box.")] - public bool ShowLogo { - get { return (bool)(this.ViewState[ShowLogoViewStateKey] ?? ShowLogoDefault); } - set { this.ViewState[ShowLogoViewStateKey] = value; } - } - - /// - /// Gets or sets a value indicating whether to use inline styling to force a solid gray border. - /// - [Bindable(true), DefaultValue(PresetBorderDefault), Category(AppearanceCategory)] - [Description("Whether to use inline styling to force a solid gray border.")] - public bool PresetBorder { - get { return (bool)(this.ViewState[PresetBorderViewStateKey] ?? PresetBorderDefault); } - set { this.ViewState[PresetBorderViewStateKey] = value; } - } - - /// /// Gets or sets a value indicating whether to send a persistent cookie upon successful /// login so the user does not have to log in upon returning to this site. /// @@ -499,43 +376,6 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { } /// - /// Gets or sets the width of the text box in characters. - /// - [Bindable(true), DefaultValue(ColumnsDefault), Category(AppearanceCategory)] - [Description("The width of the text box in characters.")] - public int Columns { - get { return this.WrappedTextBox.Columns; } - set { this.WrappedTextBox.Columns = value; } - } - - /// - /// Gets or sets the maximum number of characters the browser should allow - /// - [Bindable(true), DefaultValue(MaxLengthDefault), Category(AppearanceCategory)] - [Description("The maximum number of characters the browser should allow.")] - public int MaxLength { - get { return this.WrappedTextBox.MaxLength; } - set { this.WrappedTextBox.MaxLength = value; } - } - - /// - /// Gets or sets the tab index of the Web server control. - /// - /// - /// - /// The tab index of the Web server control. The default is 0, which indicates that this property is not set. - /// - /// - /// The specified tab index is not between -32768 and 32767. - /// - [Bindable(true), DefaultValue(TabIndexDefault), Category(BehaviorCategory)] - [Description("The tab index of the text box control.")] - public override short TabIndex { - get { return this.WrappedTextBox.TabIndex; } - set { this.WrappedTextBox.TabIndex = value; } - } - - /// /// Gets or sets your level of interest in receiving the user's nickname from the Provider. /// [Bindable(true), DefaultValue(RequestNicknameDefault), Category(ProfileCategory)] @@ -678,179 +518,22 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { #endregion - #region Properties to hide - - /// - /// Gets or sets the foreground color (typically the color of the text) of the Web server control. - /// - /// - /// A that represents the foreground color of the control. The default is . - /// - [Obsolete, Browsable(false), Bindable(false)] - public override System.Drawing.Color ForeColor { - get { throw new NotSupportedException(); } - set { throw new NotSupportedException(); } - } - - /// - /// Gets or sets the background color of the Web server control. - /// - /// - /// A that represents the background color of the control. The default is , which indicates that this property is not set. - /// - [Obsolete, Browsable(false), Bindable(false)] - public override System.Drawing.Color BackColor { - get { throw new NotSupportedException(); } - set { throw new NotSupportedException(); } - } - - /// - /// Gets or sets the border color of the Web control. - /// - /// - /// A that represents the border color of the control. The default is , which indicates that this property is not set. - /// - [Obsolete, Browsable(false), Bindable(false)] - public override System.Drawing.Color BorderColor { - get { throw new NotSupportedException(); } - set { throw new NotSupportedException(); } - } - - /// - /// Gets or sets the border width of the Web server control. - /// - /// - /// A that represents the border width of a Web server control. The default value is , which indicates that this property is not set. - /// - /// - /// The specified border width is a negative value. - /// - [Obsolete, Browsable(false), Bindable(false)] - public override Unit BorderWidth { - get { return Unit.Empty; } - set { throw new NotSupportedException(); } - } - - /// - /// Gets or sets the border style of the Web server control. - /// - /// - /// One of the enumeration values. The default is NotSet. - /// - [Obsolete, Browsable(false), Bindable(false)] - public override BorderStyle BorderStyle { - get { return BorderStyle.None; } - set { throw new NotSupportedException(); } - } - - /// - /// Gets the font properties associated with the Web server control. - /// - /// - /// A that represents the font properties of the Web server control. - /// - [Obsolete, Browsable(false), Bindable(false)] - public override FontInfo Font { - get { return null; } - } - - /// - /// Gets or sets the height of the Web server control. - /// - /// - /// A that represents the height of the control. The default is . - /// - /// - /// The height was set to a negative value. - /// - [Obsolete, Browsable(false), Bindable(false)] - public override Unit Height { - get { return Unit.Empty; } - set { throw new NotSupportedException(); } - } - - /// - /// Gets or sets the width of the Web server control. - /// - /// - /// A that represents the width of the control. The default is . - /// - /// - /// The width of the Web server control was set to a negative value. - /// - [Obsolete, Browsable(false), Bindable(false)] - public override Unit Width { - get { return Unit.Empty; } - set { throw new NotSupportedException(); } - } - - /// - /// Gets or sets the text displayed when the mouse pointer hovers over the Web server control. - /// - /// - /// The text displayed when the mouse pointer hovers over the Web server control. The default is . - /// - [Obsolete, Browsable(false), Bindable(false)] - public override string ToolTip { - get { return string.Empty; } - set { throw new NotSupportedException(); } - } - - /// - /// Gets or sets the skin to apply to the control. - /// - /// - /// The name of the skin to apply to the control. The default is . - /// - /// - /// The skin specified in the property does not exist in the theme. - /// - [Obsolete, Browsable(false), Bindable(false)] - public override string SkinID { - get { return string.Empty; } - set { throw new NotSupportedException(); } - } - - /// - /// Gets or sets a value indicating whether themes apply to this control. - /// - /// true to use themes; otherwise, false. The default is false. - /// - [Obsolete, Browsable(false), Bindable(false)] - public override bool EnableTheming { - get { return false; } - set { throw new NotSupportedException(); } - } - - #endregion - - /// - /// Gets the control that this control wraps. - /// - protected TextBox WrappedTextBox { - get { return this.wrappedTextBox; } - } - - /// - /// Gets or sets a value indicating whether the text box should - /// receive input focus when the web page appears. - /// - protected bool ShouldBeFocused { get; set; } - /// /// Gets or sets the OpenID authentication request that is about to be sent. /// protected IAuthenticationRequest Request { get; set; } /// - /// Sets the input focus to start on the text box when the page appears - /// in the user's browser. + /// Immediately redirects to the OpenID Provider to verify the Identifier + /// provided in the text box. /// - public override void Focus() { - if (Controls.Count == 0) { - this.ShouldBeFocused = true; - } else { - this.WrappedTextBox.Focus(); + public void LogOn() { + if (this.Request == null) { + this.CreateRequest(); // sets this.Request + } + + if (this.Request != null) { + this.Request.RedirectToProvider(); } } @@ -909,56 +592,18 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { } /// - /// Immediately redirects to the OpenID Provider to verify the Identifier - /// provided in the text box. - /// - public void LogOn() { - if (this.Request == null) { - this.CreateRequest(); // sets this.Request - } - - if (this.Request != null) { - this.Request.RedirectToProvider(); - } - } - - /// - /// Creates the text box control. - /// - protected override void CreateChildControls() { - base.CreateChildControls(); - - this.Controls.Add(this.wrappedTextBox); - if (this.ShouldBeFocused) { - this.WrappedTextBox.Focus(); - } - } - - /// - /// Initializes the text box control. - /// - protected virtual void InitializeControls() { - this.wrappedTextBox = new TextBox(); - this.wrappedTextBox.ID = "wrappedTextBox"; - this.wrappedTextBox.CssClass = CssClassDefault; - this.wrappedTextBox.Columns = ColumnsDefault; - this.wrappedTextBox.Text = this.text; - this.wrappedTextBox.TabIndex = TabIndexDefault; - } - - /// /// Checks for incoming OpenID authentication responses and fires appropriate events. /// /// The object that contains the event data. protected override void OnLoad(EventArgs e) { base.OnLoad(e); - if (!Enabled || Page.IsPostBack) { + if (Page.IsPostBack) { return; } - var consumer = this.CreateRelyingParty(); - var response = consumer.GetResponse(); + var rp = this.CreateRelyingParty(); + var response = rp.GetResponse(); if (response != null) { string persistentString = response.GetCallbackArgument(UsePersistentCookieCallbackKey); bool persistentBool; @@ -985,30 +630,6 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { } } - /// - /// Prepares the text box to be rendered. - /// - /// An object that contains the event data. - protected override void OnPreRender(EventArgs e) { - base.OnPreRender(e); - - if (this.ShowLogo) { - string logoUrl = Page.ClientScript.GetWebResourceUrl( - typeof(OpenIdTextBox), EmbeddedLogoResourceName); - this.WrappedTextBox.Style[HtmlTextWriterStyle.BackgroundImage] = string.Format( - CultureInfo.InvariantCulture, "url({0})", HttpUtility.HtmlEncode(logoUrl)); - this.WrappedTextBox.Style["background-repeat"] = "no-repeat"; - this.WrappedTextBox.Style["background-position"] = "0 50%"; - this.WrappedTextBox.Style[HtmlTextWriterStyle.PaddingLeft] = "18px"; - } - - if (this.PresetBorder) { - this.WrappedTextBox.Style[HtmlTextWriterStyle.BorderStyle] = "solid"; - this.WrappedTextBox.Style[HtmlTextWriterStyle.BorderWidth] = "1px"; - this.WrappedTextBox.Style[HtmlTextWriterStyle.BorderColor] = "lightgray"; - } - } - #region Events /// diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs index 25088ab..767d925 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdTextBox.cs @@ -307,6 +307,8 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { this.InitializeControls(); } + #region Events + /// /// Fired upon completion of a successful login. /// @@ -331,6 +333,7 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { [Description("Fired when an Immediate authentication attempt fails, and the Provider suggests using non-Immediate mode.")] public event EventHandler SetupRequired; + #endregion #region IEditableTextControl Members /// @@ -957,8 +960,8 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { return; } - var consumer = this.CreateRelyingParty(); - var response = consumer.GetResponse(); + var rp = this.CreateRelyingParty(); + var response = rp.GetResponse(); if (response != null) { string persistentString = response.GetCallbackArgument(UsePersistentCookieCallbackKey); bool persistentBool; -- 2.11.4.GIT