Exemplo n.º 1
0
        public async Task <IActionResult> RssAsync()
        {
            var objGeneralSettings = await _GeneralSettingsService.GetGeneralSettingsAsync();

            var feed = new SyndicationFeed(objGeneralSettings.ApplicationName, objGeneralSettings.ApplicationName, new Uri(GetBaseUrl()), "RSSUrl", DateTime.Now);

            feed.Copyright = new TextSyndicationContent($"{DateTime.Now.Year} {objGeneralSettings.ApplicationName}");
            var items = new List <SyndicationItem>();

            var postings = _BlazorBlogsContext.Blogs.OrderByDescending(x => x.BlogDate);

            foreach (var item in postings)
            {
                string BlogURL     = $"{GetBaseUrl()}/ViewBlogPost/{item.BlogId}";
                var    postUrl     = Url.Action("Article", "Blog", new { id = BlogURL }, HttpContext.Request.Scheme);
                var    title       = item.BlogTitle;
                var    description = SyndicationContent.CreateHtmlContent(item.BlogSummary.Replace("  ", " "));
                items.Add(new SyndicationItem(title, description, new Uri(BlogURL), item.BlogId.ToString(), item.BlogDate));
            }

            feed.Items = items;

            var settings = new XmlWriterSettings
            {
                Encoding            = Encoding.UTF8,
                NewLineHandling     = NewLineHandling.Entitize,
                NewLineOnAttributes = true,
                Indent = true
            };

            using (var stream = new MemoryStream())
            {
                using (var xmlWriter = XmlWriter.Create(stream, settings))
                {
                    var rssFormatter = new Rss20FeedFormatter(feed, false);
                    rssFormatter.WriteTo(xmlWriter);
                    xmlWriter.Flush();
                }

                return(File(stream.ToArray(), "application/rss+xml; charset=utf-8"));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpgradeAsync(
            IFormFile file, string FileTitle)
        {
            try
            {
                if (HttpContext.Request.Form.Files.Any())
                {
                    // Only accept .zip files
                    if (file.ContentType == "application/x-zip-compressed")
                    {
                        string UploadPath =
                            Path.Combine(
                                environment.ContentRootPath,
                                "Uploads");

                        string UploadPathAndFile =
                            Path.Combine(
                                environment.ContentRootPath,
                                "Uploads",
                                "BlazorBlogsUpgrade.zip");

                        string UpgradePath = Path.Combine(
                            environment.ContentRootPath,
                            "Upgrade");

                        // Upload Upgrade package to Upload Folder
                        if (!Directory.Exists(UpgradePath))
                        {
                            Directory.CreateDirectory(UpgradePath);
                        }

                        using (var stream =
                                   new FileStream(UploadPathAndFile, FileMode.Create))
                        {
                            await file.CopyToAsync(stream);
                        }

                        DeleteFiles(UpgradePath);

                        // Unzip files to Upgrade folder
                        ZipFile.ExtractToDirectory(UploadPathAndFile, UpgradePath, true);

                        #region Check upgrade - Get current version
                        Version objVersion      = new Version();
                        var     GeneralSettings = await generalSettingsService.GetGeneralSettingsAsync();

                        objVersion.VersionNumber = GeneralSettings.VersionNumber;
                        #endregion

                        #region Examine the manifest file
                        objVersion = ReadManifest(objVersion, UpgradePath);

                        try
                        {
                            if (objVersion.ManifestLowestVersion == "")
                            {
                                // Delete the files
                                DeleteFiles(UpgradePath);
                                return(Ok("Error: could not find manifest"));
                            }
                        }
                        catch (Exception ex)
                        {
                            return(Ok(ex.ToString()));
                        }
                        #endregion

                        #region Show error if needed and delete upgrade files
                        if
                        (
                            (ConvertToInteger(objVersion.VersionNumber) > ConvertToInteger(objVersion.ManifestHighestVersion)) ||
                            (ConvertToInteger(objVersion.VersionNumber) < ConvertToInteger(objVersion.ManifestLowestVersion))
                        )
                        {
                            // Delete the files
                            DeleteFiles(UpgradePath);

                            // Return the error response
                            return(Ok(objVersion.ManifestFailure));
                        }
                        #endregion

                        // Proceed with upgrade...

                        DeleteFiles(UpgradePath);

                        // Unzip files to final paths
                        ZipFile.ExtractToDirectory(UploadPathAndFile, environment.ContentRootPath, true);

                        Task.Delay(4000).Wait(); // Wait 4 seconds with blocking
                    }
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }

            return(Ok());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            var GeneralSettings = await _generalSettingsService.GetGeneralSettingsAsync();

            if (GeneralSettings.AllowRegistration)
            {
                returnUrl      = returnUrl ?? Url.Content("~/");
                ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
                if (ModelState.IsValid)
                {
                    var user = new ApplicationUser {
                        UserName = Input.Email, Email = Input.Email, NewsletterSubscriber = true
                    };
                    var result = await _userManager.CreateAsync(user, Input.Password);

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User created a new account with password.");

                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                        var callbackUrl = Url.Page(
                            "/Account/ConfirmEmail",
                            pageHandler: null,
                            values: new { area = "Identity", userId = user.Id, code = code },
                            protocol: Request.Scheme);

                        await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                          $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                        if (GeneralSettings.VerifiedRegistration)
                        {
                            return(RedirectToPage("RegisterConfirmation", new { email = Input.Email }));
                        }
                        else
                        {
                            // Set confirm Email for user
                            user.EmailConfirmed = true;
                            await _userManager.UpdateAsync(user);

                            // Log user in
                            await _signInManager.SignInAsync(user, isPersistent : false);

                            return(LocalRedirect(returnUrl));
                        }
                    }
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Registration Not Allowed in Administration Settings");
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }