protected LoginManagerTest()
            {
                LoginManager = new LoginManager(ApiFactory, Database, TimeService, Scheduler);

                Api.User.Get().Returns(Observable.Return(User));
                ApiFactory.CreateApiWith(Arg.Any <Credentials>()).Returns(Api);
                Database.Clear().Returns(Observable.Return(Unit.Default));
            }
Beispiel #2
0
        public IObservable <ITogglDataSource> Login(Email email, string password)
        {
            if (!email.IsValid)
            {
                throw new ArgumentException("A valid email must be provided when trying to Login");
            }
            Ensure.Argument.IsNotNullOrWhiteSpaceString(password, nameof(password));

            var credentials = Credentials.WithPassword(email, password);

            return(database
                   .Clear()
                   .SelectMany(_ => apiFactory.CreateApiWith(credentials).User.Get())
                   .Select(User.Clean)
                   .SelectMany(database.User.Create)
                   .Select(dataSourceFromUser));
        }
Beispiel #3
0
        public IObservable <ITogglDataSource> Login(Email email, Password password)
        {
            if (!email.IsValid)
            {
                throw new ArgumentException($"A valid {nameof(email)} must be provided when trying to login");
            }
            if (!password.IsValid)
            {
                throw new ArgumentException($"A valid {nameof(password)} must be provided when trying to login");
            }

            var credentials = Credentials.WithPassword(email, password);

            return(database
                   .Clear()
                   .SelectMany(_ => apiFactory.CreateApiWith(credentials).User.Get())
                   .Select(User.Clean)
                   .SelectMany(database.User.Create)
                   .Select(dataSourceFromUser)
                   .Do(shortcutCreator.OnLogin));
        }
Beispiel #4
0
        public IObservable <ITogglDataSource> Login(Email email, Password password)
        {
            if (!email.IsValid)
            {
                throw new ArgumentException($"A valid {nameof(email)} must be provided when trying to login");
            }
            if (!password.IsValid)
            {
                throw new ArgumentException($"A valid {nameof(password)} must be provided when trying to login");
            }

            var credentials = Credentials.WithPassword(email, password);

            return(database
                   .Clear()
                   .SelectMany(_ => apiFactory.CreateApiWith(credentials).User.Get())
                   .Select(User.Clean)
                   .SelectMany(database.User.Create)
                   .Select(dataSourceFromUser)
                   .Do(shortcutCreator.OnLogin)
                   .Track <ITogglDataSource, LoginSignupAuthenticationMethod, UserIsMissingApiTokenException>(
                       analyticsService.UserIsMissingApiToken,
                       LoginSignupAuthenticationMethod.Login)
                   .RetryWhenUserIsMissingApiToken(scheduler));
        }
Beispiel #5
0
        public override async Task Initialize()
        {
            await base.Initialize();

            allCountries = await new GetAllCountriesInteractor().Execute();

            var api = apiFactory.CreateApiWith(Credentials.None);

            getCountrySubscription = new GetCurrentLocationInteractor(api)
                                     .Execute()
                                     .Select(location => allCountries.Single(country => country.CountryCode == location.CountryCode))
                                     .Subscribe(
                setCountryIfNeeded,
                _ => setCountryErrorIfNeeded(),
                () =>
            {
                getCountrySubscription?.Dispose();
                getCountrySubscription = null;
            }
                );
        }
        public override async Task Initialize(CredentialsParameter parameter)
        {
            await base.Initialize(parameter);

            emailSubject.OnNext(parameter.Email);
            passwordSubject.OnNext(parameter.Password);

            allCountries = await new GetAllCountriesInteractor().Execute();

            var api = apiFactory.CreateApiWith(Credentials.None);

            getCountrySubscription = new GetCurrentLocationInteractor(api)
                                     .Execute()
                                     .Select(location => allCountries.First(country => country.CountryCode == location.CountryCode))
                                     .Subscribe(
                setCountryIfNeeded,
                _ => setCountryErrorIfNeeded(),
                () =>
            {
                getCountrySubscription?.Dispose();
                getCountrySubscription = null;
            }
                );
        }