/// <summary>
        /// Sends the current notification.
        /// </summary>
        /// <returns>A <see cref="NameValueCollection"/> mapping failed e-mail recipients to failure messages.</returns>
        public NameValueCollection Send()
        {
            NameValueCollection   failedRecipients = new NameValueCollection();
            MailAddressCollection recipients       = new MailAddressCollection();
            Settings settings = Properties.Settings.Default;
            string   header   = settings.BodyTemplateHeader;
            string   footer   = settings.BodyTemplateFooter;

            if (this.Recipients != null)
            {
                foreach (var cpuser in this.Recipients)
                {
                    try
                    {
                        MailAddress recipient = _mail.GetMailAddress(cpuser);
                        recipients.Add(recipient);
                        _mail.Recipient = recipient;
                        _mail.Send();
                    }
                    catch (Exception e)
                    {
                        // track failed recipients
                        failedRecipients[string.Format("{0} [{1}] ({2})", cpuser.DisplayName, cpuser.UserName, string.IsNullOrEmpty(cpuser.Email) ? "<no e-mail address>" : cpuser.Email)] = e.Message;
                    }
                }
            }

            // return failed recipients
            return(failedRecipients);
        }
        /// <summary>
        /// Sends an e-mail message with the contents of the form when submitted.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnSubmit(object sender, EventArgs e)
        {
            StringBuilder  body = new StringBuilder();
            MembershipUser user = Membership.GetUser();

            body.AppendLine("Sender Details:");
            body.AppendLine("---------------");
            body.AppendFormat("{0} Username: {1}\r\n", CPProviders.SettingsProvider.ApplicationName, user.UserName);
            body.AppendLine("Candidate ID: " + CPProfile.Cid);
            body.AppendLine("Candidate Name: " + CPProfile.ActiveCandidate.Name);
            body.AppendLine("Election Cycle: " + CPProfile.ElectionCycle);
            body.AppendLine("---------------");
            body.AppendLine();
            body.AppendLine("Message Details:");
            body.AppendLine("----------------");
            body.AppendLine(Message.Text);
            // assemble message
            CPMailMessage message = new CPMailMessage();

            message.Recipient = new MailAddress(CPApplication.CsuEmail);
            message.Sender    = CPProfile.GetMailAddress();
            message.Subject   = _subject;
            message.Body      = body.ToString();
            // send message
            message.Send();
            _contactForm.Visible  = false;
            _confirmation.Visible = true;
        }
Exemple #3
0
        protected void OnSubmit(object sender, EventArgs e)
        {
            string toEmail;
            string subject;

            switch (Category.SelectedValue.ToLowerInvariant())
            {
            case "audit":
                toEmail = CPApplication.AuditEmail;
                subject = Resources.CPResources.audit_email_subject;
                break;

            case "csu":
                toEmail = CPApplication.CsuEmail;
                subject = Resources.CPResources.csu_email_subject;
                break;

            default:
                toEmail = CPApplication.GeneralEmail;
                subject = Resources.CPResources.general_email_subject;
                break;
            }
            MembershipUser user = Membership.GetUser(User.Identity.Name);
            StringBuilder  body = new StringBuilder();

            body.AppendLine("Sender Details:");
            body.AppendLine("---------------");
            body.AppendFormat("{0} Username: {1}\r\n", CPProviders.SettingsProvider.ApplicationName, user.UserName);
            body.AppendLine("Candidate ID: " + CPProfile.Cid);
            body.AppendLine("Candidate Name: " + CPProfile.ActiveCandidate.Name);
            body.AppendLine("Election Cycle: " + CPProfile.ElectionCycle);
            body.AppendLine("---------------");
            body.AppendLine();
            body.AppendLine("Message Details:");
            body.AppendLine("----------------");
            body.AppendLine(Message.Text);
            // assemble message
            CPMailMessage message = new CPMailMessage();

            message.Sender    = CPProfile.GetMailAddress();
            message.Recipient = new MailAddress(toEmail);
            message.Subject   = subject;
            message.Body      = body.ToString();
            // send message
            message.Send();
            _contactForm.Visible  = false;
            _confirmation.Visible = true;
        }
 /// <summary>
 /// Handles password change attempts and updates page contents accordingly.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">An <see cref="EventArgs" /> that contains the event data.</param>
 protected void SubmitChange(object sender, EventArgs e)
 {
     _wrongPasswordMessage.Visible      = false;
     _usernameAsPasswordMessage.Visible = false;
     if (Page.IsValid)
     {
         var user = this.CPUser;
         if (_newPassword.Text.Equals(user.UserName, StringComparison.InvariantCultureIgnoreCase))
         {
             _usernameAsPasswordMessage.Visible = true;
         }
         else
         {
             if (user.ChangePassword(_currentPassword.Text, _newPassword.Text)) // TODO: implement ChangePassword security service web method
             {
                 // unexpire the password
                 if (user != null && user.PasswordExpired)
                 {
                     user.PasswordExpired = false;
                     user = CPSecurity.Provider.UpdateUser(user).User;
                 }
                 // present success confirmation
                 _changePasswordPanel.Visible = false;
                 _successPanel.Visible        = true;
                 if (Request.IsPitStop())
                 {
                     this.ReturnToHomeLink.NavigateUrl = Request.GetReturnUrl();
                     this.ReturnToHomeLink.Text        = this.ReturnToHomeLink.ToolTip = "Continue";
                 }
                 // send confirmation e-mail
                 CPMailMessage message = new CPMailMessage();
                 MailAddress   email   = CPProfile.GetMailAddress();
                 message.Recipient = email;
                 message.Subject   = _emailSubject;
                 message.Body      = string.Format(_bodyFormat, email.DisplayName, CPProviders.SettingsProvider.ApplicationName, CPProviders.SettingsProvider.ApplicationUrl, CPProviders.SettingsProvider.AgencyPhoneNumber);
                 message.Send();
                 // BUGFIX #18 - re-add authentication cookie
                 FormsAuthentication.SetAuthCookie(user.UserName, false);
             }
             else
             {
                 _wrongPasswordMessage.Visible = true;
             }
         }
     }
 }
Exemple #5
0
        void Application_Error(object sender, EventArgs e)
        {
            // Code that runs when an unhandled error occurs
            // check for SQL connection problems and show offline message as appropriate
            Exception ex = Server.GetLastError();

            // detect web transfer
            if (CPProviders.DataProvider.IsOfflineDataException(ex.GetBaseException()) || CPSecurity.Provider.IsOfflineDataException(ex.GetBaseException()))
            {
                Session.Clear();
                Session.Abandon();
                Server.Transfer("~/Offline.aspx");
            }
            else if (Request.Url.AbsolutePath.StartsWith("/_", StringComparison.Ordinal))
            {
                Server.RedirectPageNotFound();
            }
            else
            {
                try
                {
                    Cfb.ExceptionHandling.CfbExceptionPolicy.LogException(ex);
                    CPMailMessage email = new CPMailMessage();
                    email.Recipient = new MailAddress(CPApplication.GeneralEmail);
                    email.Subject   = "C-Access Server Error Report";
                    email.Body      = ex.ToString();
                    HttpException he = ex as HttpException;
                    if (he != null)
                    {
                        int httpCode = he.GetHttpCode();
                        if (httpCode < 500)
                        {
                            return;
                        }
                        email.Body += "\n\nHTTP Error Code: " + httpCode;
                    }
                    email.Send();
                }
                catch { }
            }
        }
Exemple #6
0
        /// <summary>
        /// Sends a new account request for the currently loaded contact.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">A <see cref="CommandEventArgs"/> that contains the event data.</param>
        protected void RequestAccountCommand(object sender, CommandEventArgs e)
        {
            string contactType = "Unknown";

            switch (e.CommandName)
            {
            case LiaisonCommandName:
            case TreasurerCommandName:
            case ConsultantCommandName:
            case CandidateCommandName:
                contactType = e.CommandName;
                break;
            }
            // send access request for user via e-mail
            StringBuilder  body           = new StringBuilder();
            MembershipUser requestor      = Membership.GetUser();
            MailAddress    requestorEmail = CPProfile.GetMailAddress();

            body.AppendFormat("{0} user {1} (username: {2}) has requested an additional account for the following campaign contact:", CPProviders.SettingsProvider.ApplicationName, requestorEmail.DisplayName, requestor.UserName);
            body.AppendLine();
            body.AppendLine();
            body.AppendLine("First Name: " + (_firstNameResult.Text = _firstName.Text));
            body.AppendLine("Middle Initial: " + (_miResult.Text = _mi.Text));
            body.AppendLine("Last Name: " + (_lastNameResult.Text = _lastName.Text));
            body.AppendLine("E-mail Address: " + (_emailResult.Text = _email.Text));
            body.AppendLine();
            body.AppendLine("Candidate ID: " + CPProfile.Cid);
            body.AppendLine("Contact Type: " + contactType);
            // assemble message
            CPMailMessage message = new CPMailMessage();

            message.Sender    = requestorEmail;
            message.Recipient = new MailAddress(CPApplication.CsuEmail);
            message.Subject   = string.Format(_subjectFormat, CPProviders.SettingsProvider.ApplicationName, CPProfile.ActiveCandidate.Name);
            message.Body      = body.ToString();
            // send message
            message.Send();
            _successPanel.Visible   = true;
            _contactDetails.Visible = _contactSelection.Visible = false;
        }
Exemple #7
0
 /// <summary>
 /// Attempts to submit the current extension request.
 /// </summary>
 /// <returns>true if the extension request was successfully submitted; otherwise, false.</returns>
 private bool SubmitExtensionRequest()
 {
     try
     {
         byte     number;
         DateTime dueDate;
         DateTime requestedDate;
         if (TryParseReviewNumberListItemValue(_numberDropDown.SelectedValue, out number, out dueDate) && DateTime.TryParse(_dueDateDropDown.SelectedValue, out requestedDate))
         {
             Extension req = Extension.Add(CPProfile.Cid, _electionCycle.Text, CPConvert.ParseEnum <ExtensionType>(_types.SelectedValue), number, DateTime.Now, requestedDate, _reason.Text);
             if (req != null)
             {
                 // send e-mail notification
                 CPMailMessage message = new CPMailMessage();
                 message.Sender = CPProfile.GetMailAddress();
                 message.To.Add(CPApplication.AuditExtensionRequestsEmail);
                 message.IsBodyHtml = true;
                 message.Subject    = string.Format("Request for Extension to EC{0} {1} {2}", req.ElectionCycle, _typesValue.Text, req.ReviewNumber);
                 message.Body       = string.Format(EmailBodyFormat,
                                                    Cfis.GetCandidateName(CPProfile.Cid, true),
                                                    CPProfile.Cid,
                                                    message.Sender.DisplayName,
                                                    User.Identity.Name,
                                                    req.ElectionCycle,
                                                    _typesValue.Text,
                                                    _numberLabelText.Text,
                                                    _numberValue.Text,
                                                    _dueDateValue.Text);
                 message.Send();
                 return(true);
             }
         }
     }
     catch
     {
     }
     return(false);
 }