Exemple #1
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                if (_captchaService.Verify("login", model.Captcha))
                {
                    return(RedirectToLocal(returnUrl));
                }
                else
                {
                    ModelState.AddModelError("Captcha", "Doğrulama kodunu hatalı girdiniz");
                    return(View());
                }

            case SignInStatus.LockedOut:
                return(View("Çıkış"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
Exemple #2
0
        public async Task <IActionResult> Register(RegisterViewModel model, string returnUrl = null)
        {
            ViewData["ReturnUrl"] = returnUrl;

            if (_appSettings.HCaptcha.EnableHCaptcha)
            {
                string token     = Request.Form["h-captcha-response"];
                string ipAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();

                bool isTokenValid = await _captchaService.Verify(_appSettings.HCaptcha.Secret, token, ipAddress);

                if (!isTokenValid)
                {
                    return(View(model));
                }
            }

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, DateCreated = DateTime.Now, DateModified = DateTime.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 https://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    Dictionary <string, string> data = new Dictionary <string, string>(1);
                    data[nameof(callbackUrl)] = callbackUrl;
                    await _emailManager.SendEmailAsync(model.Email, "account.confirmregistration", data);

                    //await _signInManager.SignInAsync(user, isPersistent: false);
                    _logger.LogInformation(3, "User created a new account with password.");
                    return(RedirectToLocal(returnUrl));
                }
                AddErrors(result);
            }

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