Beispiel #1
0
 public void Bind(Host host)
 {
     _host = host;
     if (_isClient)
     {
         host.AddHandler((short)AuthMType.ChalangeSuccess, SendPwdHash);
         host.AddHandler((short)AuthMType.ChalangeFailed, (m, e) => { if (OnAuthFailed != null)
                                                                      {
                                                                          OnAuthFailed.Invoke("Логин не найден");
                                                                      }
                         });
         host.AddHandler((short)AuthMType.AuthFailed, (m, e) => { if (OnAuthFailed != null)
                                                                  {
                                                                      OnAuthFailed.Invoke("Пароль не подошел");
                                                                  }
                         });
         host.AddHandler((short)AuthMType.AuthSuccess, (m, e) => { if (OnAuthSuccess != null)
                                                                   {
                                                                       OnAuthSuccess.Invoke();
                                                                   }
                         });
     }
     else
     {
         host.AddHandler((short)AuthMType.Chalange, ChalangeHandler);
         host.AddHandler((short)AuthMType.PwdHash, CheckHash);
     }
 }
Beispiel #2
0
        public bool Auth(string login, string password)
        {
            _session = SendApiRequest($"login={login}&password={password}", "auth", Session.FromJson);
            if (_session == null)
            {
                OnAuthFailed?.Invoke();
                return(false);
            }

            _session.User.Password = password;
            OnAuthSuccess?.Invoke();

            return(true);
        }
        void IOnCompleteListener.OnComplete(Task task)
        {
            if (task.IsSuccessful)
            {
                FirebaseUser user = Auth.CurrentUser;

                OnAuthSuccessful?.Invoke();
                Toast.MakeText(Activity, $"{Activity.Resources.GetString(Resource.String.firebase_auth_successful)}", ToastLength.Short).Show();
            }
            else
            {
                OnAuthFailed?.Invoke();
                Toast.MakeText(Activity, $"{Activity.Resources.GetString(Resource.String.firebase_auth_faild)}", ToastLength.Short).Show();
            }
        }
Beispiel #4
0
 public void LogOut()
 {
     OnAuthFailed?.Invoke();
 }
        public async Task <bool> GetAuthToken()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            int retriesRemaining = AuthRetries;

            try
            {
                while (sw.ElapsedMilliseconds / 1000L <= TimeoutSeconds)
                {
                    int num = 0;
                    try
                    {
                        AuthResult = await GetAuthResult().ConfigureAwait(false);

                        User  = AuthResult.User;
                        Token = AuthResult.Lqt.PartnerToken;
                        //await GetToken();
                        //this.UserId = this.AuthResult.Lqt.AccountId;
                    }
                    catch (IpBannedException ex)
                    {
                        Tools.Log(ex.StackTrace);
                        OnAuthFailed?.Invoke("Your IP has been banned due to too many requests.");
                        return(false);
                    }
                    catch (JsonReaderException ex)
                    {
                        Tools.Log(ex.StackTrace);
                        num = 1;
                    }
                    catch (Exception ex)
                    {
                        Tools.Log(ex.StackTrace);
                        Console.WriteLine(ex.StackTrace);
                    }
                    if (num == 1)
                    {
                        await Task.Delay(1000).ConfigureAwait(false);
                    }
                    else if (this.AuthResult.Reason == null && !this._useGarena)
                    {
                        if (retriesRemaining > 0)
                        {
                            --retriesRemaining;
                        }
                        else
                        {
                            OnAuthFailed?.Invoke("Unable to get Auth Token.");
                            return(false);
                        }
                    }
                    else if (this._useGarena)
                    {
                        if (this.AuthResult.Status == "LOGIN")
                        {
                            this.AuthToken = this.AuthResult.Lqt.ToString();
                            return(true);
                        }
                        await Task.Delay(1000).ConfigureAwait(false);
                    }
                    else
                    {
                        string reason = this.AuthResult.Reason;
                        if (!(reason == "attempt_rate_too_fast"))
                        {
                            if (!(reason == "invalid_credentials"))
                            {
                                if (!(reason == "account_banned"))
                                {
                                    if (!(reason == "account_transferred"))
                                    {
                                        if (!(reason == "account_inactive"))
                                        {
                                            if (reason == "server_full")
                                            {
                                                OnAuthFailed?.Invoke("Server is full. Try again later.");
                                                return(false);
                                            }
                                            if (AuthResult.Status == "QUEUE" && this.AuthResult.Tickers != null)
                                            {
                                                await WaitInQueue().ConfigureAwait(false);

                                                AuthResult.Lqt.Resources = null;
                                                AuthResult.Lqt.Other     = null;
                                                HttpResponseMessage httpResponseMessage = await _httpClient.PostAsync(_tokenUrl, AuthResult.Lqt.ToString(), true).ConfigureAwait(false);

                                                if (httpResponseMessage.StatusCode == HttpStatusCode.OK)
                                                {
                                                    AuthToken = JsonConvert.DeserializeObject <AuthResult>(await httpResponseMessage.Content.ReadAsStringAsync().ConfigureAwait(false)).Lqt.ToString();
                                                    return(true);
                                                }
                                            }
                                            if (AuthResult.Status == "LOGIN")
                                            {
                                                AuthToken = AuthResult.Lqt.ToString();
                                                return(true);
                                            }
                                            await Task.Delay(1000).ConfigureAwait(false);
                                        }
                                        else
                                        {
                                            OnAuthFailed?.Invoke("Account currently inactive.");
                                            return(false);
                                        }
                                    }
                                    else
                                    {
                                        OnAuthFailed?.Invoke(string.Format("Account transferred {0}", AuthResult.Destination).Trim());
                                        return(false);
                                    }
                                }
                                else
                                {
                                    DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddMilliseconds(AuthResult.Banned);
                                    OnAuthFailed?.Invoke(string.Format("Account banned {0}", dateTime.ToString("d", (IFormatProvider)CultureInfo.CurrentCulture)));
                                    return(false);
                                }
                            }
                            else
                            {
                                OnAuthFailed?.Invoke("Incorrect username or password.");
                                return(false);
                            }
                        }
                        else
                        {
                            OnUpdateStatusMessage?.Invoke(this, string.Format("Login rate too fast. Waiting {0} s.", AuthResult.RetryWait));
                            await Task.Delay(TimeSpan.FromSeconds(AuthResult.RetryWait)).ConfigureAwait(false);

                            sw.Restart();
                        }
                    }
                }
                sw.Stop();
                throw new TimeoutException();
            }
            catch (TimeoutException ex)
            {
                Tools.Log(ex.StackTrace);
                OnAuthFailed?.Invoke("Timeout: queue time too long.");
            }
            finally
            {
                sw.Stop();
            }
            return(false);
        }