public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new OnlineShopDuhootWebUser() /*UserName = model.UserName*/ }
                {
                    ;
                    user.Email          = model.Email;
                    user.EmailConfirmed = false;

                    user.UserName = user.Email;// Тк на данном сайте имя пользователя не указывается, то имя пользователя - это почта
                    var result = await userManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        messageSender.SendEmail("*****@*****.**", user.Email,
                                                "Email confirmation", "Web Registration", string.Format("Для завершения регистрации перейдите по ссылке:" +
                                                                                                        "<a href=\"{0}\" title=\"Подтвердить регистрацию\">{0}</a>",
                                                                                                        Url.Action("ConfirmEmail", "Account", new { Token = user.Id, user.Email }, Request.Scheme))
                                                );

                        return(RedirectToAction("Confirm", "Account", new { user.Email }));
                    }
                    else
                    {
                        // AddErrors(result);
                    }
            }
            return(View(model));
        }
        public async Task <ActionResult> ConfirmEmail(string Token, string Email)
        {
            OnlineShopDuhootWebUser user = await userManager.FindByIdAsync(Token);

            if (user != null)
            {
                if (user.Email == Email)
                {
                    user.EmailConfirmed = true;
                    await userManager.UpdateAsync(user);

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

                    return(RedirectToAction("Index", "Home", new { ConfirmedEmail = user.Email }));
                }
                else
                {
                    return(RedirectToAction("Confirm", "Account", new { user.Email }));
                }
            }
            else
            {
                return(RedirectToAction("Confirm", "Account", new { Email = "" }));
            }
        }
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl ??= Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new OnlineShopDuhootWebUser {
                    UserName = Input.Email, Email = Input.Email
                };
                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, returnUrl = returnUrl },
                        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 (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                OnlineShopDuhootWebUser user = await userManager.FindByNameAsync(model.UserName);

                if (user != null)
                {
                    await signInManager.SignOutAsync();

                    Microsoft.AspNetCore.Identity.SignInResult result = await signInManager.PasswordSignInAsync(user, model.Password, model.RememberMe, false /*TODO Добавить ограничения на вход*/);

                    if (result.Succeeded)
                    {
                        return(Redirect(returnUrl ?? "/"));
                    }
                }
                ModelState.AddModelError(nameof(LoginViewModel.UserName), "Неверный логин или пароль");
            }
            return(View(model));
        }