//Send the user password to the user email //If link button was removed from the page this method has empty content. private void SendPasswordToUser(bool usecaptcha) { //if there is a user identity table, with an email address field, //then send the user name and password to the user email if (usecaptcha) { if (!(this.Page.IsValid)) { Exception exc = new Exception(this.recaptcha.ErrorMessage); throw exc; } } // The email address is required by validation string uemail = this.Emailaddress.Text; // lookup the email address in the user identity table and abort if not present IUserIdentityRecord userRecord = SystemUtils.GetUserInfoEmailAddr(uemail); if (userRecord == null) { string msg = GetResourceValue("Msg:InvalidEmail") + "<br />"; Exception exc = new Exception(msg); throw exc; } // send the login info to the user email BaseClasses.Utils.MailSenderInThread email = new BaseClasses.Utils.MailSenderInThread(); email.AddTo(uemail); // use the from email address in the smtp section of the web.config, if available string fromadr = uemail; object obj = System.Web.Configuration.WebConfigurationManager.GetSection("system.net/mailSettings/smtp"); if (obj != null) { System.Net.Configuration.SmtpSection smtpcfg = null; smtpcfg = (System.Net.Configuration.SmtpSection)obj; fromadr = smtpcfg.From; } email.AddFrom(fromadr); email.SetSubject(GetResourceValue("Txt:GetSignin")); // Be sure the URL is processed for substitution and encryption string uarg = ((BaseApplicationPage)this.Page).Encrypt(uemail, false); string cultarg = System.Threading.Thread.CurrentThread.CurrentUICulture.Name; if (!(string.IsNullOrEmpty(cultarg))) { cultarg = System.Web.HttpUtility.UrlEncode(cultarg); cultarg = BaseClasses.Web.UI.BasePage.APPLICATION_CULTURE_UI_URL_PARAM + "=" + cultarg; } string SendEmailContentURL = null; string pgUrl = BaseClasses.Configuration.ApplicationSettings.Current.SendUserInfoEmailUrl; if (pgUrl.StartsWith("/")) { pgUrl = pgUrl.Substring(1); } SendEmailContentURL = pgUrl + "?Email=" + System.Web.HttpUtility.UrlEncode(uarg); if (!(string.IsNullOrEmpty(cultarg))) { SendEmailContentURL += "&" + cultarg; } email.AreImagesEmbedded = true; email.RemoveJS = true; email.SetIsHtmlContent(true); email.SetContentURL(SendEmailContentURL, this); try { email.SendMessage(); } catch (Exception ex) { string msg = GetResourceValue("Msg:SendToFailed") + " " + uemail + "<br />" + ex.Message; Exception exc = new Exception(msg); throw exc; } this.ForgotUserInfoLabel.Visible = true; this.ForgotUserInfoLabel.Text = GetResourceValue("Msg:PwdEmailed") + " " + uemail; this.ForgotUserErrorLabel.Text = ""; this.ForgotUserErrorLabel.Visible = false; this.EnterEmailLabel.Visible = false; this.Emailaddress.Visible = false; this.FillRecaptchaLabel.Visible = false; this.recaptcha.SkipRecaptcha = true; this.recaptcha.Visible = false; this.SendButton.Visible = false; }
// Initialize the email field from a Username argument public void InitializeEmail() { if (this.IsPostBack) { return; } //if there is a captcha control, then check that keys have been configured. string keyinit = "Enter"; if (recaptcha.PrivateKey.StartsWith(keyinit) || recaptcha.PublicKey.StartsWith(keyinit)) { this.FillRecaptchaLabel.Text = "You must configure the reCaptcha control with your key values before you use it."; // find any recaptcha_response_holder and make it invisible object pnlRecaptcha = this.FindControlRecursively("recaptcha_response_holder"); if (pnlRecaptcha != null) { ((System.Web.UI.Control)pnlRecaptcha).Visible = false; } } //get the user name and error message from any arguments string uname = ((BaseApplicationPage)this.Page).Decrypt(this.Request.QueryString["Username"]); string uerror = this.Request.QueryString["Error"]; string emailarg = this.Request.QueryString["Email"]; this.Emailaddress.Text = ""; // if there is a user name given, start with any email address for it. string uemail = ""; if (!(string.IsNullOrEmpty(emailarg))) { // initialize the email address with the value in the argument uemail = emailarg; if (!(string.IsNullOrEmpty(uemail))) { this.Emailaddress.Text = uemail; } } else if (!(string.IsNullOrEmpty(uname))) { // get the user record from the DB IUserIdentityRecord rec = null; try { rec = SystemUtils.GetUserInfoNoPassword(uname, null); } catch { rec = null; } if (rec != null) { // then initialize the email address with the value in the record uemail = rec.GetUserEmail(); if (!(string.IsNullOrEmpty(uemail))) { this.Emailaddress.Text = uemail; } } } if (!(string.IsNullOrEmpty(uerror))) { this.ForgotUserInfoLabel.Visible = false; this.ForgotUserErrorLabel.Visible = true; this.ForgotUserErrorLabel.Text = uerror; } else { this.ForgotUserErrorLabel.Text = ""; this.ForgotUserInfoLabel.Visible = true; this.ForgotUserErrorLabel.Visible = false; } }