public void MemberReport(Report report) { var sb = new StringBuilder(); var email = new Email(); sb.AppendFormat("<p>{2}: <a href=\"{0}\">{1}</a></p>", string.Concat(Dialogue.Settings().ForumRootUrlWithDomain, report.Reporter.Url), report.Reporter.UserName, AppHelpers.Lang("Report.Reporter")); sb.AppendFormat("<p>{2}: <a href=\"{0}\">{1}</a></p>", string.Concat(Dialogue.Settings().ForumRootUrlWithDomain, report.ReportedMember.Url), report.ReportedMember.UserName, AppHelpers.Lang("Report.MemberReported")); sb.AppendFormat("<p>{0}:</p>", AppHelpers.Lang("Report.Reason")); sb.AppendFormat("<p>{0}</p>", report.Reason); email.EmailFrom = Dialogue.Settings().NotificationReplyEmailAddress; email.EmailTo = Dialogue.Settings().AdminEmailAddress; email.Subject = AppHelpers.Lang("Report.MemberReport"); email.NameTo = AppHelpers.Lang("Report.Admin"); email.Body = ServiceFactory.EmailService.EmailTemplate(email.NameTo, sb.ToString()); ServiceFactory.EmailService.SendMail(email); }
public ActionResult Create(CreatePrivateMessageViewModel createPrivateMessageViewModel) { if (!Settings.AllowPrivateMessages || CurrentMember.DisablePrivateMessages) { return ErrorToHomePage(Lang("Errors.GenericMessage")); } using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { if (ModelState.IsValid) { var userTo = createPrivateMessageViewModel.UserToUsername; // first check they are not trying to message themself! if (!string.Equals(userTo, CurrentMember.UserName, StringComparison.CurrentCultureIgnoreCase)) { // Map the view model to message var privateMessage = new PrivateMessage { MemberFrom = CurrentMember, MemberFromId = CurrentMember.Id, Subject = createPrivateMessageViewModel.Subject, Message = createPrivateMessageViewModel.Message, }; // now get the user its being sent to var memberTo = ServiceFactory.MemberService.Get(userTo); // check the member if (memberTo != null) { // Check in box size // First check sender var receiverCount = ServiceFactory.PrivateMessageService.GetAllReceivedByUser(memberTo.Id).Count; if (receiverCount > Settings.PrivateMessageInboxSize) { ModelState.AddModelError(string.Empty, string.Format(Lang("PM.ReceivedItemsOverCapcity"), memberTo.UserName)); } else { // Good to go send the message! privateMessage.MemberTo = memberTo; privateMessage.MemberToId = memberTo.Id; ServiceFactory.PrivateMessageService.Add(privateMessage); try { ShowMessage(new GenericMessageViewModel { Message = Lang("PM.MessageSent"), MessageType = GenericMessages.Success }); unitOfWork.Commit(); // Finally send an email to the user so they know they have a new private message // As long as they have not had notifications disabled if (memberTo.DisableEmailNotifications != true) { var email = new Email { EmailFrom = Settings.NotificationReplyEmailAddress, EmailTo = memberTo.Email, Subject = Lang("PM.NewPrivateMessageSubject"), NameTo = memberTo.UserName }; var sb = new StringBuilder(); sb.AppendFormat("<p>{0}</p>", string.Format(Lang("PM.NewPrivateMessageBody"), CurrentMember.UserName)); email.Body = ServiceFactory.EmailService.EmailTemplate(email.NameTo, sb.ToString()); ServiceFactory.EmailService.SendMail(email); } return Redirect(Urls.GenerateUrl(Urls.UrlType.MessageInbox)); } catch (Exception ex) { unitOfWork.Rollback(); LogError(ex); ModelState.AddModelError(string.Empty, Lang("Errors.GenericMessage")); } } } else { // Error send back to user ModelState.AddModelError(string.Empty, Lang("PM.UnableFindMember")); } } else { ModelState.AddModelError(string.Empty, Lang("PM.TalkToSelf")); } } ShowModelErrors(); return Redirect(Urls.GenerateUrl(Urls.UrlType.MessageCreate)); } }
private void SendEmailConfirmationEmail(IMember userToSave) { var manuallyAuthoriseMembers = Settings.ManuallyAuthoriseNewMembers; var memberEmailAuthorisationNeeded = Settings.NewMembersMustConfirmAccountsViaEmail; if (manuallyAuthoriseMembers == false && memberEmailAuthorisationNeeded) { if (!string.IsNullOrEmpty(userToSave.Email)) { // SEND AUTHORISATION EMAIL var sb = new StringBuilder(); var confirmationLink = string.Concat(AppHelpers.ReturnCurrentDomain(), Urls.GenerateUrl(Urls.UrlType.EmailConfirmation), "?id=", userToSave.Id); sb.AppendFormat("<p>{0}</p>", string.Format(Lang("Members.MemberEmailAuthorisation.EmailBody"), Settings.ForumName, string.Format("<p><a href=\"{0}\">{0}</a></p>", confirmationLink))); var email = new Email { EmailFrom = Settings.NotificationReplyEmailAddress, EmailTo = userToSave.Email, NameTo = userToSave.Username, Subject = Lang("Members.MemberEmailAuthorisation.Subject") }; email.Body = ServiceFactory.EmailService.EmailTemplate(email.NameTo, sb.ToString()); ServiceFactory.EmailService.SendMail(email); // ADD COOKIE // We add a cookie for 7 days, which will display the resend email confirmation button // This cookie is removed when they click the confirmation link and they are logged in var myCookie = new HttpCookie(AppConstants.MemberEmailConfirmationCookieName) { Value = string.Format("{0}#{1}", userToSave.Id, userToSave.Username), Expires = DateTime.Now.AddDays(7) }; // Add the cookie. Response.Cookies.Add(myCookie); } } }
public ActionResult MemberRegisterLogic(RegisterViewModel userModel) { var forumReturnUrl = Settings.ForumRootUrl; var newMemberGroup = Settings.Group; if (userModel.ForumId != null && userModel.ForumId != Settings.ForumId) { var correctForum = Dialogue.Settings((int)userModel.ForumId); forumReturnUrl = correctForum.ForumRootUrl; newMemberGroup = correctForum.Group; } using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork()) { // Secondly see if the email is banned if (ServiceFactory.BannedEmailService.EmailIsBanned(userModel.Email)) { ModelState.AddModelError(string.Empty, Lang("Error.EmailIsBanned")); if (userModel.LoginType != LoginType.Standard) { ShowModelErrors(); return Redirect(Settings.RegisterUrl); } return CurrentUmbracoPage(); } var userToSave = AppHelpers.UmbMemberHelper().CreateRegistrationModel(AppConstants.MemberTypeAlias); userToSave.Username = ServiceFactory.BannedWordService.SanitiseBannedWords(userModel.UserName); userToSave.Name = userToSave.Username; userToSave.UsernameIsEmail = false; userToSave.Email = userModel.Email; userToSave.Password = userModel.Password; var homeRedirect = false; MembershipCreateStatus createStatus; AppHelpers.UmbMemberHelper().RegisterMember(userToSave, out createStatus, false); if (createStatus != MembershipCreateStatus.Success) { ModelState.AddModelError(string.Empty, ServiceFactory.MemberService.ErrorCodeToString(createStatus)); } else { // Get the umbraco member var umbracoMember = AppHelpers.UmbServices().MemberService.GetByUsername(userToSave.Username); // Set the role/group they should be in AppHelpers.UmbServices().MemberService.AssignRole(umbracoMember.Id, newMemberGroup.Name); // See if this is a social login and we have their profile pic if (!string.IsNullOrEmpty(userModel.SocialProfileImageUrl)) { // We have an image url - Need to save it to their profile var image = AppHelpers.GetImageFromExternalUrl(userModel.SocialProfileImageUrl); // Upload folder path for member var uploadFolderPath = AppHelpers.GetMemberUploadPath(umbracoMember.Id); // Upload the file var uploadResult = AppHelpers.UploadFile(image, uploadFolderPath); // Don't throw error if problem saving avatar, just don't save it. if (uploadResult.UploadSuccessful) { umbracoMember.Properties[AppConstants.PropMemberAvatar].Value = string.Concat(VirtualPathUtility.ToAbsolute(AppConstants.UploadFolderPath), umbracoMember.Id, "/", uploadResult.UploadedFileName); } } // Now check settings, see if users need to be manually authorised // OR Does the user need to confirm their email var manuallyAuthoriseMembers = Settings.ManuallyAuthoriseNewMembers; var memberEmailAuthorisationNeeded = Settings.NewMembersMustConfirmAccountsViaEmail; if (manuallyAuthoriseMembers || memberEmailAuthorisationNeeded) { umbracoMember.IsApproved = false; } // Store access token for social media account in case we want to do anything with it if (userModel.LoginType == LoginType.Facebook) { umbracoMember.Properties[AppConstants.PropMemberFacebookAccessToken].Value = userModel.UserAccessToken; } if (userModel.LoginType == LoginType.Google) { umbracoMember.Properties[AppConstants.PropMemberGoogleAccessToken].Value = userModel.UserAccessToken; } // Do a save on the member AppHelpers.UmbServices().MemberService.Save(umbracoMember); if (Settings.EmailAdminOnNewMemberSignup) { var sb = new StringBuilder(); sb.AppendFormat("<p>{0}</p>", string.Format(Lang("Members.NewMemberRegistered"), Settings.ForumName, Settings.ForumRootUrl)); sb.AppendFormat("<p>{0} - {1}</p>", userToSave.Username, userToSave.Email); var email = new Email { EmailTo = Settings.AdminEmailAddress, EmailFrom = Settings.NotificationReplyEmailAddress, NameTo = Lang("Members.Admin"), Subject = Lang("Members.NewMemberSubject") }; email.Body = ServiceFactory.EmailService.EmailTemplate(email.NameTo, sb.ToString()); ServiceFactory.EmailService.SendMail(email); } // Fire the activity Service ServiceFactory.ActivityService.MemberJoined(MemberMapper.MapMember(umbracoMember)); var userMessage = new GenericMessageViewModel(); // Set the view bag message here if (manuallyAuthoriseMembers) { userMessage.Message = Lang("Members.NowRegisteredNeedApproval"); userMessage.MessageType = GenericMessages.Success; } else if (memberEmailAuthorisationNeeded) { userMessage.Message = Lang("Members.MemberEmailAuthorisationNeeded"); userMessage.MessageType = GenericMessages.Success; } else { // If not manually authorise then log the user in FormsAuthentication.SetAuthCookie(userToSave.Username, true); userMessage.Message = Lang("Members.NowRegistered"); userMessage.MessageType = GenericMessages.Success; } //Show the message ShowMessage(userMessage); if (!manuallyAuthoriseMembers && !memberEmailAuthorisationNeeded) { homeRedirect = true; } try { unitOfWork.Commit(); // Only send the email if the admin is not manually authorising emails or it's pointless SendEmailConfirmationEmail(umbracoMember); if (homeRedirect && !string.IsNullOrEmpty(forumReturnUrl)) { if (Url.IsLocalUrl(userModel.ReturnUrl) && userModel.ReturnUrl.Length > 1 && userModel.ReturnUrl.StartsWith("/") && !userModel.ReturnUrl.StartsWith("//") && !userModel.ReturnUrl.StartsWith("/\\")) { return Redirect(userModel.ReturnUrl); } return Redirect(forumReturnUrl); } } catch (Exception ex) { unitOfWork.Rollback(); LogError("Eror during member registering", ex); FormsAuthentication.SignOut(); ModelState.AddModelError(string.Empty, ex.Message); } } if (userModel.LoginType != LoginType.Standard) { ShowModelErrors(); return Redirect(Settings.RegisterUrl); } return CurrentUmbracoPage(); } }
public ActionResult ForgotPassword(ForgotPasswordViewModel model) { var changePasswordSucceeded = true; var currentUser = new Member(); var newPassword = AppHelpers.RandomString(8); try { if (ModelState.IsValid) { currentUser = ServiceFactory.MemberService.GetByEmail(model.EmailAddress); if (currentUser != null) { changePasswordSucceeded = ServiceFactory.MemberService.ResetPassword(currentUser, newPassword); } else { changePasswordSucceeded = false; } } } catch (Exception ex) { LogError(string.Format("Error resetting password for {0}", model.EmailAddress), ex); changePasswordSucceeded = false; } if (changePasswordSucceeded) { var sb = new StringBuilder(); sb.AppendFormat("<p>{0}</p>", string.Format(Lang("Members.ForgotPassword.Email"), Settings.ForumName)); sb.AppendFormat("<p><b>{0}</b></p>", newPassword); var email = new Email { EmailFrom = Settings.NotificationReplyEmailAddress, EmailTo = currentUser.Email, NameTo = currentUser.UserName, Subject = Lang("Members.ForgotPassword.Subject") }; email.Body = ServiceFactory.EmailService.EmailTemplate(email.NameTo, sb.ToString()); ServiceFactory.EmailService.SendMail(email); // We use temp data because we are doing a redirect ShowMessage(new GenericMessageViewModel { Message = Lang("Members.ForgotPassword.SuccessMessage"), MessageType = GenericMessages.Success }); return CurrentUmbracoPage(); } ModelState.AddModelError("", Lang("Members.ForgotPassword.ErrorMessage")); // Hack to show form validation ShowModelErrors(); return CurrentUmbracoPage(); }
/// <summary> /// Send a single email /// </summary> /// <param name="email"></param> public void SendMail(Email email) { SendMail(new List<Email> { email }); }