private void DoResetPassword(object parameter)
        {
            ResetPasswordModel resetPasswordModel;

            if (!IsFormValid(parameter, out resetPasswordModel))
            {
                return;
            }

            Loading      = true;
            ErrorMessage = "";
            Task.Run(async() =>
            {
                try
                {
                    await _userClient.ResetPassword(resetPasswordModel);
                    var userDetails = await _userClient.GetCurrentUserDetails();
                    MainVm.Login(this, userDetails);

                    Ui(() =>
                    {
                        Loading = false;
                        ResetForm(parameter);
                    });
                }
                catch (BadRequestException e)
                {
                    Ui(() =>
                    {
                        ErrorMessage = e.Message;
                        Loading      = false;
                    });
                }
                catch (ApiException)
                {
                    Ui(() =>
                    {
                        ErrorMessage = "An Unknown Error Occurred";
                        Loading      = false;
                    });
                }
            });
        }
Example #2
0
        private void DoLogin(object parameter)
        {
            LoginModel loginModel;

            if (!IsFormValid(parameter, out loginModel))
            {
                return;
            }

            MainVm.LoggedIn = false;
            Loading         = true;
            ErrorMessage    = "";
            Task.Run(async() =>
            {
                try
                {
                    // Verify email first
                    if (ShowConfirmEmail)
                    {
                        var model = new VerifyEmailModel(Email, EmailToken);
                        await _userClient.VerifyEmail(model);
                    }
                    await _userClient.LoginAsync(loginModel.Email, loginModel.Password);

                    var details = await _userClient.GetCurrentUserDetails();
                    MainVm.Login(this, details);

                    ShowConfirmEmail = false;
                    Loading          = false;
                    Email            = "";
                }
                catch (IncorrectLoginException)
                {
                    Ui(() =>
                    {
                        ErrorMessage = "Invalid Username or Password";
                        Loading      = false;
                    });
                }
                catch (EmailVerificationNeededException)
                {
                    Ui(() =>
                    {
                        ShowConfirmEmail = true;
                        ErrorMessage     =
                            "This email is unconfirmed. Please enter the verification token sent to this email.";
                        Loading = false;
                    });
                }
                catch (UnauthorizedException)
                {
                    Ui(() =>
                    {
                        ErrorMessage = "Invalid Token";
                        Loading      = false;
                    });
                }
                catch (ApiException e)
                {
                    Ui(() =>
                    {
                        ErrorMessage = "An Unknown Error Occurred";
                        Loading      = false;
                    });
                }
            });
        }