Beispiel #1
0
        public async Task AddProfilePictureToUserAsync(string picUrl, string userName)
        {
            var user = await context.Users.FirstOrDefaultAsync(x => x.UserName == userName);

            user.ProfilePicture = new Picture
            {
                Url  = picUrl,
                Name = "ProfilePicture"
            };

            await context.SaveChangesAsync();
        }
        public async Task DeleteForumPostAsync(string id)
        {
            var post = await this.context.ForumPosts.FirstOrDefaultAsync(x => x.Id == id);

            this.context.ForumPosts.Remove(post);

            await context.SaveChangesAsync();
        }
Beispiel #3
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            if (this.User.Identity.IsAuthenticated)
            {
                return(this.Forbid());
            }

            returnUrl = returnUrl ?? Url.Content("~/");

            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = await _signInManager.PasswordSignInAsync(Input.Username, Input.Password, Input.RememberMe, lockoutOnFailure : false);

                if (this.HttpContext.Session.Keys.Contains("Cart"))
                {
                    this.HttpContext.Session.SetString("Cart", "empty");
                }

                if (result.Succeeded)
                {
                    var user = await this.context.Users.FirstOrDefaultAsync(x => x.UserName == Input.Username);

                    user.LastLoginDate = DateTime.UtcNow;
                    await context.SaveChangesAsync();


                    if (this.User.IsInRole("Admin"))
                    {
                        return(RedirectToAction("BlacksmithIndex", "Administratior", new { area = "Administration" }));
                    }

                    _logger.LogInformation("User logged in.");
                    return(LocalRedirect(returnUrl));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToPage("./Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");
                    return(Page());
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
        public async Task CreateCharacteristicsCategoryAsync(InsertCharacteristicsCategoryViewModel form)
        {
            await this.context.AdminCharacteristicsCategories.AddAsync(new AdminCharacteristicsCategory
            {
                CategoryName         = form.CategoryName,
                BasicCharacteristics = new List <AdminCharacteristic>(),
                FullCharacteristics  = new List <AdminCharacteristic>(),
            });

            await context.SaveChangesAsync();
        }