Example #1
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid && model.Password == model.ConfirmPassword)
            {
                var user = new ChilledUser {
                    UserName = model.Name, Email = model.Email, Joined = DateTimeOffset.Now
                };

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Action("ConfirmEmail", "GemMaster", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    await _emailSender.SendEmailAsync(model.Email, "Confirm your account",
                                                      "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");

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

                    _logger.LogInformation(3, "User created a new account with password.");
                    await _userManager.ConfirmEmailAsync(user, code);

                    return(RedirectToAction(nameof(HomeController.Index), "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Example #2
0
        public void AddNewBlogPost(BlogGem blog, ChilledDbContext context, ChilledUser user)
        {
            var rss = context.RSSHeaders.FirstOrDefault(r => r.RSSNumber == blog.FeedId);

            context.BlogPosts.Add(new BlogPost()
            {
                Hashtags        = GetHashTags(blog.Hashtags),
                MarkdownContent = blog.MarkdownContent,
                Published       = blog.Published,
                RSSHeaderId     = rss.Id,
                SubTitle        = blog.Subtitle,
                Title           = blog.Title,
                Author          = user
            });
            context.SaveChanges();
        }
Example #3
0
        public async Task SavePictureToDatabase(PictureGemManagerViewModel gem, ChilledUser user, Paths paths, ChilledDbContext context)
        {
            var gemDB = new Gem()
            {
                Title       = gem.PictureMetadata.Title,
                CreatedBy   = user,
                GemType     = GemType.Picture,
                SummaryText = gem.PictureMetadata.SummaryText,
                PictureData = new Picture()
                {
                    HoverText   = gem.PictureMetadata.HoverText,
                    ArtistName  = gem.PictureMetadata.ArtistName,
                    ArtistLink  = gem.PictureMetadata.ArtistLink,
                    CreatedDate = DateTime.Now,
                    FileSize    = gem.PictureMetadata.PictureFile.Length
                }
            };

            context.Gems.Add(gemDB);
            context.SaveChanges();
            var filePath       = paths.PicturesDirectory;
            var fileFolder     = Path.Combine(filePath, gemDB.Id.ToString());
            var fileName       = gem.PictureMetadata.PictureFile.FileName;
            var filetype       = gem.PictureMetadata.PictureFile.ContentType;
            var fullyQualified = Path.Combine(fileFolder, fileName);

            Directory.CreateDirectory(fileFolder);
            using (var stream = new FileStream(fullyQualified, FileMode.CreateNew))
            {
                await gem.PictureMetadata.PictureFile.CopyToAsync(stream);

                stream.Flush();
            }
            gemDB.PictureData.Location = $"//{paths.URLPath}/uploads/pictures/{gemDB.Id}/{fileName}";
            gemDB.FilePath             = fullyQualified;
            context.SaveChanges();
        }