public void SendPackageOwnerRequest(User fromUser, User toUser, PackageRegistration package, string confirmationUrl, string message)
        {
            if (!toUser.EmailAllowed)
            {
                return;
            }

            const string subject = "[{0}] The user '{1}' wants to add you as an owner of the package '{2}'.";

            string body = string.Format(CultureInfo.CurrentCulture, $@"The user '{fromUser.Username}' wants to add you as an owner of the package '{package.Id}'.
If you do not want to be listed as an owner of this package, simply delete this email.

To accept this request and become a listed owner of the package, click the following URL:

[{confirmationUrl}]({confirmationUrl})");


            if (!string.IsNullOrWhiteSpace(message))
            {
                body += Environment.NewLine + Environment.NewLine + string.Format(CultureInfo.CurrentCulture, $@"The user '{fromUser.Username}' added the following message for you:

'{message}'");
            }

            body += Environment.NewLine + Environment.NewLine + $@"Thanks,
The {Config.GalleryOwner.DisplayName} Team";

            using (var mailMessage = new MailMessage())
            {
                mailMessage.Subject = String.Format(CultureInfo.CurrentCulture, subject, Config.GalleryOwner.DisplayName, fromUser.Username, package.Id);
                mailMessage.Body    = body;
                mailMessage.From    = Config.GalleryNoReplyAddress;
                mailMessage.ReplyToList.Add(fromUser.ToMailAddress());

                mailMessage.To.Add(toUser.ToMailAddress());
                SendMessage(mailMessage);
            }
        }
            public void UsesTypeCaptionToDescribeCredentialIfNoProviderNounPresent()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", Username = "******"
                };
                var cred           = new CredentialBuilder().CreatePasswordCredential("bogus");
                var messageService = new TestableMessageService();

                messageService.MockAuthService
                .Setup(a => a.DescribeCredential(cred))
                .Returns(new CredentialViewModel()
                {
                    TypeCaption = "Password"
                });

                messageService.SendCredentialRemovedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal("[Joe Shmoe] Password removed from your account", message.Subject);
                Assert.Contains("A Password was removed from your account", message.Body);
            }
            public void UsesProviderNounToDescribeCredentialIfPresent()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", Username = "******"
                };
                var cred           = CredentialBuilder.CreateExternalCredential("MicrosoftAccount", "abc123", "Test User");
                var messageService = new TestableMessageService();

                messageService.MockAuthService
                .Setup(a => a.DescribeCredential(cred))
                .Returns(new CredentialViewModel()
                {
                    AuthUI = new AuthenticatorUI("sign in", "Microsoft Account", "Microsoft Account")
                });

                messageService.SendCredentialAddedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal("[Joe Shmoe] Microsoft Account added to your account", message.Subject);
                Assert.Contains("A Microsoft Account was added to your account", message.Body);
            }
Example #4
0
            public void UsesTypeCaptionToDescribeCredentialIfNoProviderNounPresent()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", Username = "******"
                };
                var cred           = new CredentialBuilder().CreatePasswordCredential("bogus");
                var messageService = new TestableMessageService();

                messageService.MockAuthService
                .Setup(a => a.DescribeCredential(cred))
                .Returns(new CredentialViewModel
                {
                    TypeCaption = "Password"
                });

                messageService.SendCredentialAddedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal(string.Format(Strings.Emails_CredentialAdded_Subject, TestGalleryOwner.DisplayName, Strings.CredentialType_Password), message.Subject);
                Assert.Contains(string.Format(Strings.Emails_CredentialAdded_Body, Strings.CredentialType_Password), message.Body);
            }
Example #5
0
        public void SendOrganizationMembershipRequestRejectedNotice(Organization organization, User pendingUser)
        {
            string subject = $"[{Config.GalleryOwner.DisplayName}] Membership request for organization '{organization.Username}' declined";

            string body = string.Format(CultureInfo.CurrentCulture, $@"The user '{pendingUser.Username}' has declined your request to become a member of your organization.

Thanks,
The {Config.GalleryOwner.DisplayName} Team");

            using (var mailMessage = new MailMessage())
            {
                mailMessage.Subject = subject;
                mailMessage.Body    = body;
                mailMessage.From    = Config.GalleryNoReplyAddress;
                mailMessage.ReplyToList.Add(pendingUser.ToMailAddress());

                if (!AddAddressesForAccountManagementToEmail(mailMessage, organization))
                {
                    return;
                }

                SendMessage(mailMessage);
            }
        }
Example #6
0
        public void SendPackageOwnerRemovedNotice(User fromUser, User toUser, PackageRegistration package)
        {
            var subject = $"[{Config.GalleryOwner.DisplayName}] Package ownership removal for '{package.Id}'";

            var body = $@"The user '{fromUser.Username}' removed {(toUser is Organization ? "your organization" : "you")} as an owner of the package '{package.Id}'.

Thanks,
The {Config.GalleryOwner.DisplayName} Team";

            using (var mailMessage = new MailMessage())
            {
                mailMessage.Subject = subject;
                mailMessage.Body    = body;
                mailMessage.From    = Config.GalleryNoReplyAddress;
                mailMessage.ReplyToList.Add(fromUser.ToMailAddress());

                if (!AddAddressesForPackageOwnershipManagementToEmail(mailMessage, toUser))
                {
                    return;
                }

                SendMessage(mailMessage);
            }
        }
Example #7
0
        public void SendPackageOwnerRequestCancellationNotice(User requestingOwner, User newOwner, PackageRegistration package)
        {
            var subject = string.Format(CultureInfo.CurrentCulture, $"[{Config.GalleryOwner.DisplayName}] Package ownership request for '{package.Id}' cancelled");

            var body = string.Format(CultureInfo.CurrentCulture, $@"The user '{requestingOwner.Username}' has cancelled their request for {(newOwner is Organization ? "your organization" : "you")} to be added as an owner of the package '{package.Id}'.

Thanks,
The {Config.GalleryOwner.DisplayName} Team");

            using (var mailMessage = new MailMessage())
            {
                mailMessage.Subject = subject;
                mailMessage.Body    = body;
                mailMessage.From    = Config.GalleryNoReplyAddress;
                mailMessage.ReplyToList.Add(requestingOwner.ToMailAddress());

                if (!AddAddressesForPackageOwnershipManagementToEmail(mailMessage, newOwner))
                {
                    return;
                }

                SendMessage(mailMessage);
            }
        }
Example #8
0
        public void SendNewAccountEmail(User newUser, string confirmationUrl)
        {
            var isOrganization = newUser is Organization;

            string body = $@"Thank you for {(isOrganization ? $"creating an organization on the" : $"registering with the")} {Config.GalleryOwner.DisplayName}.
We can't wait to see what packages you'll upload.

So we can be sure to contact you, please verify your email address and click the following link:

[{HttpUtility.UrlDecode(confirmationUrl).Replace("_", "\\_")}]({confirmationUrl})

Thanks,
The {Config.GalleryOwner.DisplayName} Team";

            using (var mailMessage = new MailMessage())
            {
                mailMessage.Subject = String.Format(CultureInfo.CurrentCulture, "[{0}] Please verify your account", Config.GalleryOwner.DisplayName);
                mailMessage.Body    = body;
                mailMessage.From    = Config.GalleryNoReplyAddress;

                mailMessage.To.Add(newUser.ToMailAddress());
                SendMessage(mailMessage);
            }
        }
Example #9
0
            public void UsesProviderNounToDescribeCredentialIfPresent()
            {
                var user = new User {
                    EmailAddress = "*****@*****.**", Username = "******"
                };
                var          cred = new CredentialBuilder().CreateExternalCredential("MicrosoftAccount", "abc123", "Test User");
                const string MicrosoftAccountCredentialName = "Microsoft Account";
                var          messageService = new TestableMessageService();

                messageService.MockAuthService
                .Setup(a => a.DescribeCredential(cred))
                .Returns(new CredentialViewModel
                {
                    AuthUI = new AuthenticatorUI("sign in", "register", MicrosoftAccountCredentialName)
                });

                messageService.SendCredentialRemovedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal(string.Format(Strings.Emails_CredentialRemoved_Subject, TestGalleryOwner.DisplayName, MicrosoftAccountCredentialName), message.Subject);
                Assert.Contains(string.Format(Strings.Emails_CredentialRemoved_Body, MicrosoftAccountCredentialName), message.Body);
            }
Example #10
0
        public void SendPasswordResetInstructions(User user, string resetPasswordUrl, bool forgotPassword)
        {
            string body = String.Format(
                CultureInfo.CurrentCulture,
                forgotPassword ? Strings.Emails_ForgotPassword_Body : Strings.Emails_SetPassword_Body,
                Constants.DefaultPasswordResetTokenExpirationHours,
                resetPasswordUrl,
                Config.GalleryOwner.DisplayName);

            string subject = String.Format(CultureInfo.CurrentCulture, forgotPassword ? Strings.Emails_ForgotPassword_Subject : Strings.Emails_SetPassword_Subject, Config.GalleryOwner.DisplayName);
            using (var mailMessage = new MailMessage())
            {
                mailMessage.Subject = subject;
                mailMessage.Body = body;
                mailMessage.From = Config.GalleryOwner;

                mailMessage.To.Add(user.ToMailAddress());
                SendMessage(mailMessage);
            }
        }
Example #11
0
        private void SendSupportMessage(User user, string body, string subject)
        {
            using (var mailMessage = new MailMessage())
            {
                mailMessage.Subject = subject;
                mailMessage.Body = body;
                mailMessage.From = Config.GalleryOwner;

                mailMessage.To.Add(user.ToMailAddress());
                SendMessage(mailMessage);
            }
        }
Example #12
0
        public MailMessage SendPasswordResetInstructions(User user, string resetPasswordUrl)
        {
            string body = @"The word on the street is you lost your password. Sorry to hear it!
If you haven't forgotten your password you can safely ignore this email. Your password has not been changed.

Click the following link within the next {0} hours to reset your password:

[{1}]({1})

Thanks,
The {2} Team";

            body = String.Format(body,
                Const.DefaultPasswordResetTokenExpirationHours,
                resetPasswordUrl,
                settings.GalleryOwnerName);

            using (
                var mailMessage = new MailMessage
                {
                    Subject = String.Format("[{0}] Please reset your password.", settings.GalleryOwnerName),
                    Body = body,
                    From = new MailAddress(settings.GalleryOwnerEmail, settings.GalleryOwnerName),
                })
            {
                mailMessage.To.Add(user.ToMailAddress());
                SendMessage(mailMessage);
                return mailMessage;
            }
        }
        public void SendPackageOwnerRequest(User fromUser, User toUser, PackageRegistration package, string confirmationUrl)
        {
            if (!toUser.EmailAllowed) return;

            string subject = "[{0}] The user '{1}' wants to add you as a maintainer of the package '{2}'.";

            string body = @"The user '{0}' wants to add you as a maintainer of the package '{1}'. 
If you do not want to be listed as a maintainer of this package, simply delete this email.

To accept this request and become a listed maintainer of the package, click the following URL:

{2}

Thanks,
The {3} Team";

            body = String.Format(
                CultureInfo.CurrentCulture, body, fromUser.Username, package.Id, confirmationUrl, settings.GalleryOwnerName);

            using (var mailMessage = new MailMessage())
            {
                mailMessage.Subject = String.Format(
                    CultureInfo.CurrentCulture, subject, settings.GalleryOwnerName, fromUser.Username, package.Id);
                mailMessage.Body = body;
                mailMessage.From = fromUser.ToMailAddress();

                mailMessage.To.Add(toUser.ToMailAddress());
                SendMessage(mailMessage);
            }
        }
Example #14
0
        private void SendSupportMessage(User user, string body, string subject)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            using (var mailMessage = new MailMessage())
            {
                mailMessage.Subject = subject;
                mailMessage.Body = body;
                mailMessage.From = Config.GalleryOwner;

                mailMessage.To.Add(user.ToMailAddress());
                SendMessage(mailMessage);
            }
        }
            public void UsesTypeCaptionToDescribeCredentialIfNoProviderNounPresent()
            {
                var user = new User { EmailAddress = "*****@*****.**", Username = "******" };
                var cred = CredentialBuilder.CreatePbkdf2Password("bogus");
                var messageService = new TestableMessageService();
                messageService.MockAuthService
                    .Setup(a => a.DescribeCredential(cred))
                    .Returns(new CredentialViewModel() {
                        TypeCaption = "Password"
                    });

                messageService.SendCredentialAddedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal("[Joe Shmoe] Password added to your account", message.Subject);
                Assert.Contains("A Password was added to your account", message.Body);
            }
            public void UsesProviderNounToDescribeCredentialIfPresent()
            {
                var user = new User { EmailAddress = "*****@*****.**", Username = "******" };
                var cred = CredentialBuilder.CreateExternalCredential("MicrosoftAccount", "abc123", "Test User");
                var messageService = new TestableMessageService();
                messageService.MockAuthService
                    .Setup(a => a.DescribeCredential(cred))
                    .Returns(new CredentialViewModel() {
                        AuthUI = new AuthenticatorUI("sign in", "Microsoft Account", "Microsoft Account")
                    });

                messageService.SendCredentialAddedNotice(user, cred);
                var message = messageService.MockMailSender.Sent.Last();

                Assert.Equal(user.ToMailAddress(), message.To[0]);
                Assert.Equal(TestGalleryOwner, message.From);
                Assert.Equal("[Joe Shmoe] Microsoft Account added to your account", message.Subject);
                Assert.Contains("A Microsoft Account was added to your account", message.Body);
            }
Example #17
0
        public MailMessage SendPackageOwnerRequest(User fromUser, User toUser, PackageRegistration package, string confirmationUrl)
        {
            if (!toUser.EmailAllowed)
            {
                return null;
            }

            string subject = "[{0}] The user '{1}' wants to add you as an owner of the package '{2}'.";

            string body = @"The user '{0}' wants to add you as an owner of the package '{1}'. 
If you do not want to be listed as an owner of this package, simply delete this email.

To accept this request and become a listed owner of the package, click the following URL:

[{2}]({2})

Thanks,
The {3} Team";

            body = String.Format(body, fromUser.Username, package.Id, confirmationUrl, settings.GalleryOwnerName);

            using (
                var mailMessage = new MailMessage
                {
                    Subject = String.Format(subject, settings.GalleryOwnerName, fromUser.Username, package.Id),
                    Body = body,
                    From = fromUser.ToMailAddress(),
                })
            {
                mailMessage.To.Add(toUser.ToMailAddress());
                SendMessage(mailMessage);
                return mailMessage;
            }
        }
        public void SendPasswordResetInstructions(User user, string resetPasswordUrl)
        {
            string body = @"The word on the street is you lost your password. Sorry to hear it!
If you haven't forgotten your password you can safely ignore this email. Your password has not been changed.

Click the following link within the next {0} hours to reset your password:

{1}

Thanks,
The {2} Team";

            body = String.Format(
                CultureInfo.CurrentCulture,
                body,
                Constants.DefaultPasswordResetTokenExpirationHours,
                resetPasswordUrl,
                settings.GalleryOwnerName);

            string subject = String.Format(
                CultureInfo.CurrentCulture, "[{0}] Please reset your password.", settings.GalleryOwnerName);
            using (var mailMessage = new MailMessage())
            {
                mailMessage.Subject = subject;
                mailMessage.Body = body;
                mailMessage.From = new MailAddress(settings.GalleryOwnerEmail, settings.GalleryOwnerName);

                mailMessage.To.Add(user.ToMailAddress());
                SendMessage(mailMessage);
            }
        }
Example #19
0
        public void SendPackageOwnerRequest(User fromUser, User toUser, PackageRegistration package, string confirmationUrl, string message)
        {
            if (!toUser.EmailAllowed)
            {
                return;
            }

            const string subject = "[{0}] The user '{1}' wants to add you as an owner of the package '{2}'.";

            string body = string.Format(CultureInfo.CurrentCulture, $@"The user '{fromUser.Username}' wants to add you as an owner of the package '{package.Id}'.
If you do not want to be listed as an owner of this package, simply delete this email.

To accept this request and become a listed owner of the package, click the following URL:

[{confirmationUrl}]({confirmationUrl})");


            if (!string.IsNullOrWhiteSpace(message))
            {
                body += Environment.NewLine + Environment.NewLine + string.Format(CultureInfo.CurrentCulture, $@"The user '{fromUser.Username}' added the following message for you:

'{message}'");
            }

            body += Environment.NewLine + Environment.NewLine + $@"Thanks,
The {Config.GalleryOwner.DisplayName} Team";

            using (var mailMessage = new MailMessage())
            {
                mailMessage.Subject = String.Format(CultureInfo.CurrentCulture, subject, Config.GalleryOwner.DisplayName, fromUser.Username, package.Id);
                mailMessage.Body = body;
                mailMessage.From = Config.GalleryNoReplyAddress;
                mailMessage.ReplyToList.Add(fromUser.ToMailAddress());

                mailMessage.To.Add(toUser.ToMailAddress());
                SendMessage(mailMessage);
            }
        }
        public void SendPackageOwnerConfirmation(User fromUser, User toUser, PackageRegistration package)
        {
            if (!toUser.EmailAllowed) return;
            var packageUrl = string.Format(
                "{0}packages/{1}", EnsureTrailingSlash(Configuration.ReadAppSettings("SiteRoot")), package.Id);

            string subject = "[{0}] The user '{1}' has added you as a maintainer of the package '{2}'.";

            string body = @"The user '{0}' has added you as a maintainer of the package '{1}'. 

Package Url: {2}

Thanks,
The {3} Team";

            body = String.Format(
                CultureInfo.CurrentCulture, body, fromUser.Username, package.Id, packageUrl, settings.GalleryOwnerName);

            using (var mailMessage = new MailMessage())
            {
                mailMessage.Subject = String.Format(
                    CultureInfo.CurrentCulture, subject, settings.GalleryOwnerName, fromUser.Username, package.Id);
                mailMessage.Body = body;
                mailMessage.From = fromUser.ToMailAddress();

                mailMessage.To.Add(toUser.ToMailAddress());
                SendMessage(mailMessage);
            }
        }
Example #21
0
        public void SendPackageOwnerRemovedNotice(User fromUser, User toUser, PackageRegistration package)
        {
            if (!toUser.EmailAllowed)
            {
                return;
            }

            const string subject = "[{0}] The user '{1}' has removed you as an owner of the package '{2}'.";

            string body = @"The user '{0}' removed you as an owner of the package '{1}'.

If this was done incorrectly, we'd recommend contacting '{0}' at '{2}'.

Thanks,
The {3} Team";
            body = String.Format(CultureInfo.CurrentCulture, body, fromUser.Username, package.Id, fromUser.EmailAddress, Config.GalleryOwner.DisplayName);

            using (var mailMessage = new MailMessage())
            {
                mailMessage.Subject = String.Format(CultureInfo.CurrentCulture, subject, Config.GalleryOwner.DisplayName, fromUser.Username, package.Id);
                mailMessage.Body = body;
                mailMessage.From = Config.GalleryNoReplyAddress;
                mailMessage.ReplyToList.Add(fromUser.ToMailAddress());

                mailMessage.To.Add(toUser.ToMailAddress());
                SendMessage(mailMessage);
            }
        }