Exemplo n.º 1
0
        public static IDisposable BindProxySettings(
            this AuthenticationModel model,
            IPopupController popupController)
        {
            model.SetProxyCommand = ReactiveCommand.Create(
                () => popupController.Show(new ProxyPopupContext()),
                null,
                RxApp.MainThreadScheduler);

            return(Disposable.Empty);
        }
        private static void HandleState(AuthenticationModel model, TdApi.AuthorizationState state)
        {
            switch (state)
            {
            case TdApi.AuthorizationState.AuthorizationStateWaitPhoneNumber _:
                OnWaitingPhoneNumber(model);
                break;

            case TdApi.AuthorizationState.AuthorizationStateWaitCode wait:
                OnWaitingConfirmCode(model, !wait.IsRegistered);
                break;

            case TdApi.AuthorizationState.AuthorizationStateWaitPassword _:
                OnWaitingPassword(model);
                break;
            }
        }
Exemplo n.º 3
0
        private bool IsPhoneValid(AuthenticationModel model, string phone)
        {
            if (string.IsNullOrWhiteSpace(phone))
            {
                return(false);
            }

            var mask = model.PhoneCode?.Mask;

            if (string.IsNullOrWhiteSpace(mask))
            {
                return(!string.IsNullOrWhiteSpace(phone));
            }

            return(phone.All(c => char.IsDigit(c) || char.IsWhiteSpace(c)) &&
                   phone.Count(char.IsDigit) == mask.Count(c => !char.IsWhiteSpace(c)));
        }
        public static IDisposable BindAuthentication(
            this AuthenticationModel model,
            IAuthenticator authenticator)
        {
            var canSendCode = model
                              .WhenAnyValue(x => x.PhoneNumber)
                              .Select(phone => !string.IsNullOrWhiteSpace(phone));

            var canCheckCode = model
                               .WhenAnyValue(x => x.ConfirmCode)
                               .Select(code => !string.IsNullOrWhiteSpace(code));

            var canCheckPassword = model
                                   .WhenAnyValue(x => x.Password)
                                   .Select(password => !string.IsNullOrWhiteSpace(password));

            model.SendCodeCommand = ReactiveCommand.CreateFromObservable(
                (AuthenticationModel m) => SendCode(authenticator, m.PhoneNumber),
                canSendCode,
                RxApp.MainThreadScheduler);

            model.CheckCodeCommand = ReactiveCommand.CreateFromObservable(
                (AuthenticationModel m) => CheckCode(authenticator, m.ConfirmCode, m.FirstName, m.LastName),
                canCheckCode,
                RxApp.MainThreadScheduler);

            model.CheckPasswordCommand = ReactiveCommand.CreateFromObservable(
                (AuthenticationModel m) => CheckPassword(authenticator, m.Password),
                canCheckPassword,
                RxApp.MainThreadScheduler);

            return(authenticator.ObserveState()
                   .SubscribeOn(RxApp.TaskpoolScheduler)
                   .ObserveOn(RxApp.MainThreadScheduler)
                   .Accept(state => HandleState(model, state)));
        }
 private static void OnWaitingPassword(AuthenticationModel model)
 {
     model.ConfirmIndex  = 1;
     model.PasswordIndex = 1;
 }
 private static void OnWaitingPhoneNumber(AuthenticationModel model)
 {
     model.ConfirmIndex  = 0;
     model.PasswordIndex = 0;
 }
Exemplo n.º 7
0
 private void HandlePhoneCodeChange(AuthenticationModel model, PhoneCodeModel phoneCode)
 {
     model.PhoneNumber = FormatPhone(model.PhoneNumber, phoneCode?.Mask);
 }
Exemplo n.º 8
0
 private void HandlePhoneChange(AuthenticationModel model, string phone)
 {
     // TODO: does not update
     model.PhoneNumber = FormatPhone(phone, model.PhoneCode?.Mask);
 }