/// <summary> /// Handles the Click event of the SendEmail control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void SendEmail_Click([NotNull] object sender, [NotNull] EventArgs e) { if (this.EmailAddress.Text.Length == 0) { this.PageContext.AddLoadMessage(this.GetText("need_email"), MessageTypes.warning); return; } try { var emailTopic = new TemplateEmail("EMAILTOPIC") { TemplateParams = { ["{message}"] = this.Message.Text.Trim() } }; // send a change email message... emailTopic.SendEmail(new MailAddress(this.EmailAddress.Text.Trim()), this.Subject.Text.Trim()); BuildLink.Redirect(ForumPages.posts, "t={0}", this.PageContext.PageTopicID); } catch (Exception x) { this.Logger.Log(this.PageContext.PageUserID, this, x); this.PageContext.AddLoadMessage(this.GetTextFormatted("failed", x.Message), MessageTypes.danger); } }
/// <summary> /// Handles the SendingMail event of the PasswordRecovery1 control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="MailMessageEventArgs"/> instance containing the event data.</param> protected void PasswordRecovery1_SendingMail([NotNull] object sender, [NotNull] MailMessageEventArgs e) { // get the username and password from the body var body = e.Message.Body; // remove first line... body = body.Remove(0, body.IndexOf('\n') + 1); // remove "Username: "******": ", StringComparison.Ordinal) + 2); // get first line which is the username var userName = body.Substring(0, body.IndexOf('\n')); // delete that same line... body = body.Remove(0, body.IndexOf('\n') + 1); // remove the "Password: "******": ", StringComparison.Ordinal) + 2); // the rest is the password... var password = body.Substring(0, body.IndexOf('\n')); var subject = this.GetTextFormatted("PASSWORDRETRIEVAL_EMAIL_SUBJECT", this.Get <BoardSettings>().Name); var userIpAddress = this.Get <HttpRequestBase>().GetUserRealIPAddress(); // get the e-mail ready from the real template. var passwordRetrieval = new TemplateEmail("PASSWORDRETRIEVAL") { TemplateParams = { ["{username}"] = userName, ["{password}"] = password, ["{ipaddress}"] = userIpAddress } }; passwordRetrieval.SendEmail(e.Message.To[0], subject); // log password reset attempt this.Logger.Log( userName, $"{userName} Requested a Password Reset", $"The user {userName} with the IP address: '{userIpAddress}' requested a password reset.", EventLogTypes.Information); // manually set to success... e.Cancel = true; this.PasswordRecovery1.TabIndex = 3; }
/// <summary> /// Reset the User Password /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void btnResetPassword_Click([NotNull] object sender, [NotNull] EventArgs e) { // reset password... try { var user = UserMembershipHelper.GetMembershipUserById(this.CurrentUserID.Value); if (user == null) { return; } // reset the password... user.UnlockUser(); var newPassword = user.ResetPassword(); var subject = this.GetTextFormatted( "PASSWORDRETRIEVAL_EMAIL_SUBJECT", this.Get <BoardSettings>().Name); var logoUrl = $"{BoardInfo.ForumClientFileRoot}{BoardFolders.Current.Logos}/{this.PageContext.BoardSettings.ForumLogo}"; var themeCss = $"{this.Get<BoardSettings>().BaseUrlMask}{this.Get<ITheme>().BuildThemePath("bootstrap-forum.min.css")}"; // email a notification... var passwordRetrieval = new TemplateEmail("PASSWORDRETRIEVAL_ADMIN") { TemplateParams = { ["{username}"] = user.UserName, ["{password}"] = newPassword, ["{forumname}"] = this.Get <BoardSettings>().Name, ["{forumlink}"] = BoardInfo.ForumURL, ["{themecss}"] = themeCss, ["{logo}"] = $"{this.Get<BoardSettings>().BaseUrlMask}{logoUrl}" } }; passwordRetrieval.SendEmail(new MailAddress(user.Email, user.UserName), subject); this.PageContext.AddLoadMessage( this.Get <ILocalization>().GetText("ADMIN_EDITUSER", "MSG_PASS_RESET"), MessageTypes.success); } catch (Exception x) { this.PageContext.AddLoadMessage($"Exception: {x.Message}", MessageTypes.danger); } }
/// <summary> /// Handles the Click event of the SendEmail control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void SendEmail_Click([NotNull] object sender, [NotNull] EventArgs e) { try { var emailTopic = new TemplateEmail("EMAILTOPIC") { TemplateParams = { ["{message}"] = this.Message.Text.Trim() } }; // send a change email message... emailTopic.SendEmail(new MailAddress(this.EmailAddress.Text.Trim()), this.Subject.Text.Trim()); this.Get <LinkBuilder>().Redirect( ForumPages.Posts, "t={0}&name={1}", this.PageContext.PageTopicID, this.PageContext.PageTopicName); } catch (Exception x) { this.Logger.Log(this.PageContext.PageUserID, this, x); this.PageContext.AddLoadMessage(this.GetTextFormatted("failed", x.Message), MessageTypes.danger); } }
/// <summary> /// Handles the ItemCommand event of the UserList control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.RepeaterCommandEventArgs"/> instance containing the event data.</param> public void UserListItemCommand([NotNull] object source, [NotNull] RepeaterCommandEventArgs e) { switch (e.CommandName) { case "edit": BuildLink.Redirect(ForumPages.admin_edituser, "u={0}", e.CommandArgument); break; case "resendEmail": var commandArgument = e.CommandArgument.ToString().Split(';'); var checkMail = this.GetRepository <CheckEmail>().ListTyped(commandArgument[0]).FirstOrDefault(); if (checkMail != null) { var verifyEmail = new TemplateEmail("VERIFYEMAIL"); var subject = this.Get <ILocalization>() .GetTextFormatted("VERIFICATION_EMAIL_SUBJECT", this.Get <BoardSettings>().Name); verifyEmail.TemplateParams["{link}"] = BuildLink.GetLinkNotEscaped( ForumPages.Approve, true, "k={0}", checkMail.Hash); verifyEmail.TemplateParams["{key}"] = checkMail.Hash; verifyEmail.TemplateParams["{forumname}"] = this.Get <BoardSettings>().Name; verifyEmail.TemplateParams["{forumlink}"] = BoardInfo.ForumURL; verifyEmail.SendEmail(new MailAddress(checkMail.Email, commandArgument[1]), subject); this.PageContext.AddLoadMessage( this.GetText("ADMIN_ADMIN", "MSG_MESSAGE_SEND"), MessageTypes.success); } else { var userFound = this.Get <IUserDisplayName>().Find(commandArgument[1]).FirstOrDefault(); var user = this.Get <MembershipProvider>().GetUser(userFound.Name, false); this.Get <ISendNotification>().SendVerificationEmail(user, commandArgument[0], userFound.ID); } break; case "delete": if (!Config.IsAnyPortal) { UserMembershipHelper.DeleteUser(e.CommandArgument.ToType <int>()); } this.GetRepository <User>().Delete(e.CommandArgument.ToType <int>()); this.BindData(); break; case "approve": UserMembershipHelper.ApproveUser(e.CommandArgument.ToType <int>()); this.BindData(); break; case "deleteall": // vzrus: Should not delete the whole providers portal data? Under investigation. var daysValueAll = this.PageContext.CurrentForumPage.FindControlRecursiveAs <TextBox>("DaysOld").Text.Trim(); if (!ValidationHelper.IsValidInt(daysValueAll)) { this.PageContext.AddLoadMessage( this.GetText("ADMIN_ADMIN", "MSG_VALID_DAYS"), MessageTypes.warning); return; } if (!Config.IsAnyPortal) { UserMembershipHelper.DeleteAllUnapproved(System.DateTime.UtcNow.AddDays(-daysValueAll.ToType <int>())); } else { this.GetRepository <User>().DeleteOld(this.PageContext.PageBoardID, daysValueAll.ToType <int>()); } this.BindData(); break; case "approveall": UserMembershipHelper.ApproveAll(); // vzrus: Should delete users from send email list this.GetRepository <User>().ApproveAll(this.PageContext.PageBoardID); this.BindData(); break; } }
/// <summary> /// Change the Users Password /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void btnChangePassword_Click([NotNull] object sender, [NotNull] EventArgs e) { this.Page.Validate(); if (!this.Page.IsValid) { return; } // change password... try { var user = UserMembershipHelper.GetMembershipUserById(this.CurrentUserID.Value); if (user == null) { return; } // new password... var newPass = this.txtNewPassword.Text.Trim(); // reset the password... user.UnlockUser(); var tempPass = user.ResetPassword(); // change to new password... user.ChangePassword(tempPass, newPass); if (this.chkEmailNotify.Checked) { var subject = this.GetTextFormatted( "PASSWORDRETRIEVAL_EMAIL_SUBJECT", this.Get <BoardSettings>().Name); // email a notification... var passwordRetrieval = new TemplateEmail("PASSWORDRETRIEVAL_ADMIN") { TemplateParams = { ["{username}"] = user.UserName, ["{password}"] = newPass } }; passwordRetrieval.SendEmail(new MailAddress(user.Email, user.UserName), subject); this.PageContext.AddLoadMessage( this.Get <ILocalization>().GetText("ADMIN_EDITUSER", "MSG_PASS_CHANGED_NOTI"), MessageTypes.success); } else { this.PageContext.AddLoadMessage( this.Get <ILocalization>().GetText("ADMIN_EDITUSER", "MSG_PASS_CHANGED"), MessageTypes.success); } } catch (Exception x) { this.PageContext.AddLoadMessage($"Exception: {x.Message}", MessageTypes.danger); } }
/// <summary> /// The password recovery 1_ verifying user. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> protected void PasswordRecovery1_VerifyingUser([NotNull] object sender, [NotNull] LoginCancelEventArgs e) { MembershipUser user = null; if (this.PasswordRecovery1.UserName.Contains("@") && this.Get <MembershipProvider>().RequiresUniqueEmail) { // Email Login var username = this.Get <MembershipProvider>().GetUserNameByEmail(this.PasswordRecovery1.UserName); if (username != null) { user = this.Get <MembershipProvider>().GetUser(username, false); // update the username this.PasswordRecovery1.UserName = username; } } else { // Standard user name login if (this.Get <BoardSettings>().EnableDisplayName) { // Display name login var id = this.Get <IUserDisplayName>().GetId(this.PasswordRecovery1.UserName); if (id.HasValue) { // get the username associated with this id... var username = UserMembershipHelper.GetUserNameFromID(id.Value); // update the username this.PasswordRecovery1.UserName = username; } user = this.Get <MembershipProvider>().GetUser(this.PasswordRecovery1.UserName, false); } } if (user == null) { return; } // verify the user is approved, etc... if (user.IsApproved) { return; } if (this.Get <BoardSettings>().EmailVerification) { // get the hash from the db associated with this user... var checkTyped = this.GetRepository <CheckEmail>().ListTyped(user.Email).FirstOrDefault(); if (checkTyped != null) { // re-send verification email instead of lost password... var verifyEmail = new TemplateEmail("VERIFYEMAIL"); var subject = this.GetTextFormatted( "VERIFICATION_EMAIL_SUBJECT", this.Get <BoardSettings>().Name); verifyEmail.TemplateParams["{link}"] = BuildLink.GetLinkNotEscaped( ForumPages.Approve, true, "k={0}", checkTyped.Hash); verifyEmail.TemplateParams["{key}"] = checkTyped.Hash; verifyEmail.TemplateParams["{forumname}"] = this.Get <BoardSettings>().Name; verifyEmail.TemplateParams["{forumlink}"] = $"{BoardInfo.ForumURL}"; verifyEmail.SendEmail(new MailAddress(user.Email, user.UserName), subject); this.PageContext.LoadMessage.AddSession( this.GetTextFormatted("ACCOUNT_NOT_APPROVED_VERIFICATION", user.Email), MessageTypes.warning); } } else { // explain they are not approved yet... this.PageContext.LoadMessage.AddSession(this.GetText("ACCOUNT_NOT_APPROVED"), MessageTypes.warning); } // just in case cancel the verification... e.Cancel = true; // nothing they can do here... redirect to login... BuildLink.Redirect(ForumPages.Login); }