Ejemplo n.º 1
0
        public RequestSignInViewModel(IUserAccountManager manager, TaskCompletionSource <bool> source, string text)
        {
            _source = source;
            Text    = text;
            CreateAccountCommand = new RelayCommand(async args =>
            {
                taskCompletionSource.SetResult(true);
                source.SetResult(await manager.RegisterAsync());
            });

            SignInCommand = new RelayCommand(async args =>
            {
                taskCompletionSource.SetResult(true);
                source.SetResult(await manager.LoginAsync());
            });
        }
Ejemplo n.º 2
0
        public LoginViewModel(IUserAccountManager manager, PanaceaServices core, TaskCompletionSource <bool> source)
        {
            _core   = core;
            _source = source;
            if (Debugger.IsAttached)
            {
                Email = "*****@*****.**";
            }
            ForgotPasswordCommand = new RelayCommand(async arg =>
            {
                if (_core.TryGetUiManager(out IUiManager ui))
                {
                    var src = new TaskCompletionSource <bool>();
                    var forgotPassViewModel = new ForgotPasswordViewModel(_core, src);
                    _watingForAnotherTask   = true;
                    ui.Navigate(forgotPassViewModel);
                    var res = await src.Task;
                    if (_core.TryGetUiManager(out IUiManager ui2))
                    {
                        ui2.GoHome();
                    }
                    source.SetResult(res);
                }
                else
                {
                    _core.Logger.Error(this, "ui manager not loaded");
                }
            });
            RegisterCommand = new RelayCommand(async arg =>
            {
                _watingForAnotherTask = true;
                source.SetResult(await manager.RegisterAsync());
            });
            LoginWithDateCommand = new AsyncCommand(async arg =>
            {
                try
                {
                    var password = (arg as PasswordBox).Password;
                    if (string.IsNullOrEmpty(Date.ToString()))
                    {
                        ShowWarning("Please provide a date of birth");
                        return;
                    }
                    if (string.IsNullOrEmpty(password))
                    {
                        ShowWarning("Please provide a password");
                        return;
                    }
                    if (await DoWhileBusy(() => core.UserService.LoginAsync(Date.Value, password)))
                    {
                        if (_core.TryGetUiManager(out IUiManager ui))
                        {
                            ui.GoHome();
                        }
                        source?.SetResult(true);
                        return;
                    }
                    else
                    {
                        ShowWarning("Incorrect credentials");
                        return;
                    }
                }
                catch
                {
                }
                finally
                {
                }
            });
            LoginWithEmailCommand = new AsyncCommand(async arg =>
            {
                var password = (arg as PasswordBox).Password;

                if (string.IsNullOrEmpty(Email))
                {
                    ShowWarning("Please provide an email");
                    return;
                }

                if (!Regex.IsMatch(Email,
                                   @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z",
                                   RegexOptions.IgnoreCase))
                {
                    ShowWarning("Please provide a valid email");
                    return;
                }

                if (string.IsNullOrEmpty(password))
                {
                    ShowWarning("Please provide a password");
                    return;
                }

                if (await DoWhileBusy(() => core.UserService.LoginAsync(Email, password)))
                {
                    if (_core.TryGetUiManager(out IUiManager ui))
                    {
                        ui.GoHome();
                    }
                    source?.SetResult(true);
                    return;
                }
                else
                {
                    ShowWarning("Incorrect credentials", PopupType.Error);
                    return;
                }
            });
        }