summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-10-29 20:19:31 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-10-29 20:19:31 -0700
commite65d24a8c0c3bf4cc7dfc0f79b553184bac9be22 (patch)
tree6ab6bf9c088bbe9561f415919c755cbc1f1352c7
parent515b05ec1c046eee0f93792d3e9cb4463e87b8f1 (diff)
downloadDotNetOpenAuth-e65d24a8c0c3bf4cc7dfc0f79b553184bac9be22.zip
DotNetOpenAuth-e65d24a8c0c3bf4cc7dfc0f79b553184bac9be22.tar.gz
DotNetOpenAuth-e65d24a8c0c3bf4cc7dfc0f79b553184bac9be22.tar.bz2
Added a login button to make it clear how to use the ajax text box in the selector control.
-rw-r--r--src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs50
-rw-r--r--src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.js47
-rw-r--r--src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.cs1
-rw-r--r--src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.js9
4 files changed, 90 insertions, 17 deletions
diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs
index 263fc4c..d0060dc 100644
--- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs
+++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.cs
@@ -137,6 +137,11 @@ namespace DotNetOpenAuth.OpenId.RelyingParty {
private const string LogOnToolTipViewStateKey = "LoginToolTip";
/// <summary>
+ /// The viewstate key to use for storing the value of the <see cref="LogOnPostBackToolTip"/> property.
+ /// </summary>
+ private const string LogOnPostBackToolTipViewStateKey = "LoginPostBackToolTip";
+
+ /// <summary>
/// The viewstate key to use for storing the value of the <see cref="Name"/> property.
/// </summary>
private const string NameViewStateKey = "Name";
@@ -171,6 +176,11 @@ namespace DotNetOpenAuth.OpenId.RelyingParty {
/// </summary>
private const string DownloadYahooUILibraryViewStateKey = "DownloadYahooUILibrary";
+ /// <summary>
+ /// The viewstate key to use for storing the value of the <see cref="ShowLogOnPostBackButton"/> property.
+ /// </summary>
+ private const string ShowLogOnPostBackButtonViewStateKey = "ShowLogOnPostBackButton";
+
#endregion
#region Property defaults
@@ -251,15 +261,25 @@ namespace DotNetOpenAuth.OpenId.RelyingParty {
private const string LogOnToolTipDefault = "Click here to log in using a pop-up window.";
/// <summary>
+ /// The default value for the <see cref="LogOnPostBackToolTip"/> property.
+ /// </summary>
+ private const string LogOnPostBackToolTipDefault = "Click here to log in immediately.";
+
+ /// <summary>
/// The default value for the <see cref="RetryText"/> property.
/// </summary>
private const string RetryTextDefault = "RETRY";
/// <summary>
- /// The default vlaue for the <see cref="DownloadYahooUILibrary"/> property.
+ /// The default value for the <see cref="DownloadYahooUILibrary"/> property.
/// </summary>
private const bool DownloadYahooUILibraryDefault = true;
+ /// <summary>
+ /// The default value for the <see cref="ShowLogOnPostBackButton"/> property.
+ /// </summary>
+ private const bool ShowLogOnPostBackButtonDefault = false;
+
#endregion
/// <summary>
@@ -480,6 +500,16 @@ namespace DotNetOpenAuth.OpenId.RelyingParty {
}
/// <summary>
+ /// Gets or sets the rool tip text that appears on the LOG IN button when clicking the button will result in an immediate postback.
+ /// </summary>
+ [Bindable(true), DefaultValue(LogOnPostBackToolTipDefault), Localizable(true), Category(AppearanceCategory)]
+ [Description("The tool tip text that appears on the LOG IN button when clicking the button will result in an immediate postback.")]
+ public string LogOnPostBackToolTip {
+ get { return (string)(this.ViewState[LogOnPostBackToolTipViewStateKey] ?? LogOnPostBackToolTipDefault); }
+ set { this.ViewState[LogOnPostBackToolTipViewStateKey] = value ?? string.Empty; }
+ }
+
+ /// <summary>
/// Gets or sets the text that appears on the RETRY button in cases where authentication times out.
/// </summary>
[Bindable(true), DefaultValue(RetryTextDefault), Localizable(true), Category(AppearanceCategory)]
@@ -583,6 +613,17 @@ namespace DotNetOpenAuth.OpenId.RelyingParty {
set { this.ViewState[DownloadYahooUILibraryViewStateKey] = value; }
}
+ /// <summary>
+ /// Gets or sets a value indicating whether the "Log in" button will be shown
+ /// to initiate a postback containing the positive assertion.
+ /// </summary>
+ [Bindable(true), DefaultValue(ShowLogOnPostBackButtonDefault), Category(AppearanceCategory)]
+ [Description("Whether the log in button will be shown to initiate a postback containing the positive assertion.")]
+ public bool ShowLogOnPostBackButton {
+ get { return (bool)(this.ViewState[ShowLogOnPostBackButtonViewStateKey] ?? ShowLogOnPostBackButtonDefault); }
+ set { this.ViewState[ShowLogOnPostBackButtonViewStateKey] = value; }
+ }
+
#endregion
/// <summary>
@@ -788,7 +829,7 @@ loader.insert();";
startupScript.AppendFormat("var box = document.getElementsByName('{0}')[0];{1}", this.Name, Environment.NewLine);
startupScript.AppendFormat(
CultureInfo.InvariantCulture,
- "initAjaxOpenId(box, {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, function() {{{18};}});{19}",
+ "initAjaxOpenId(box, {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, function() {{{21};}});{22}",
MessagingUtilities.GetSafeJavascriptValue(this.Page.ClientScript.GetWebResourceUrl(this.GetType(), OpenIdTextBox.EmbeddedLogoResourceName)),
MessagingUtilities.GetSafeJavascriptValue(this.Page.ClientScript.GetWebResourceUrl(this.GetType(), EmbeddedDotNetOpenIdLogoResourceName)),
MessagingUtilities.GetSafeJavascriptValue(this.Page.ClientScript.GetWebResourceUrl(this.GetType(), EmbeddedSpinnerResourceName)),
@@ -799,6 +840,8 @@ loader.insert();";
string.IsNullOrEmpty(this.OnClientAssertionReceived) ? "null" : "'" + this.OnClientAssertionReceived.Replace(@"\", @"\\").Replace("'", @"\'") + "'",
MessagingUtilities.GetSafeJavascriptValue(this.LogOnText),
MessagingUtilities.GetSafeJavascriptValue(this.LogOnToolTip),
+ this.ShowLogOnPostBackButton ? "true" : "false",
+ MessagingUtilities.GetSafeJavascriptValue(this.LogOnPostBackToolTip),
MessagingUtilities.GetSafeJavascriptValue(this.RetryText),
MessagingUtilities.GetSafeJavascriptValue(this.RetryToolTip),
MessagingUtilities.GetSafeJavascriptValue(this.BusyToolTip),
@@ -807,7 +850,8 @@ loader.insert();";
MessagingUtilities.GetSafeJavascriptValue(this.AuthenticationSucceededToolTip),
MessagingUtilities.GetSafeJavascriptValue(this.AuthenticatedAsToolTip),
MessagingUtilities.GetSafeJavascriptValue(this.AuthenticationFailedToolTip),
- this.AutoPostBack ? Page.ClientScript.GetPostBackEventReference(this, null) : null,
+ this.AutoPostBack ? "true" : "false",
+ Page.ClientScript.GetPostBackEventReference(this, null),
Environment.NewLine);
startupScript.AppendLine("</script>");
diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.js b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.js
index 7d784d4..1941175 100644
--- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.js
+++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdAjaxTextBox.js
@@ -8,11 +8,14 @@
function initAjaxOpenId(box, openid_logo_url, dotnetopenid_logo_url, spinner_url, success_icon_url, failure_icon_url,
throttle, timeout, assertionReceivedCode,
- loginButtonText, loginButtonToolTip, retryButtonText, retryButtonToolTip, busyToolTip,
+ loginButtonText, loginButtonToolTip, showLoginPostBackButton, loginPostBackToolTip,
+ retryButtonText, retryButtonToolTip, busyToolTip,
identifierRequiredMessage, loginInProgressMessage,
authenticatedByToolTip, authenticatedAsToolTip, authenticationFailedToolTip,
- postback) {
- box.dnoi_internal = {};
+ autoPostback, postback) {
+ box.dnoi_internal = {
+ postback: postback
+ };
if (assertionReceivedCode) {
box.dnoi_internal.onauthenticated = function(sender, e) { eval(assertionReceivedCode); };
}
@@ -50,6 +53,21 @@ function initAjaxOpenId(box, openid_logo_url, dotnetopenid_logo_url, spinner_url
return splitButton;
};
+ box.dnoi_internal.createLoginPostBackButton = function() {
+ var postback = function() {
+ var discoveryResult = window.dnoa_internal.discoveryResults[box.value];
+ var respondingEndpoint = discoveryResult.findSuccessfulRequest();
+ box.dnoi_internal.postback(discoveryResult, respondingEndpoint, respondingEndpoint.extensionResponses, { background: false });
+ };
+ var button = box.dnoi_internal.constructButton(loginButtonText, loginPostBackToolTip, postback);
+ button.style.visibility = 'visible';
+ button.destroy = function() {
+ button.parentNode.removeChild(button);
+ };
+
+ return button;
+ };
+
box.dnoi_internal.createLoginButton = function(providers) {
var onMenuItemClick = function(p_sType, p_aArgs, p_oItem) {
var selectedProvider = (p_oItem && p_oItem.value) ? p_oItem.value : providers[0].value;
@@ -158,6 +176,10 @@ function initAjaxOpenId(box, openid_logo_url, dotnetopenid_logo_url, spinner_url
box.dnoi_internal.loginButton.destroy();
box.dnoi_internal.loginButton = null;
}
+ if (box.dnoi_internal.postbackLoginButton) {
+ box.dnoi_internal.postbackLoginButton.destroy();
+ box.dnoi_internal.postbackLoginButton = null;
+ }
box.title = '';
box.dnoi_internal.state = state;
var opLogo;
@@ -182,8 +204,12 @@ function initAjaxOpenId(box, openid_logo_url, dotnetopenid_logo_url, spinner_url
box.dnoi_internal.openid_logo.style.visibility = 'visible';
box.dnoi_internal.openid_logo.title = box.dnoi_internal.op_logo.originalTitle.replace('{0}', authenticatedBy.getHost());
}
- box.dnoi_internal.success_icon.style.visibility = 'visible';
- box.dnoi_internal.success_icon.title = box.dnoi_internal.success_icon.originalTitle.replace('{0}', authenticatedAs);
+ if (showLoginPostBackButton) {
+ box.dnoi_internal.postbackLoginButton = box.dnoi_internal.createLoginPostBackButton();
+ } else {
+ box.dnoi_internal.success_icon.style.visibility = 'visible';
+ box.dnoi_internal.success_icon.title = box.dnoi_internal.success_icon.originalTitle.replace('{0}', authenticatedAs);
+ }
box.title = box.dnoi_internal.claimedIdentifier;
window.status = "Authenticated as " + authenticatedAs;
} else if (state == "setup") {
@@ -416,7 +442,9 @@ function initAjaxOpenId(box, openid_logo_url, dotnetopenid_logo_url, spinner_url
box.dnoi_internal.onauthenticated(box, extensionResponses);
}
- if (box.dnoi_internal.submitPending) {
+ if (showLoginPostBackButton && !state.background) {
+ box.dnoi_internal.postback(discoveryResult, serviceEndpoint, extensionResponses, state);
+ } else if (box.dnoi_internal.submitPending) {
// We submit the form BEFORE resetting the submitPending so
// the submit handler knows we've already tried this route.
if (box.dnoi_internal.submitPending === true) {
@@ -426,12 +454,9 @@ function initAjaxOpenId(box, openid_logo_url, dotnetopenid_logo_url, spinner_url
}
box.dnoi_internal.submitPending = null;
- } else {
+ } else if (!state.deserialized && autoPostback) {
// as long as this is a fresh auth response, postback to the server if configured to do so.
- if (!state.deserialized) {
- // this function is a no-op if the control's AutoPostback property is set to false.
- postback();
- }
+ box.dnoi_internal.postback(discoveryResult, serviceEndpoint, extensionResponses, state);
}
}
});
diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.cs b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.cs
index eac01ac..6cdbc4f 100644
--- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.cs
+++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.cs
@@ -160,6 +160,7 @@ namespace DotNetOpenAuth.OpenId.RelyingParty {
this.textBox = new OpenIdAjaxTextBox();
this.textBox.ID = "openid_identifier";
this.textBox.HookFormSubmit = false;
+ this.textBox.ShowLogOnPostBackButton = true;
this.Controls.Add(this.textBox);
this.positiveAssertionField = new HiddenField();
diff --git a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.js b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.js
index 6486879..41aaea6 100644
--- a/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.js
+++ b/src/DotNetOpenAuth/OpenId/RelyingParty/OpenIdSelector.js
@@ -77,17 +77,20 @@ $(function() {
var openid = new window.OpenIdIdentifier(identifier);
if (!openid) { throw 'checkidSetup called without an identifier.'; }
openid.login(function(discoveryResult, respondingEndpoint, extensionResponses) {
- doLogin(respondingEndpoint, discoveryResult);
+ doLogin(discoveryResult, respondingEndpoint);
});
}
// Sends the positive assertion we've collected to the server and actually logs the user into the RP.
- function doLogin(respondingEndpoint, discoveryResult) {
+ function doLogin(discoveryResult, respondingEndpoint) {
var retain = true; //!$('#NotMyComputer')[0].selected;
$.cookie('openid_identifier', retain ? discoveryResult.userSuppliedIdentifier : null, { path: window.aspnetapppath });
window.postLoginAssertion(respondingEndpoint.response.toString(), window.parent.location.href);
}
+ // take over how the text box does postbacks.
+ ajaxbox.dnoi_internal.postback = doLogin;
+
// This FrameManager will be used for background logins for the OP buttons
// and the last used identifier. It is NOT the frame manager used by the
// OpenIdAjaxTextBox, as it has its own.
@@ -141,7 +144,7 @@ $(function() {
// If the user clicked on a button that has the "we're ready to log you in immediately",
// then log them in!
if (respondingEndpoint) {
- doLogin(respondingEndpoint, discoveryResult);
+ doLogin(discoveryResult, respondingEndpoint);
} else if ($(this).hasClass('OPButton')) {
checkidSetup($(this)[0].id);
} else if ($(this).hasClass('infocard') && wasGrayedOut) {