コード例 #1
0
        private async Task InvokeLogin()
        {
            var isLoggedIn = false;

            do
            {
                var loginData = await _dialogCordinator.ShowNtLogin(this);

                if (loginData == null)
                {
                    // User has cancelled Login, Should exist.
                    Application.Current.Shutdown();
                }

                IsBusy = true;
                var errorMsg = new NtRef <string>();
                isLoggedIn = await _currentUserService.Authenticate(loginData.Username, loginData.Password, errorMsg);

                IsBusy = false;
                if (!isLoggedIn)
                {
                    await _dialogCordinator.ShowNtOkDialog(this, "Authentication Failed", errorMsg);
                }
            }while (!isLoggedIn);

            _eventAggregator.PublishOnUIThread(new UserLoggedInMessage(this));
        }
コード例 #2
0
        public async Task <bool> Authenticate(string userName, string password, NtRef <string> errorMessage)
        {
            var request = new AuthenticateRequest
            {
                Password = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(password)),
                Username = userName
            };

            var httpService = IoC.Get <IHttpService>();
            var response    = await httpService.PostAsync <AuthenticateRequest, AuthenticateResponse>(HttpUtils.ValidateUserUrl, request)
                              .ConfigureAwait(false);

            if (response.HasError)
            {
                errorMessage.Value = response.Errors.First();
                return(false);
            }
            UserName    = response.UserName;
            DisplayName = response.DisplayName;
            Bio         = response.Bio;
            AuthToken   = response.AuthToken;
            return(true);
        }