public async Task <IActionResult> Login(LoginModel model) { if (ModelState.IsValid) { if (captcha.IsForbid(Guid.Empty, model.Email)) { model.ErrorMessage = "Превышено число попыток, попробуйте позже"; ModelState.AddModelError("", "Превышено число попыток, попробуйте позже"); return(View(model)); } var hashPassword = cryptoService.EncryptSHA256(model.Password); var user = await db.Users.FirstOrDefaultAsync(u => u.Email == model.Email && u.Password == hashPassword); if (user != null) { await Authenticate(model.Email, user.Id).ConfigureAwait(true); return(model.ReturnUrl.IsNullOrWhitespace() ? (IActionResult)RedirectToAction("Index", "Home") : Redirect(model.ReturnUrl)); } captcha.IncrementForbid(Guid.Empty, model.Email); ModelState.AddModelError("", "Некорректные логин и(или) пароль"); model.ErrorMessage = "Некорректные логин и(или) пароль"; } return(View(model)); }
public async Task <ActionResult> YandexAuthorize(YandexAuthorizeForm authorizeForm, Guid sessionId) { if (captcha.IsForbid(UserId, "Yandex")) { return(View("YandexAuthorize", new YandexAuthorizeForm { Login = authorizeForm.Login, Forbid = true })); } var success = await yandexService.CheckCredentialsAsync(authorizeForm.Login, authorizeForm.Pass) .ConfigureAwait(true); Response.SetCookies(Constants.YaLoginCookie, authorizeForm.Login ?? string.Empty); if (!success) { captcha.IncrementForbid(UserId, "Yandex"); return(View("YandexAuthorize", new YandexAuthorizeForm { Login = authorizeForm.Login, AuthFailed = true })); } var authInfo = authorizationSettings.GetCachedMuserAuthorization(UserId); if (authInfo == null) { authInfo = new MuserAuthorization { YaLogin = authorizeForm.Login, YaPassword = authorizeForm.Pass }; } else { authInfo.YaLogin = authorizeForm.Login; authInfo.YaPassword = authorizeForm.Pass; } authorizationSettings.SetMuserAuthorization(authInfo, UserId); return(await GetYaPlaylists(sessionId).ConfigureAwait(true)); }