Exemple #1
0
        protected virtual MailObject GetDemoMail()
        {
            MailObject mail = new MailObject()
            {
                Subject   = "Plain old email",
                PreHeader = "Some preheader text..."
            };

            mail.AddH1("Cras ac consectetur orci, eu.", align: "left");
            mail.AddH2("Aliquam tempor congue dui, quis.", align: "left");
            mail.AddH3("Nulla ac est blandit, pretium augue a, porta dui. ", align: "left");
            mail.AddH4("Nunc at pellentesque ligula, vel ullamcorper ipsum. Aenean lorem.", align: "left");
            mail.AddParagraph("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum at semper lorem, id varius leo. Vivamus tristique ac ante eu bibendum. Praesent quis dolor justo. Nullam interdum vestibulum tortor, vitae aliquet mauris faucibus id. Aenean sed massa quis dolor tempor mollis vitae sit amet erat. Donec eleifend, nisi consectetur gravida egestas, leo erat viverra mauris, a dapibus ligula nisi ut erat. Nulla laoreet scelerisque vulputate. Duis laoreet ex quis tellus elementum efficitur. Proin ut lorem a lorem blandit pulvinar vel a tellus. Cras in dolor bibendum, maximus eros eget, tristique erat. Aliquam commodo quis lacus quis volutpat. Suspendisse ut auctor mauris, eget venenatis sem. Suspendisse et leo vitae risus auctor malesuada et id lacus. Vestibulum a libero quis sapien varius pharetra lacinia elementum nulla. Nam tempus, turpis id faucibus congue, magna lorem aliquam orci, quis suscipit metus elit bibendum justo. Quisque sagittis consequat tellus, eget imperdiet risus congue non.", align: "left");
            mail.AddParagraph("Vivamus vehicula auctor maximus. Praesent purus dui, venenatis eu lectus et, convallis aliquam urna. Vestibulum pharetra imperdiet dolor, ac convallis risus sagittis eget. Sed nulla erat, tristique et erat id, viverra viverra nisi. Morbi ex libero, eleifend eget orci blandit, vestibulum bibendum nisl. In dapibus faucibus eros, sit amet iaculis turpis dignissim lacinia. Phasellus pretium odio vitae sem porttitor molestie. Morbi luctus est posuere lectus ullamcorper viverra. In sed facilisis purus.", align: "left");
            mail.AddParagraph("Sed semper lectus quis fermentum tincidunt. Maecenas nisi nisl, scelerisque non mi non, pharetra dapibus nibh. Sed ante orci, pretium eu ullamcorper a, laoreet at massa. Nam at arcu dui. Integer sollicitudin urna eget rutrum auctor. Nulla nec metus vel elit fermentum tincidunt. Donec placerat venenatis quam, at sodales mi cursus et. Etiam scelerisque, augue ac ullamcorper dictum, ex purus vestibulum quam, sit amet rutrum tortor arcu sed turpis. Curabitur ut turpis bibendum, semper neque non, maximus mi.", align: "left");
            mail.AddCallToAction("Ut non imperdiet", HttpContext.GetSiteUrl(), align: "left");
            mail.AddParagraph("And that's about it!", align: "left");
            return(mail);
        }
Exemple #2
0
        public virtual async Task <Response> Create(AdminCreateUserViewModel model)
        {
            try
            {
                ApplicationUser user = new ApplicationUser
                {
                    UserName          = model.Username,
                    Email             = model.Email,
                    FirstName         = model.FirstName,
                    LastName          = model.LastName,
                    DisplayName       = model.DisplayName,
                    PhoneNumber       = model.Phone,
                    JobTitle          = model.JobTitle,
                    Anonymous         = model.Anonymous,
                    CreatedOn         = DateTime.UtcNow,
                    LastLogOn         = DateTime.UtcNow,
                    LastLoginLocation = HttpContext.Connection.RemoteIpAddress.ToString(),
                    LastLoginIP       = HttpContext.Connection.RemoteIpAddress.ToString()
                };
                user.AddUserNote(new UserNote()
                {
                    CreatedBy = User.GetLocalUserId(),
                    CreatedOn = DateTime.UtcNow,
                    Note      = $"User created via admin panel by {User.Identity.Name}."
                });
                IdentityResult result = await _account.CreateAsync(user, model.Password);

                if (!result.Succeeded)
                {
                    return(new Response(result.Errors));
                }

                if (model.CreateValidated)
                {
                    user.EmailConfirmed = true;
                    user.Active         = true;
                    await _account.UpdateUserAsync(user);
                }
                else
                {
                    if (!Engine.Settings.Account.RequireEmailConfirmation)
                    {
                        user.EmailConfirmed = true;
                    }
                }

                if (model.NotifyUser)
                {
                    // Send the email to the user, letting em know n' shit.
                    // Create the email content
                    try
                    {
                        MailObject message = new MailObject()
                        {
                            To        = new SendGrid.Helpers.Mail.EmailAddress(user.Email),
                            PreHeader = "You access information for " + Engine.Settings.Basic.FullTitle,
                            Subject   = "You account has been created."
                        };
                        message.AddH1("Account Created!");
                        message.AddParagraph("Your new account has been set up on the " + Engine.Settings.Basic.FullTitle + " website.");
                        message.AddParagraph("Name: <strong>" + user.ToInternalName() + "</strong>");
                        message.AddParagraph("Username: <strong>" + model.Username + "</strong>");
                        message.AddParagraph("Password: <strong>" + model.Password + "</strong>");
                        message.AddCallToAction("Log in here", ControllerContext.HttpContext.GetSiteUrl() + "/account/login", "#32bc4e", "center");
                        await _emailSender.SendEmailAsync(message);
                    }
                    catch (Exception)
                    {
                        // roll back!
                        ApplicationUser deleteUser = await _account.GetUserByEmailAsync(model.Email);

                        await _account.DeleteUserAsync(deleteUser.Id, User);

                        throw new Exception("There was a problem sending the email, ensure the site's email address and SendGrid settings are set up correctly before sending.");
                    }
                }
                await _logService.AddLogAsync <BaseUsersController>($"A new user account has been created in the admin area for {user.Email}", type : LogType.Success);

                return(new Response(true, "Successfully created."));
            }
            catch (Exception ex)
            {
                return(await ErrorResponseAsync <BaseUsersController>($"Error creating a user via the admin panel.", ex));
            }
        }
Exemple #3
0
        /// <summary>
        /// This is the main thread, controls the whole update process.
        /// All other functions are fired of from here and once complete, the update is complete.
        /// </summary>
        private async void RefreshAllMedia()
        {
            try
            {
                // Start by cleaning the temp folder.
                CleanTempFolder();

                var all = Database.Media;

                Lock.AcquireWriterLock(Timeout.Infinite);
                Total = all.Count();
                Lock.ReleaseWriterLock();

                foreach (var media in all)
                {
                    CheckForCancel();
                    try
                    {
                        await _media.RefreshMedia(media, TempFolder);
                    }
                    catch (WebException ex)
                    {
                        StatusMessage = string.Format("Downloading file failed: {0} - {1}", media.Filename, ex.Message);
                    }
                    catch (Exception ex)
                    {
                        StatusMessage = string.Format("Error updating media: {0} -  {1}", media.Filename, ex.Message);
                    }

                    Lock.AcquireWriterLock(Timeout.Infinite);
                    Processed++;
                    PercentComplete = (Processed / Total) * 60;
                    StatusMessage   = string.Format("Processed file: {0}", media.Filename);
                    Lock.ReleaseWriterLock();
                }
                Lock.AcquireWriterLock(Timeout.Infinite);
                PercentComplete = 60;
                StatusMessage   = string.Format("Processed all files, commencing Content updates...");
                Lock.ReleaseWriterLock();

                await Database.SaveChangesAsync();

                // now we need to iterate through any items that may have media attached, and re-attach.
                // content
                // properties
                // app users

                foreach (var content in Database.Content)
                {
                    if (content.FeaturedImage != null)
                    {
                        var media = Database.Media.Find(content.FeaturedImage.Id);
                        content.FeaturedImage = new ContentMedia(media);
                        StatusMessage         = string.Format("Refreshing content featured image: {0} {1}", content.Id, content.Title);
                    }
                }
                await Database.SaveChangesAsync();

                Lock.AcquireWriterLock(Timeout.Infinite);
                PercentComplete = 70;
                StatusMessage   = string.Format("Content updated, commencing Properties updates...");
                Lock.ReleaseWriterLock();

                foreach (var property in Database.Properties)
                {
                    if (property.FeaturedImage != null)
                    {
                        property.FeaturedImage = Database.Media.Find(property.FeaturedImage.Id);
                        StatusMessage          = string.Format("Refreshing property featured image: {0} {1}", property.Id, property.Title);
                    }
                    if (property.InfoDownload != null)
                    {
                        property.FeaturedImage = Database.Media.Find(property.FeaturedImage.Id);
                        StatusMessage          = string.Format("Refreshing property info download: {0} {1}", property.Id, property.Title);
                    }
                }
                await Database.SaveChangesAsync();

                Lock.AcquireWriterLock(Timeout.Infinite);
                PercentComplete = 80;
                StatusMessage   = string.Format("Properties updated, commencing Users updates...");
                Lock.ReleaseWriterLock();

                foreach (var user in Database.Users)
                {
                    if (user.Avatar != null)
                    {
                        user.Avatar   = Database.Media.Find(user.Avatar.Id);
                        StatusMessage = string.Format("Refreshing user avatar: {0} {1}", user.Id, user.ToInternalName());
                    }
                }
                await Database.SaveChangesAsync();

                Lock.AcquireWriterLock(Timeout.Infinite);
                PercentComplete = 90;
                StatusMessage   = string.Format("All done, emailing results...");
                Lock.ReleaseWriterLock();

                MailObject message = new MailObject()
                {
                    PreHeader = "All media files have been refreshed.",
                    Subject   = "All media files have been refreshed."
                };
                message.AddH1("Complete!");
                message.AddParagraph("All media files have been successfully refreshed on " + _context.GetSiteUrl());

                IEmailSender emailSender = Engine.Services.Resolve <IEmailSender>();
                await emailSender.NotifyRoleAsync(message, "SuperUser");

                // Clean the temp directory...
                CleanTempFolder();

                Lock.AcquireWriterLock(Timeout.Infinite);
                PercentComplete = 100;
                Succeeded       = true;
                Running         = false;
                StatusMessage   = "Update completed at " + DateTime.UtcNow.ToShortTimeString() + " on " + DateTime.UtcNow.ToLongDateString() + ".";
                Lock.ReleaseWriterLock();

                return;
            }
            catch (Exception ex)
            {
                Lock.AcquireWriterLock(Timeout.Infinite);
                Running       = false;
                StatusMessage = ex.Message;
                Lock.ReleaseWriterLock();
                return;
            }
        }