Esempio n. 1
0
        public IHttpActionResult Post(EmailCommunicationDTO email)
        {
            return(Authorized(token =>
            {
                try
                {
                    _emailCommunication.SendEmail(email, token);

                    return Ok();
                }
                catch (Exception ex)
                {
                    return InternalServerError(ex);
                }
            }));
        }
Esempio n. 2
0
        private void SendPendingInquiryReminderEmail(MpGroup group, IReadOnlyCollection <MpInquiry> inquiries)
        {
            var leaders         = ((List <MpGroupParticipant>)group.Participants).FindAll(p => p.GroupRoleId == _groupRoleLeaderId).ToList();
            var allLeaders      = string.Join(", ", leaders.Select(leader => $"{leader.NickName} {leader.LastName} ({leader.Email})").ToArray());
            var pendingRequests = string.Join("<br>", inquiries.Select(inquiry => $"{inquiry.FirstName} {inquiry.LastName} ({inquiry.EmailAddress})").ToArray());

            // ReSharper disable once LoopCanBePartlyConvertedToQuery
            foreach (var leader in leaders)
            {
                var mergeData = new Dictionary <string, object>
                {
                    { "Nick_Name", leader.NickName },
                    { "Last_Name", leader.LastName },
                    { "All_Leaders", allLeaders },
                    { "Pending_Requests", pendingRequests },
                    { "Group_Name", group.Name },
                    { "Group_Description", group.GroupDescription },
                    { "Group_ID", group.GroupId },
                    { "Pending_Requests_Count", inquiries.Count }
                };

                var email = new EmailCommunicationDTO
                {
                    groupId     = group.GroupId,
                    TemplateId  = _groupRequestPendingReminderEmailTemplateId,
                    ToContactId = leader.ContactId,
                    MergeData   = mergeData
                };
                _emailCommunicationService.SendEmail(email);
            }
        }
Esempio n. 3
0
        public bool PasswordResetRequest(string username)
        {
            int user_ID    = 0;
            int contact_Id = 0;

            // validate the email on the server side to avoid erroneous or malicious requests
            try
            {
                user_ID    = _userService.GetUserIdByUsername(username);
                contact_Id = _userService.GetContactIdByUserId(user_ID);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Could not find email {0} for password reset", JsonConvert.SerializeObject(username, Formatting.Indented)), ex);
                return(false);
            }

            // create a token -- see http://stackoverflow.com/questions/664673/how-to-implement-password-resets
            var resetArray = Encoding.UTF8.GetBytes(Guid.NewGuid() + username + System.DateTime.Now);
            RNGCryptoServiceProvider prov = new RNGCryptoServiceProvider();

            prov.GetBytes(resetArray);
            var    resetToken = Encoding.UTF8.GetString(resetArray);
            string cleanToken = Regex.Replace(resetToken, "[^A-Za-z0-9]", "");

            Dictionary <string, object> userUpdateValues = new Dictionary <string, object>();

            userUpdateValues["User_ID"]            = user_ID;
            userUpdateValues["PasswordResetToken"] = cleanToken; // swap out for real implementation
            _userService.UpdateUser(userUpdateValues);

            string baseURL   = _configurationWrapper.GetConfigValue("BaseURL");
            string resetLink = (@"https://" + baseURL + "/reset-password?token=" + cleanToken);

            // add the email here...
            var emailCommunication = new EmailCommunicationDTO
            {
                FromContactId = 7, // church admin contact id
                FromUserId    = 5, // church admin user id
                ToContactId   = contact_Id,
                TemplateId    = 13356,
                MergeData     = new Dictionary <string, object>
                {
                    { "resetlink", resetLink }
                }
            };

            try
            {
                _emailCommunication.SendEmail(emailCommunication);
                return(true);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Could not send email {0} for password reset", JsonConvert.SerializeObject(username, Formatting.Indented)), ex);
                return(false);
            }
        }
Esempio n. 4
0
        private void SendEmail(CheckScannerBatch batch, Exception error)
        {
            if (batch.MinistryPlatformContactId == null || batch.MinistryPlatformUserId == null)
            {
                return;
            }

            var email = new EmailCommunicationDTO
            {
                FromContactId = batch.MinistryPlatformContactId.Value,
                FromUserId    = batch.MinistryPlatformUserId,
                ToContactId   = batch.MinistryPlatformContactId.Value,
                TemplateId    = error == null ? _checkScannerBatchSuccessTemplateId : _checkScannerBatchFailureTemplateId,
                MergeData     = new Dictionary <string, object>
                {
                    { "batchName", batch.Name },
                    { "programId", batch.ProgramId },
                }
            };

            if (error != null)
            {
                email.MergeData["exception"] = error;
            }
            else
            {
                email.MergeData["batch"] = batch.EmailMsg;
            }


            try
            {
                _emailService.SendEmail(email);
            }
            catch (Exception e)
            {
                _logger.Error(string.Format("Could not send email {0} for batch", JsonConvert.SerializeObject(email, Formatting.Indented)), e);
            }
        }