Пример #1
0
        public IObservable <AuthenticationResult> LogInFromCache()
        {
            Func <Task <AuthenticationResult> > f = async() =>
            {
                try
                {
                    var user = await loginManager.LoginFromCache(Address, ApiClient.GitHubClient);

                    var accountCacheItem = new AccountCacheItem(user);
                    usage.IncrementLoginCount().Forget();
                    await ModelService.InsertUser(accountCacheItem);

                    if (user != unverifiedUser.User)
                    {
                        IsLoggedIn = true;
                        return(AuthenticationResult.Success);
                    }
                    else
                    {
                        return(AuthenticationResult.VerificationFailure);
                    }
                }
                catch (AuthorizationException)
                {
                    return(AuthenticationResult.CredentialFailure);
                }
            };

            return(f().ToObservable());
        }
Пример #2
0
        IObservable <AuthenticationResult> LoginWithApiUser(UserAndScopes userAndScopes)
        {
            return(GetAuthenticationResultForUser(userAndScopes)
                   .SelectMany(result =>
            {
                if (result.IsSuccess())
                {
                    var accountCacheItem = new AccountCacheItem(userAndScopes.User);
                    usage.IncrementLoginCount().Forget();
                    return ModelService.InsertUser(accountCacheItem).Select(_ => result);
                }

                if (result == AuthenticationResult.VerificationFailure)
                {
                    return loginCache.EraseLogin(Address).Select(_ => result);
                }
                return Observable.Return(result);
            })
                   .ObserveOn(RxApp.MainThreadScheduler)
                   .Do(result =>
            {
                if (result.IsSuccess())
                {
                    SupportsGist = userAndScopes.Scopes?.Contains("gist") ?? true;
                    IsLoggedIn = true;
                }

                log.Info("Log in from cache for login '{0}' to host '{1}' {2}",
                         userAndScopes?.User?.Login ?? "(null)",
                         hostAddress.ApiUri,
                         result.IsSuccess() ? "SUCCEEDED" : "FAILED");
            }));
        }
 public Task IncrementLoginCount() => inner.IncrementLoginCount();