diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-06-20 11:57:20 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-06-20 11:59:42 -0700 |
commit | bfec3a8eb6c14c312008af8e4fd3f68c4d510c5b (patch) | |
tree | 79716fa53270f486d6f5858286c0d1986e4b9ac0 | |
parent | 79b2adcec5b62f7c633d150184258322cba955ed (diff) | |
download | DotNetOpenAuth-bfec3a8eb6c14c312008af8e4fd3f68c4d510c5b.zip DotNetOpenAuth-bfec3a8eb6c14c312008af8e4fd3f68c4d510c5b.tar.gz DotNetOpenAuth-bfec3a8eb6c14c312008af8e4fd3f68c4d510c5b.tar.bz2 |
OpenIdButton now defaults to NOT precreating the OpenID request, but that behavior is just a property away.
-rw-r--r-- | src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdButton.cs | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdButton.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdButton.cs index c6a5476..ed529a2 100644 --- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdButton.cs +++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdButton.cs @@ -20,7 +20,7 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// An ASP.NET control that renders a button that initiates an /// authentication when clicked. /// </summary> - public class OpenIdButton : OpenIdRelyingPartyControlBase { + public class OpenIdButton : OpenIdRelyingPartyControlBase, IPostBackEventHandler { #region Property defaults /// <summary> @@ -28,6 +28,11 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// </summary> private const string TextDefault = "Log in with [Provider]!"; + /// <summary> + /// The default value for the <see cref="PrecreateRequest"/> property. + /// </summary> + private const bool PrecreateRequestDefault = false; + #endregion #region View state keys @@ -42,6 +47,11 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { /// </summary> private const string ImageUrlViewStateKey = "ImageUrl"; + /// <summary> + /// The key under which the value for the <see cref="PrecreateRequest"/> property will be stored. + /// </summary> + private const string PrecreateRequestViewStateKey = "PrecreateRequest"; + #endregion /// <summary> @@ -79,6 +89,17 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { } /// <summary> + /// Gets or sets a value indicating whether to pre-discover the identifier so + /// the user agent has an immediate redirect. + /// </summary> + [Bindable(true), Category(BehaviorCategory), DefaultValue(PrecreateRequestDefault)] + [Description("Whether to pre-discover the identifier so the user agent has an immediate redirect.")] + public bool PrecreateRequest { + get { return (bool)(ViewState[PrecreateRequestViewStateKey] ?? PrecreateRequestDefault); } + set { ViewState[PrecreateRequestViewStateKey] = value; } + } + + /// <summary> /// Gets or sets a value indicating when to use a popup window to complete the login experience. /// </summary> /// <value>The default value is <see cref="PopupBehavior.Never"/>.</value> @@ -88,6 +109,21 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { set { ErrorUtilities.VerifySupported(value == base.Popup, OpenIdStrings.PropertyValueNotSupported); } } + #region IPostBackEventHandler Members + + /// <summary> + /// When implemented by a class, enables a server control to process an event raised when a form is posted to the server. + /// </summary> + /// <param name="eventArgument">A <see cref="T:System.String"/> that represents an optional event argument to be passed to the event handler.</param> + public void RaisePostBackEvent(string eventArgument) { + if (!this.PrecreateRequest) { + IAuthenticationRequest request = this.CreateRequests().FirstOrDefault(); + request.RedirectToProvider(); + } + } + + #endregion + /// <summary> /// Raises the <see cref="E:System.Web.UI.Control.PreRender"/> event. /// </summary> @@ -109,11 +145,15 @@ namespace DotNetOpenAuth.OpenId.RelyingParty { writer.WriteEncodedText(string.Format(CultureInfo.CurrentCulture, "[{0}]", OpenIdStrings.NoIdentifierSet)); } else { string tooltip = this.Text; - IAuthenticationRequest request = this.CreateRequests().FirstOrDefault(); - if (request != null) { - RenderOpenIdMessageTransmissionAsAnchorAttributes(writer, request, tooltip); + if (this.PrecreateRequest && !this.DesignMode) { + IAuthenticationRequest request = this.CreateRequests().FirstOrDefault(); + if (request != null) { + RenderOpenIdMessageTransmissionAsAnchorAttributes(writer, request, tooltip); + } else { + tooltip = OpenIdStrings.OpenIdEndpointNotFound; + } } else { - tooltip = OpenIdStrings.OpenIdEndpointNotFound; + writer.AddAttribute(HtmlTextWriterAttribute.Href, this.Page.ClientScript.GetPostBackClientHyperlink(this, null)); } writer.AddAttribute(HtmlTextWriterAttribute.Title, tooltip); |