/// <summary> /// Converts a add view model to a membershipuser /// </summary> /// <param name="viewModel"></param> /// <returns></returns> public static MembershipUser ToMembershipUser(this MemberAddViewModel viewModel) { var userToSave = new MembershipUser { UserName = viewModel.UserName, Email = viewModel.Email, Password = viewModel.Password, IsApproved = viewModel.IsApproved, Comment = viewModel.Comment }; if (viewModel.LoginType == LoginType.Facebook) { userToSave.FacebookAccessToken = viewModel.UserAccessToken; } if (viewModel.LoginType == LoginType.Google) { userToSave.GoogleAccessToken = viewModel.UserAccessToken; } if (viewModel.LoginType == LoginType.Microsoft) { userToSave.MicrosoftAccessToken = viewModel.UserAccessToken; } // Save the social url if (!string.IsNullOrWhiteSpace(viewModel.SocialProfileImageUrl)) { // Save the SocialProfileImageUrl in ExtendedData as we'll need it userToSave.SetExtendedDataValue(Constants.ExtendedDataKeys.SocialProfileImageUrl, viewModel.SocialProfileImageUrl); } // Save the return url on the user to if (!string.IsNullOrWhiteSpace(viewModel.ReturnUrl)) { userToSave.SetExtendedDataValue(Constants.ExtendedDataKeys.ReturnUrl, viewModel.ReturnUrl); } return(userToSave); }
/// <summary> /// Sends registration confirmation email /// </summary> /// <param name="userToSave">The user being created</param> /// <param name="manuallyAuthoriseMembers"></param> /// <param name="memberEmailAuthorisationNeeded"></param> public void SendEmailConfirmationEmail(MembershipUser userToSave, bool manuallyAuthoriseMembers, bool memberEmailAuthorisationNeeded) { var settings = _settingsService.GetSettings(); if (manuallyAuthoriseMembers == false && memberEmailAuthorisationNeeded == true) { if (!string.IsNullOrWhiteSpace(userToSave.Email)) { // Registration guid var registrationGuid = Guid.NewGuid().ToString(); // Set a Guid in the extended data userToSave.SetExtendedDataValue(Constants.ExtendedDataKeys.RegistrationEmailConfirmationKey, registrationGuid); // SEND AUTHORISATION EMAIL var sb = new StringBuilder(); var requestContext = HttpContext.Current.Request.RequestContext; var actionUrl = new UrlHelper(requestContext).Action("EmailConfirmation", "Members", new { id = userToSave.Id, key = registrationGuid }); var confirmationLink = string.Concat(StringUtils.ReturnCurrentDomain(), actionUrl); sb.AppendFormat("<p>{0}</p>", string.Format( _localizationService.GetResourceString("Members.MemberEmailAuthorisation.EmailBody"), settings.ForumName, string.Format("<p><a href=\"{0}\">{0}</a></p>", confirmationLink))); var email = new Email { EmailTo = userToSave.Email, NameTo = userToSave.UserName, Subject = _localizationService.GetResourceString("Members.MemberEmailAuthorisation.Subject") }; email.Body = EmailTemplate(email.NameTo, sb.ToString()); SendMail(email); // 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 var myCookie = new HttpCookie(Constants.MemberEmailConfirmationCookieName) { Value = userToSave.UserName, Expires = DateTime.Now.AddDays(7) }; // Add the cookie. HttpContext.Current.Response.Cookies.Add(myCookie); } } }