예제 #1
0
        public async Task SendContactMessage(Guid chapterId, string fromAddress, string message)
        {
            if (string.IsNullOrWhiteSpace(fromAddress) || string.IsNullOrWhiteSpace(message))
            {
                throw new OdkServiceException("Email address and message must be provided");
            }

            if (!MailUtils.ValidEmailAddress(fromAddress))
            {
                throw new OdkServiceException("Invalid email address format");
            }

            VersionedServiceResult <Chapter> chapter = await GetChapter(null, chapterId);

            ContactRequest contactRequest = new ContactRequest(Guid.Empty, chapter.Value.Id, DateTime.UtcNow, fromAddress, message, false);
            await _chapterRepository.AddContactRequest(contactRequest);

            IDictionary <string, string> parameters = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)
            {
                { "from", fromAddress },
                { "message", HttpUtility.HtmlEncode(message) }
            };

            await _emailService.SendContactEmail(chapter.Value, fromAddress, message, parameters);
        }
예제 #2
0
        private async Task ValidateMemberProfile(Guid chapterId, CreateMemberProfile profile)
        {
            IReadOnlyCollection <ChapterProperty> chapterProperties = await _chapterRepository.GetChapterProperties(chapterId);

            IReadOnlyCollection <string> missingProperties = GetMissingMemberProfileProperties(profile, chapterProperties, profile.Properties).ToArray();

            if (missingProperties.Count > 0)
            {
                throw new OdkServiceException($"The following properties are required: {string.Join(", ", missingProperties)}");
            }

            if (!MailUtils.ValidEmailAddress(profile.EmailAddress))
            {
                throw new OdkServiceException("Invalid email address format");
            }
        }
예제 #3
0
        public async Task RequestMemberEmailAddressUpdate(Guid memberId, string newEmailAddress)
        {
            Member member = await GetMember(memberId, memberId);

            if (member.EmailAddress.Equals(newEmailAddress, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            if (!MailUtils.ValidEmailAddress(newEmailAddress))
            {
                throw new OdkServiceException("Invalid email address format");
            }

            MemberEmailAddressUpdateToken existingToken = await _memberRepository.GetMemberEmailAddressUpdateToken(member.Id);

            if (existingToken != null)
            {
                await _memberRepository.DeleteEmailAddressUpdateToken(member.Id);
            }

            string activationToken = RandomStringGenerator.Generate(64);

            MemberEmailAddressUpdateToken token = new MemberEmailAddressUpdateToken(member.Id, newEmailAddress, activationToken);
            await _memberRepository.AddEmailAddressUpdateToken(token);

            Chapter chapter = await _chapterRepository.GetChapter(member.ChapterId);

            string url = _settings.ConfirmEmailAddressUpdateUrl.Interpolate(new Dictionary <string, string>
            {
                { "chapter.name", chapter.Name },
                { "token", HttpUtility.UrlEncode(activationToken) }
            });

            await _emailService.SendEmail(chapter, newEmailAddress, EmailType.EmailAddressUpdate, new Dictionary <string, string>
            {
                { "chapter.name", chapter.Name },
                { "url", url }
            });
        }
예제 #4
0
        public async Task RequestPasswordReset(string emailAddress)
        {
            if (!MailUtils.ValidEmailAddress(emailAddress))
            {
                throw new OdkServiceException("Invalid email address format");
            }

            Member member = await _memberRepository.FindMemberByEmailAddress(emailAddress);

            DateTime created = DateTime.UtcNow;
            DateTime expires = created.AddMinutes(_settings.PasswordResetTokenLifetimeMinutes);
            string   token   = RandomStringGenerator.Generate(64);

            try
            {
                _authorizationService.AssertMemberIsCurrent(member);
            }
            catch
            {
                return;
            }

            Chapter chapter = await _chapterRepository.GetChapter(member.ChapterId);

            await _memberRepository.AddPasswordResetRequest(member.Id, created, expires, token);

            string url = _settings.PasswordResetUrl.Interpolate(new Dictionary <string, string>
            {
                { "chapter.name", chapter.Name },
                { "token", HttpUtility.UrlEncode(token) }
            });

            await _emailService.SendEmail(chapter, member.EmailAddress, EmailType.PasswordReset, new Dictionary <string, string>
            {
                { "chapter.name", chapter.Name },
                { "url", url }
            });
        }