private void InitScript() { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "SignInScriptOnload", Resource.signInControlScript); string template = ResourceHelper.LoadStringFromResource( Assembly.GetExecutingAssembly(), "MCS.Library.Passport.Controls.SignInControlInitScript.htm"); string script = string.Format(template, PassportWebControlHelper.GetControlValue(this.TemplateControl, "signInName", "ClientID", string.Empty), PassportWebControlHelper.GetControlValue(this.TemplateControl, "password", "ClientID", string.Empty)); Page.ClientScript.RegisterStartupScript( this.GetType(), "SignInScriptOnload", script, true); Control detailErrorMessageLink = PassportWebControlHelper.FindControlRecursively(this.TemplateControl, "detailErrorMessageLink"); if (detailErrorMessageLink != null && detailErrorMessageLink is HtmlContainerControl) { ((HtmlContainerControl)detailErrorMessageLink).Attributes["onclick"] = string.Format("return doDetailErrorMessageClick(\"{0}\");", PassportWebControlHelper.GetControlValue(this.TemplateControl, "detailErrorMessage", "ClientID", string.Empty)); } }
private void InitScript() { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "SignInScriptOnload", Resource.changePasswordScript, true); Page.ClientScript.RegisterStartupScript(this.GetType(), "ChangePasswordScriptOnload", string.Format("window.attachEvent(\"onload\", new Function(\"initControlsFocus('{0}', '{1}')\"));", PassportWebControlHelper.GetControlValue(this.TemplateControl, "signInName", "ClientID", string.Empty), PassportWebControlHelper.GetControlValue(this.TemplateControl, "oldPassword", "ClientID", string.Empty)), true); Control detailErrorMessageLink = PassportWebControlHelper.FindControlRecursively(this.TemplateControl, "detailErrorMessageLink"); if (detailErrorMessageLink != null && detailErrorMessageLink is HtmlContainerControl) { ((HtmlContainerControl)detailErrorMessageLink).Attributes["onclick"] = string.Format("doDetailErrorMessageClick(\"{0}\")", PassportWebControlHelper.GetControlValue(this.TemplateControl, "detailErrorMessage", "ClientID", string.Empty)); } this.updateButton.OnClientClick = string.Format("beforeSubmit(\"{0}\", \"{1}\", \"{2}\", \"{3}\")", PassportWebControlHelper.GetControlValue(this.TemplateControl, "signInName", "ClientID", string.Empty), PassportWebControlHelper.GetControlValue(this.TemplateControl, "errorMessage", "ClientID", string.Empty), PassportWebControlHelper.GetControlValue(this.TemplateControl, "newPassword", "ClientID", string.Empty), PassportWebControlHelper.GetControlValue(this.TemplateControl, "confirmPassword", "ClientID", string.Empty)); IAttributeAccessor backButton = (IAttributeAccessor)PassportWebControlHelper.FindControlRecursively(this.TemplateControl, "backButton"); if (backButton != null) { backButton.SetAttribute("backUrl", this.GetBackUrl()); backButton.SetAttribute("onclick", "onBackButtonClick();"); } }
private void Initialize() { this.updateButton = (Button)PassportWebControlHelper.FindControlRecursively(this.TemplateControl, "changePasswordButton"); if (this.updateButton != null) { this.updateButton.Click += new EventHandler(updateButton_Click); } if (this.Page.IsPostBack == false) { if (HttpContext.Current.User != null) { PassportWebControlHelper.SetControlValue(this.TemplateControl, "signInName", "Text", HttpContext.Current.User.Identity.Name); } } }
/// <summary> /// 判断SignInInfo状态,如果在SignInInfo合法情况下,基于Session的Cookie,或者用户选择自动登录的进行自动登录。 /// </summary> private void Initialize() { Control signInBtn = PassportWebControlHelper.FindControlRecursively(this.TemplateControl, "SignInButton"); if (signInBtn != null && signInBtn is IButtonControl) { ((IButtonControl)signInBtn).Click += new EventHandler(SignInButton_Click); } if (Page.IsPostBack == false) { //从Cookie中得到登录信息 ISignInInfo signInInfo = SignInInfo.LoadFromCookie(); if (signInInfo != null) { Trace.WriteLine(string.Format("认证服务,从cookie中得到用户{0}的认证信息", signInInfo.UserID), "PassportSDK"); } this._PageData.LoadFromCookie(); PassportSignInSettings settings = PassportSignInSettings.GetConfig(); if (IsSignInInfoInvalid(signInInfo) == false) //SignIn Info非法 { if (settings.IsSessionBased || this.PageData.AutoSignIn) { if (IsSelfAuthenticate == false) { AutoSignIn(signInInfo); //May be execute Response.End when redirect to app's url } } } if (Page.IsPostBack == false) { InitForm(this.PageData); } Page.Response.Expires = 0; } }
private void SignInButton_Click(object sender, System.EventArgs e) { try { ITicket ticket = AuthenticateUser(); RedirectToAppUrl(ticket); } catch (System.Threading.ThreadAbortException) { } catch (System.Exception ex) { System.Exception realEx = ex.GetRealException(); string strSignInName = (string)PassportWebControlHelper.GetControlValue(this.TemplateControl, "signInName", "Text", string.Empty); SignInContext signInContext = new SignInContext( SignInResultType.Fail, strSignInName, null, CollectPageData(), (string)PassportWebControlHelper.GetControlValue(this.TemplateControl, "clientEnv", "Value", string.Empty), realEx); OnSignInComplete(signInContext); PassportWebControlHelper.SetControlValue(this.TemplateControl, "errorMessage", "Text", HttpUtility.HtmlEncode(realEx.Message)); PassportWebControlHelper.SetControlValue(this.TemplateControl, "errorMessage", "ForeColor", Color.Red); PassportWebControlHelper.SetControlValue(this.TemplateControl, "detailErrorMessage", "Text", HttpUtility.HtmlEncode(ex.StackTrace)); Control detailErrorMessageLink = PassportWebControlHelper.FindControlRecursively(this.TemplateControl, "detailErrorMessageLink"); if (detailErrorMessageLink != null && detailErrorMessageLink is HtmlContainerControl) { ((HtmlContainerControl)detailErrorMessageLink).Style["display"] = "block"; } } }
private void updateButton_Click(object sender, EventArgs e) { try { string userID = PassportWebControlHelper.GetControlValue(this.TemplateControl, "signInName", "Text", string.Empty); string oldPassword = PassportWebControlHelper.GetControlValue(this.TemplateControl, "oldPassword", "Value", string.Empty); string newPassword = PassportWebControlHelper.GetControlValue(this.TemplateControl, "newPassword", "Value", string.Empty); ChangeUserPassword(userID, oldPassword, newPassword); if (AutoRedirect) { HttpContext.Current.Response.Redirect(this.ReferUrl, true); } else { if (string.IsNullOrEmpty(this.SuccessUrl) == false) { HttpContext.Current.Response.Redirect(this.SuccessUrl, true); } } } catch (System.Exception ex) { PassportWebControlHelper.SetControlValue(this.TemplateControl, "errorMessage", "Text", HttpUtility.HtmlEncode(ExceptionHelper.GetRealException(ex).Message)); PassportWebControlHelper.SetControlValue(this.TemplateControl, "errorMessage", "ForeColor", Color.Red); PassportWebControlHelper.SetControlValue(this.TemplateControl, "detailErrorMessage", "Text", HttpUtility.HtmlEncode(ex.StackTrace)); Control detailErrorMessageLink = PassportWebControlHelper.FindControlRecursively(this.TemplateControl, "detailErrorMessageLink"); if (detailErrorMessageLink != null && detailErrorMessageLink is HtmlContainerControl) { ((HtmlContainerControl)detailErrorMessageLink).Style["display"] = "block"; } } }