Skip to content

Commit

Permalink
#697 Бросаю ошибку при вводе неверного логина или пароля
Browse files Browse the repository at this point in the history
  • Loading branch information
inyutin-maxim committed Apr 7, 2019
1 parent ec34726 commit 8623969
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions VkNet/Utils/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public partial class Browser : IBrowser

private readonly ICaptchaSolver _captchaSolver;

private ushort LoginPasswordError { get; set; }

private const ushort MaxLoginPasswordError = 1;

/// <inheritdoc />
public Browser([CanBeNull] ILogger<Browser> logger,
IVkApiVersionManager versionManager,
Expand Down Expand Up @@ -166,13 +170,9 @@ private bool HasNotTwoFactor(Func<string> code, WebCallResult loginFormPostResul
/// </summary>
/// <param name="email"> Логин </param>
/// <param name="password"> Пароль </param>
/// <param name="captchaSid"> ИД капчи </param>
/// <param name="captchaKey"> Значение капчи </param>
/// <param name="authorizeUrlResult"> </param>
/// <returns> </returns>
private WebCallResult FilledLoginForm(string email
, string password
, WebCallResult authorizeUrlResult)
private WebCallResult FilledLoginForm(string email, string password, WebCallResult authorizeUrlResult)
{
var loginForm = WebForm.From(authorizeUrlResult)
.WithField("email")
Expand All @@ -191,9 +191,7 @@ private WebCallResult FilledLoginForm(string email
/// <param name="password"> Пароль </param>
/// <param name="authorizeUrlResult"> </param>
/// <returns> </returns>
private WebCallResult FilledCaptchaLoginForm(string email
, string password
, WebCallResult authorizeUrlResult)
private WebCallResult FilledCaptchaLoginForm(string email, string password, WebCallResult authorizeUrlResult)
{
var loginForm = WebForm.From(authorizeUrlResult)
.WithField("email")
Expand Down Expand Up @@ -414,6 +412,13 @@ private async Task<AuthorizationResult> NextStepAsync(WebCallResult formResult)
case ImplicitFlowPageType.LoginPassword:

{
LoginPasswordError++;

if (LoginPasswordError >= MaxLoginPasswordError)
{
throw new VkAuthorizationException("Неверный логин или пароль.");
}

_logger?.LogDebug("Ввод логина и пароля.");

resultForm = await FilledLoginFormAsync(_authParams.Login,
Expand Down Expand Up @@ -487,6 +492,13 @@ private AuthorizationResult NextStep(WebCallResult formResult)
case ImplicitFlowPageType.LoginPassword:

{
LoginPasswordError++;

if (LoginPasswordError >= MaxLoginPasswordError)
{
throw new VkAuthorizationException("Неверный логин или пароль.");
}

_logger?.LogDebug("Ввод логина и пароля.");

resultForm = FilledLoginForm(_authParams.Login,
Expand Down Expand Up @@ -531,6 +543,9 @@ private AuthorizationResult NextStep(WebCallResult formResult)
{
return _vkAuthorization.GetAuthorizationResult(formResult.ResponseUrl);
}
default:

throw new VkApiException("Не найден ни один тип для параметра " + nameof(pageType));
}

return NextStep(resultForm);
Expand Down

0 comments on commit 8623969

Please sign in to comment.