コード例 #1
0
        public ActionResult Index(ResetPasswordModel model)
        {
            if (String.IsNullOrEmpty(model.EmailAddress))
            {
                ViewBag.ErrorMessage = "Please enter an email address";
                return(View());
            }

            return(DatabaseFunction <ActionResult>(conn =>
            {
                Invite[] invites = Invite.GetInvites(conn);

                Invite loggedInInvite = invites.SingleOrDefault(p => p.EmailAddress.ToLower() == model.EmailAddress.Trim().ToLower());

                if (loggedInInvite == null)
                {
                    ViewBag.ErrorMessage = "Email address not found";
                    return View();
                }

                loggedInInvite.ResetPassword();
                loggedInInvite.Save(conn);

                SendInviteEmail(loggedInInvite);

                return RedirectToAction("Index", "LogIn");
            }));
        }
コード例 #2
0
        /// <summary>
        /// Sends the emails relating to the specified message to the specified recipient invite
        /// </summary>
        /// <param name="conn">Open connection to the database</param>
        /// <param name="message">Message the emails relate to</param>
        /// <param name="recipientInvite">Invite the messages are being sent to</param>
        protected static void SendMessageEmails(SqlConnection conn, Message message, Invite recipientInvite)
        {
            List <MailMessage> emails = new List <MailMessage>();

            switch (message.Sender)
            {
            case MessageSender.Admin:

                if (recipientInvite.EmailMessages)
                {
                    MailMessage email = new MailMessage();
                    email.To.Add(recipientInvite.EmailAddress);
                    email.From       = new MailAddress(MailFrom, "John Lace & Lizzie Toms");
                    email.Subject    = "John & Lizzie have sent you a message";
                    email.IsBodyHtml = true;

                    email.Body = Resources.MessageToInvite
                                 .Replace("[INVITE_ID]", message.InviteId.ToString())
                                 .Replace("[MESSAGE_BODY]", message.Body);

                    emails.Add(email);
                }

                break;

            case MessageSender.Invite:

                Invite[] invites = Invite.GetInvites(conn);

                foreach (Invite invite in invites.Where(p => p.IsAdmin && p.EmailMessages))
                {
                    MailMessage email = new MailMessage();
                    email.To.Add(invite.EmailAddress);
                    email.From       = new MailAddress(MailFrom, recipientInvite.EmailAddress);
                    email.Subject    = "One of your guests has sent you a message";
                    email.IsBodyHtml = true;

                    email.Body = Resources.MessageFromInvite
                                 .Replace("[INVITE_ID]", message.InviteId.ToString())
                                 .Replace("[GUEST_LIST]", recipientInvite.GuestList)
                                 .Replace("[MESSAGE_BODY]", message.Body);

                    emails.Add(email);
                }

                break;

            default:
                throw new UnknownEnumValueException(message.Sender);
            }

            SendEmails(emails);
        }
コード例 #3
0
        /// <summary>
        /// Sends the emails notifying invites that the gift website has been set up
        /// </summary>
        protected static void SendGiftWebsiteEmails()
        {
            List <MailMessage> emails = new List <MailMessage>();

            DatabaseAction(conn =>
            {
                foreach (Invite invite in Invite.GetInvites(conn).Where(p => p.NotifyGiftWebsite))
                {
                    MailMessage message = new MailMessage();
                    message.To.Add(invite.EmailAddress);
                    message.From       = new MailAddress(MailFrom, "John Lace & Lizzie Toms");
                    message.Subject    = "The wedding of John & Lizzie";
                    message.IsBodyHtml = true;

                    message.Body = Resources.GiftWebsiteEmail
                                   .Replace("[GUEST_LIST]", invite.GuestListForenames);

                    emails.Add(message);
                }
            });

            SendEmails(emails);
        }
コード例 #4
0
        public ActionResult Index(LoginViewModel model)
        {
            if (String.IsNullOrEmpty(model.Username))
            {
                ViewBag.ErrorMessage = "Please enter an email address";
                return(View());
            }

            Invite[] invites = DatabaseFunction <Invite[]>(conn =>
            {
                return(Invite.GetInvites(conn));
            });

            Invite loggedInInvite = invites.SingleOrDefault(p => p.EmailAddress.ToLower() == model.Username.Trim().ToLower() && p.CheckPassword(model.Password));

            if (loggedInInvite == null)
            {
                ViewBag.ErrorMessage = "Email address and password not found";
                return(View());
            }

            FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
            LoggedInInvite = loggedInInvite;
            LastUsername   = LoggedInInvite.EmailAddress;

            UserPageController.LayoutImagesLoaded = false;

            String returnUrl = Request.QueryString["ReturnUrl"];

            if (String.IsNullOrEmpty(returnUrl))
            {
                return(RedirectToAction("Index", "Default"));
            }

            return(Redirect(returnUrl));
        }