示例#1
0
    protected void CancelAccount_Click(object sender, EventArgs e)
    {
        MembershipUser currUser = Membership.GetUser();

        Database db    = Global.GetDbConnection();
        var      email = new EmailMessage(db.GetEmailTemplate(9));

        email.From = "*****@*****.**";         // Placeholder, will be replaced by Email Engine.
        email.ReplaceGeneralTokens();
        email.ApplyToUser(currUser, db.ORManager.Get <UserInformation>(currUser.ProviderUserKey));
        email.ToAddress = "*****@*****.**";
        email.ReplaceInMessage(TOKEN_CANCELLATION_REASON, AccountCancellationReason.Text);
        RtEngines.EmailEngine.SendEmail(email.GetMailMessage());

        currUser.IsApproved = false;
        Membership.UpdateUser(currUser);

        // TODO: Replace this with a better way of logging the user out if there is one.
        HttpCookie authCookie = Request.Cookies[".ASPXAUTH"];

        authCookie.Expires = DateTime.Now.AddYears(-1);
        Response.Cookies.Set(authCookie);

        redirectHome();
    }
示例#2
0
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        Database db = Global.GetDbConnection();

        // Set user's approval to false so that it is "pending"
        MembershipUser membershipUser = Membership.GetUser(CreateUserWizard1.UserName);

        membershipUser.IsApproved = false;
        Membership.UpdateUser(membershipUser);

        // Save user's extended information to the database
        var userInformation = new UserInformation();

        userInformation.UserId    = membershipUser.ProviderUserKey;
        userInformation.FirstName = ((TextBox)CreateUserWizardStep3.ContentTemplateContainer.FindControl("FirstName")).Text;
        userInformation.LastName  = ((TextBox)CreateUserWizardStep3.ContentTemplateContainer.FindControl("LastName")).Text;
        userInformation.LeadKey   = getLeadKey();
        db.ORManager.Save(userInformation);

        // Save user's agreement to the TOS
        LegalNoticeVersion termsOfService = db.GetLatestLegalNoticeVersion(GlobalSettings.SignUpTermsOfService);
        var tosAgreement = new LegalNoticeAgreement(termsOfService, membershipUser, true);

        db.SaveLegalNoticeAgreement(tosAgreement);

        // Update the user for the promotion participant if the user participated in a promotion
        int?signupPromoParticipantId = getSignupPromotionParticipantId();

        if (signupPromoParticipantId != null)
        {
            var promoParticipant = db.ORManager.Get <PromotionParticipant>(signupPromoParticipantId);

            // Make sure that the promotion participant isn't already assigned to another user
            if (promoParticipant.UserId == null)
            {
                promoParticipant.UserId = (Guid?)membershipUser.ProviderUserKey;
                db.ORManager.SaveOrUpdate(promoParticipant);
            }

            // Delete the promotion cookie
            HttpCookie cookie = Request.Cookies[COOKIE_PROMO_PARTICIPANT];
            if (cookie != null)
            {
                cookie.Expires = DateTime.Now.AddYears(-1);
                Response.SetCookie(cookie);
            }
        }

        // Save Verify User Email to email queue
        EmailTemplate emailTemplate = db.GetEmailTemplate(GlobalSettings.VerifyUserEmail);
        var           emailMessage  = new EmailMessage(emailTemplate);

        emailMessage.From = GlobalSettings.AdministrativeEmail;
        emailMessage.ApplyToUser(membershipUser, userInformation);
        db.SaveEmail(emailMessage);

        ThreadPool.QueueUserWorkItem(forceEmailEngineRun, membershipUser);

        Response.Redirect("Sign-Up-Complete.aspx");
    }
示例#3
0
    private void initTokens()
    {
        Database       db    = Global.GetDbConnection();
        MembershipUser user  = Membership.GetUser();
        var            uinfo = db.ORManager.Get <UserInformation>(user.ProviderUserKey);

        HomepageUrl.Text        = EmailMessage.TOKEN_HOMEPAGE_URL;
        HomepageUrlExample.Text = EmailMessage.ReplaceGeneralTokens(EmailMessage.TOKEN_HOMEPAGE_URL);

        HomepageLink.Text        = EmailMessage.TOKEN_HOMEPAGE_LINK;
        HomepageLinkExample.Text = EmailMessage.ReplaceGeneralTokens(EmailMessage.TOKEN_HOMEPAGE_LINK);

        Logo.Text        = EmailMessage.TOKEN_LOGO;
        LogoExample.Text = EmailMessage.ReplaceGeneralTokens(EmailMessage.TOKEN_LOGO);

        UsersUid.Text        = EmailMessage.TOKEN_USERUID;
        UsersUidExample.Text = EmailMessage.ApplyToUser(EmailMessage.TOKEN_USERUID, user, uinfo);

        UsersFirstName.Text        = EmailMessage.TOKEN_FIRSTNAME;
        UsersFirstNameExample.Text = EmailMessage.ApplyToUser(EmailMessage.TOKEN_FIRSTNAME, user, uinfo);

        UsersLastName.Text        = EmailMessage.TOKEN_LASTNAME;
        UsersLastNameExample.Text = EmailMessage.ApplyToUser(EmailMessage.TOKEN_LASTNAME, user, uinfo);

        UsersFullName.Text        = EmailMessage.TOKEN_FULLNAME;
        UsersFullNameExample.Text = EmailMessage.ApplyToUser(EmailMessage.TOKEN_FULLNAME, user, uinfo);

        UsersUsername.Text        = EmailMessage.TOKEN_USERNAME;
        UsersUsernameExample.Text = EmailMessage.ApplyToUser(EmailMessage.TOKEN_USERNAME, user, uinfo);

        UsersEmail.Text        = EmailMessage.TOKEN_EMAIL;
        UsersEmailExample.Text = EmailMessage.ApplyToUser(EmailMessage.TOKEN_EMAIL, user, uinfo);
    }
示例#4
0
        public static void EnqueueEmail(Database db, EmailTemplate template, MembershipUser user, string from)
        {
            EmailMessage msg = new EmailMessage(template);

            msg.From = from;
            msg.ApplyToUser(user, db.ORManager.Get <UserInformation>(user.ProviderUserKey));
            db.SaveEmail(msg);
        }
示例#5
0
    private static void sendPreview(EmailTemplate emailTemplate)
    {
        Database       db              = Global.GetDbConnection();
        var            emailMessage    = new EmailMessage(emailTemplate);
        MembershipUser currUser        = Membership.GetUser();
        var            userInformation = db.ORManager.Get <UserInformation>(currUser.ProviderUserKey);

        emailMessage.ApplyToUser(currUser, userInformation);
        emailMessage.From = GlobalSettings.AdministrativeEmail;

        db.SaveEmail(emailMessage);
        ThreadPool.QueueUserWorkItem(forceEmailEngineRun);
    }
示例#6
0
    protected void LookupUsername_Click(object sender, EventArgs e)
    {
        ForgotUsername_Success.Visible = false;
        ForgotUsername_UsernameLookupFailure.Visible = false;

        string username = Membership.GetUserNameByEmail(EmailAddress.Text);

        if (string.IsNullOrEmpty(username))
        {
            ForgotUsername_UsernameLookupFailure.Visible = true;
            return;
        }

        MembershipUser membershipUser = Membership.GetUser(username);

        if (membershipUser == null)
        {
            ForgotUsername_UsernameLookupFailure.Visible = true;
            return;
        }

        ForgotUsername_Success.Visible = true;

        Database db = Global.GetDbConnection();
        var      userInformation = db.ORManager.Get <UserInformation>(membershipUser.ProviderUserKey);

        // Save Verify User Email to email queue
        EmailTemplate emailTemplate = db.GetEmailTemplate(GlobalSettings.VerifyUserEmail);
        var           emailMessage  = new EmailMessage(emailTemplate);

        emailMessage.From = GlobalSettings.AdministrativeEmail;
        emailMessage.ApplyToUser(membershipUser, userInformation);
        db.SaveEmail(emailMessage);

        ThreadPool.QueueUserWorkItem(forceEmailEngineRun, membershipUser);
    }
示例#7
0
        public virtual void SendReport(int id)
        {
            ReportPartGenerator rpg         = new ReportPartGenerator(_db);
            EmailMessage        email       = new EmailMessage(_customReportTemplate);
            StringBuilder       htmlBuilder = new StringBuilder();
            Dictionary <string, MemoryStream> imageStreams = new Dictionary <string, MemoryStream>();
            int imgCounter = 0;

            CustomReport report = _db.ORManager.Get <CustomReport>(id);

            // Prepare the EmailMessage
            email.From = "*****@*****.**";                       // Placeholder - will be replaced by email engine
            email.ReplaceGeneralTokens();
            email.ApplyToUser(Membership.GetUser(report.UserId), _db.ORManager.Get <UserInformation>(report.UserId));
            email.ReplaceInMessage(TOKEN_REPORT_TITLE, report.Name);

            // Fetch the custom report components
            ICriteria componentCriteria = _db.ORManager.Session.CreateCriteria(typeof(CustomReportComponent)).Add(Expression.Eq("CustomReport.Id", id));
            IList <CustomReportComponent> components = componentCriteria.List <CustomReportComponent>();

            htmlBuilder.Append("<table class=\"ReportComponentsTable\">");

            // Add each custom report component to the custom report
            foreach (CustomReportComponent component in components)
            {
                GeneratedReportPart grp = rpg.GenerateReport(component);
                if (grp.Bytes != null)
                {
                    // Create a placeholder for the embedded image
                    string cid = string.Format("{0}{1}", CID_REPORT_IMAGE, imgCounter++);

                    // Create an embedded image tag
                    htmlBuilder.AppendFormat("<tr><td><img src=cid:{0}><br /></td></tr>", cid);

                    // Generate and save the memory stream for this embeded image
                    MemoryStream ms = new MemoryStream(grp.Bytes);
                    imageStreams.Add(cid, ms);
                }
                else
                {
                    // Append the raw HTML
                    htmlBuilder.AppendFormat("<tr><td>{0}</td></tr>", grp.Html);
                }
            }

            htmlBuilder.Append("</table>");

            // Insert report components into email message
            email.ReplaceInMessage(TOKEN_REPORT_CONTENT, htmlBuilder.ToString());
            MailMessage msg = email.GetMailMessage();

            // Create Text-Only AlternateView
            AlternateView plainView = AlternateView.CreateAlternateViewFromString("Your email client does not appear to support viewing HTML emails.  Your email client must support this in order to view this email.", Encoding.Default, "text/plain");

            msg.AlternateViews.Add(plainView);

            // Prepare new AlternateView and clear the message body
            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(msg.Body, Encoding.Default, MediaTypeNames.Text.Html);

            htmlView.TransferEncoding = TransferEncoding.SevenBit;
            msg.AlternateViews.Add(htmlView);
            msg.Body = null;

            // Embed Logo
            EmbedGifImage(htmlView, GetEmbeddedImage("RankTrend-Logo.gif"), "EmbeddedLogo");

            // Embed the images
            foreach (string key in imageStreams.Keys)
            {
                EmbedPngImage(htmlView, imageStreams[key], key);
            }

            // Send the email
            RtEngines.EmailEngine.SendEmail(msg, true);
        }