Пример #1
0
        private string GenerateDefaultEmailContent(UserTDO user, EventTDO ev, GuestTDO guest, string permalink)
        {
            var model = new {
                Name        = !string.IsNullOrEmpty(guest.Salutation) ? (guest.Salutation + " ") : "" + ((!string.IsNullOrEmpty(guest.LastName)) ? guest.LastName : "Sir/Madam"),
                FirstName   = !string.IsNullOrEmpty(guest.FirstName) ? guest.FirstName : "",
                LastName    = !string.IsNullOrEmpty(guest.LastName) ? guest.LastName : "",
                EventName   = !string.IsNullOrEmpty(ev.EventName) ? ev.EventName : "",
                Email       = !string.IsNullOrEmpty(guest.Email) ? guest.Email : "",
                UserName    = (!string.IsNullOrEmpty(user.FirstName) ? (user.FirstName + " ") : "") + (!string.IsNullOrEmpty(user.LastName) ? user.LastName : ""),
                AccountName = !string.IsNullOrEmpty(user.AccountName) ? user.AccountName : "",
                PermaLink   = permalink
            };
            string template = @"<html>
                                    <head><title>@Model.LastName</title></head>
                                    <body>
                                        Dear @Model.FirstName:<br />
                                        <p>
                                        Thank you for joining us at @Model.EventName. We hope that you enjoy it.
                                        </p>
                                        <p>
                                        Please follow the <a href='@Model.PermaLink'>link</a> to view your photo.
                                        </p>
                                        <br />
                                        <p>
                                        Sincerely,<br />
                                        @Model.UserName - @Model.AccountName
                                        </p>
                                    </body>
                                </html>";

            return(Razor.Parse(template, model));
        }
Пример #2
0
 internal void SendEmails(UserTDO user, EventTDO ev, PhotoAnnotation photoAnnotation, ICollection <string> permalinks)
 {
     this.Error = "";
     foreach (GuestTDO guest in (IEnumerable <GuestTDO>)photoAnnotation.Guests)
     {
         this.SendEmailTo(user, ev, guest, permalinks);
     }
 }
Пример #3
0
        internal void SendEmails(UserTDO user, EventTDO ev, PhotoAnnotation photoAnnotation, string permalink)
        {
            Error = "";

            ICollection <GuestTDO> guests = photoAnnotation.Guests;

            foreach (GuestTDO guest in guests)
            {
                SendEmailTo(user, ev, guest, permalink);
            }
        }
Пример #4
0
        private bool Login(LoginModel model)
        {
            UserTDO user = _fsWebService.Login(AppConfigs.ApiKey, model);

            if (user != null)
            {
                Response.SetAuthCookie <string>(user.FirstName + " " + user.LastName, model.RememberMe, _fsWebService.Authorization);
                return(true);
            }

            return(false);
        }
Пример #5
0
        private bool InitializeApi(FsApiWebService fsApiService, bool serverAuthenticated)
        {
            if (serverAuthenticated)
            {
                if (User != null)
                {
                    return(true);
                }
            }
            else if (ClientUser != null)
            {
                return(true);
            }

            LoginModel model = new LoginModel {
                UserName = AppConfig.FsUserEmail, Password = AppConfig.FsPassword
            };

            UserTDO user = null;

            try {
                FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Authorizing for fotoShout on {0}...", fsApiService.BaseAddress));
                user = fsApiService.Login(AppConfig.FsApiKey, model);
                if (user == null)
                {
                    FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("There is no user on {0} associated with the fotoShout Authorization key. The authentication will be retried in the next round.", fsApiService.BaseAddress));
                    return(false);
                }
                FotoShoutUtils.Log.LogManager.Info(_logger, "Succeeded to access to the user info.");
            }
            catch (Exception ex) {
                if (ex is WebException)
                {
                    FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Exception on {0}: {1}.", fsApiService.BaseAddress, ex.Message));
                }
                else
                {
                    FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("There is no user on {0} associated with the fotoShout Authorization key. The authentication will be retried in the next round.", fsApiService.BaseAddress));
                }
                return(false);
            }

            if (serverAuthenticated)
            {
                User = user;
            }
            else
            {
                ClientUser = user;
            }

            return(true);
        }
Пример #6
0
        // GET api/Authorization
        public UserTDO Get()
        {
            UserTDO tdo = null;

            try {
                // get the api key
                string apiKey = this.GetApiKey(_logger);

                FotoShoutUtils.Log.LogManager.Info(_logger, "Getting user info...");
                User user = this.GetUser(apiKey, db);
                if (user == null)
                {
                    this.GenerateException(HttpStatusCode.Unauthorized, Errors.ERROR_AUTHORIZATIONKEY_INVALID, _logger);
                }

                FotoShoutUtils.Log.LogManager.Info(_logger, "Successfully got user info");

                FotoShoutUtils.Log.LogManager.Info(_logger, "Getting account info...");
                Account account = this.GetAccount(user.Id, db);
                if (account == null)
                {
                    this.GenerateException(HttpStatusCode.Unauthorized, Errors.ERROR_AUTHORIZATIONKEY_INVALID, _logger);
                }

                FotoShoutUtils.Log.LogManager.Info(_logger, "Successfully got account info");

                tdo = new UserTDO {
                    Id            = user.Id,
                    FirstName     = user.FirstName,
                    LastName      = user.LastName,
                    MiddleInitial = user.MiddleInitial,
                    Title         = user.Title,
                    Phone         = user.Phone,
                    PhoneExt      = user.PhoneExt,
                    Email         = user.Email,
                    Status        = user.Status,
                    CreatedBy     = user.CreatedBy,
                    Created       = user.Created,
                    AccountName   = account.AccountName,
                    Role          = (user.Role != null) ? user.Role.Name : ""
                };
            }
            catch (HttpResponseException ex) {
                throw ex;
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                this.GenerateException(HttpStatusCode.BadRequest, ex.Message);
            }

            return(tdo);
        }
Пример #7
0
        internal void SendEmailTo(UserTDO user, EventTDO ev, GuestTDO guest, ICollection <string> permalinks)
        {
            if (string.IsNullOrEmpty(guest.Email))
            {
                FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("There is no email address stored for {0}.", ((!string.IsNullOrEmpty(guest.FirstName)) ? (guest.FirstName + " ") : "") + ((!string.IsNullOrEmpty(guest.LastName)) ? guest.LastName : guest.GuestId.ToString())));
                return;
            }

            foreach (string permalink in permalinks)
            {
                SendEmailTo(user, ev, guest, permalink);
            }
        }
Пример #8
0
        private void SendEmails(UserTDO user, EventTDO ev, PhotoTDO photo, PhotoAnnotation photoAnnotation, string photoUrl)
        {
            if (ev.WebsiteId != null)
            {
                Website website = _fsWebService.Get <Website>("Websites/" + ev.WebsiteId, true);
                photoUrl = GeneratePhotoWebsiteUrl(photoUrl, website); // string.Format("{0}PhotoWebsite/{1}?website={2}", Regex.Replace(AppSettings.FsApiBaseAddress, @"api/", ""), photo.PhotoId, ev.WebsiteId);
            }

            ICollection <GuestTDO>   guests = photoAnnotation.Guests;
            IEnumerable <PhotoEmail> list   = this._fsWebService.GetList <PhotoEmail>("PhotoEmails/" + (object)photo.PhotoId, true);

            foreach (GuestTDO guestTdo in (IEnumerable <GuestTDO>)guests)
            {
                GuestTDO   guest      = guestTdo;
                bool       flag       = true;
                PhotoEmail postObject = list.Where(ee => ee.PhotoId == photo.PhotoId && ee.GuestId == guest.GuestId).FirstOrDefault();
                if (postObject == null)
                {
                    postObject = new PhotoEmail {
                        EventId = ev.EventId,
                        PhotoId = photo.PhotoId,
                        GuestId = guest.GuestId
                    };
                    flag = false;
                }
                else if (postObject.Status == (byte)1)
                {
                    continue;
                }
                this._emailService.Error = "";
                this._emailService.SendEmailTo(user, ev, guest, photoUrl);
                if (string.IsNullOrEmpty(this._emailService.Error))
                {
                    postObject.Status = (byte)1;
                    postObject.Error  = null;
                }
                else
                {
                    postObject.Status = byte.MaxValue;
                    postObject.Error  = this._emailService.Error;
                }
                if (flag)
                {
                    this._fsWebService.UploadString("PhotoEmails?photoEmailId=" + (object)postObject.PhotoEmailId, this.GeneratePostContent <PhotoEmail>(postObject), "PUT");
                }
                else
                {
                    this._fsWebService.UploadString("PhotoEmails", this.GeneratePostContent <PhotoEmail>(postObject), null);
                }
            }
        }
Пример #9
0
        public UserTDO Login(Credentials credentials)
        {
            string ret = Authenticate(credentials);

            if (!string.IsNullOrEmpty(ret))
            {
                FotoShoutUtils.Log.LogManager.Debug(_logger, "Getting user info...");
                // Need to switch back
                _user = GetUser <UserTDO>();
                //_user = new UserTDO {
                //    FirstName = "Phong",
                //    LastName = "Nguyen"
                //};
            }

            return(_user);
        }
Пример #10
0
        private string GetEmailContent(UserTDO user, EventTDO ev, GuestTDO guest, string permalink)
        {
            var model = new {
                Name        = !string.IsNullOrEmpty(guest.Salutation) ? (guest.Salutation + " ") : "" + ((!string.IsNullOrEmpty(guest.LastName)) ? guest.LastName : "Sir/Madam"),
                FirstName   = !string.IsNullOrEmpty(guest.FirstName) ? guest.FirstName : "",
                LastName    = !string.IsNullOrEmpty(guest.LastName) ? guest.LastName : "",
                EventName   = !string.IsNullOrEmpty(ev.EventName) ? ev.EventName : "",
                Email       = !string.IsNullOrEmpty(guest.Email) ? guest.Email : "",
                UserName    = (!string.IsNullOrEmpty(user.FirstName) ? (user.FirstName + " ") : "") + (!string.IsNullOrEmpty(user.LastName) ? user.LastName : ""),
                AccountName = !string.IsNullOrEmpty(user.AccountName) ? user.AccountName : "",
                PermaLink   = permalink
            };
            string emailContent = "";

            try {
                emailContent = Razor.Parse(EmailTemplate.EmailContent, model);
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Error: {0} - Publishing service will use the default email content.", ex.ToString()));
            }
            return(emailContent);
        }
Пример #11
0
        internal void SendEmailTo(UserTDO user, EventTDO ev, GuestTDO guest, string permalink)
        {
            string receiver = ((!string.IsNullOrEmpty(guest.FirstName)) ? (guest.FirstName + " ") : "") + ((!string.IsNullOrEmpty(guest.LastName)) ? guest.LastName : "");

            if (string.IsNullOrEmpty(receiver))
            {
                receiver = guest.GuestId.ToString();
            }
            FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Sending the \"{0}\" link to \"{1}\"...", permalink, receiver));

            try {
                string emailContent = "";
                if (EmailTemplate != null)
                {
                    emailContent = GetEmailContent(user, ev, guest, permalink);
                }
                if (string.IsNullOrEmpty(emailContent))
                {
                    emailContent = GenerateDefaultEmailContent(user, ev, guest, permalink);
                }

                using (MailMessage message = new MailMessage()) {
                    message.From = new MailAddress(EmailServerAccount.Username);
                    message.To.Add(new MailAddress(guest.Email));
                    message.Subject      = EmailTemplate.EmailSubject;
                    message.IsBodyHtml   = true;
                    message.Body         = emailContent;
                    message.BodyEncoding = System.Text.Encoding.UTF8;

                    int        port       = (int)EmailServerAccount.Port;
                    SmtpClient mailClient = (port == 0) ? new SmtpClient(EmailServerAccount.Server) : new SmtpClient(EmailServerAccount.Server, port);
                    bool       enableSsl  = EmailServerAccount.EnableSSL;
                    try {
                        if (enableSsl)
                        {
                            mailClient.EnableSsl = true;
                            FotoShoutUtils.Log.LogManager.Info(_logger, "Enabled SSL");
                        }
                        //mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
                        if (!string.IsNullOrEmpty(EmailServerAccount.Username))
                        {
                            mailClient.Credentials = string.IsNullOrEmpty(EmailServerAccount.Domain) ?
                                                     new NetworkCredential(EmailServerAccount.Username, EmailServerAccount.Password) :
                                                     new NetworkCredential(EmailServerAccount.Username, EmailServerAccount.Password, EmailServerAccount.Domain);
                        }
                        else
                        {
                            mailClient.UseDefaultCredentials = true;
                        }
                        FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Mail Server: {0}, From: {1} - {2}", EmailServerAccount.Server, message.From.Address, message.From.DisplayName));
                        mailClient.Send(message);
                    }
                    finally {
                        if (mailClient != null)
                        {
                            mailClient.Dispose();
                        }
                    }
                }

                FotoShoutUtils.Log.LogManager.Info(_logger, "Successfully sending email");
            }
            catch (Exception ex) {
                FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Failed to send the \"{0}\" link to \"{1}\"...", permalink, receiver));
                FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                Error = ex.Message;
            }
        }