コード例 #1
0
        public void EnsureAuthenticated()
        {
            var computerInfo = _computerInfoService.GetComputerInfo();

            if (computerInfo.PersistentData.SessionId != null && computerInfo.PersistentData.SecretKey != null)
            {
                // Check if the existing session is still valid.
                var authInfo = _jamHostApiService.ValidateSession();
                if (authInfo.IsValid)
                {
                    // Already authenticated.
                    _userInfo.Authenticated = true;
                    _userInfo.FullName      = authInfo.FullName;
                    _userInfo.Email         = authInfo.EmailAddress;
                    _userInfo.AccountType   = authInfo.AccountType;
                    return;
                }
            }

            AuthForm way = new AuthForm(_siteInfo.GetSiteInfo(), _imageService, _jamHostApiService, _computerInfoService);

            if (way.ShowDialog() != DialogResult.OK)
            {
                Environment.Exit(1);
            }

            _userInfo.Authenticated = true;
            _userInfo.FullName      = way.AuthResult.FullName;
            _userInfo.Email         = way.AuthResult.EmailAddress;
            _userInfo.AccountType   = way.AuthResult.AccountType;

            way.Dispose();
            GC.Collect();
        }
コード例 #2
0
        public AuthInfo ValidateSession()
        {
            try
            {
                var siteInfo     = _siteInfoService.GetSiteInfo();
                var computerInfo = _computerInfoService.GetComputerInfo();

                var url    = siteInfo.Url + @"jamcast/api/validatesession?_domain=" + siteInfo.Id;
                var client = new WebClient();

                var result = client.UploadValues(url, "POST", new NameValueCollection
                {
                    { "sessionId", computerInfo.PersistentData.SessionId },
                    { "secretKey", computerInfo.PersistentData.SecretKey }
                });

                var resultParsed = JsonConvert.DeserializeObject <dynamic>(Encoding.ASCII.GetString(result));
                var hasError     = (bool?)resultParsed.has_error;
                if (hasError.HasValue && hasError.Value)
                {
                    return(new AuthInfo
                    {
                        IsValid = false,
                        Error = (string)resultParsed.error
                    });
                }

                return(new AuthInfo
                {
                    IsValid = true,
                    FullName = (string)resultParsed.result.fullName,
                    EmailAddress = (string)resultParsed.result.email,
                    SessionId = (string)resultParsed.result.sessionId,
                    SecretKey = (string)resultParsed.result.secretKey,
                    AccountType = (string)resultParsed.result.accountType
                });
            }
            catch (Exception ex)
            {
                return(new AuthInfo
                {
                    IsValid = false,
                    Error = ex.ToString()
                });
            }
        }
コード例 #3
0
        public void ReportMacAddress()
        {
            try
            {
                var computer = _computerInfo.GetComputerInfo();

                foreach (var mac in computer.HwAddresses)
                {
                    _jamHostApiService.ReportMacAddressInformation(
                        computer.Host,
                        mac.ToString(),
                        string.Join(",", computer.IpAddresses.Select(i => i.ToString())));
                }
            }
            catch (Exception ex)
            {
                // Do nothing.
            }
        }
コード例 #4
0
        private void _login_Click(object sender, System.EventArgs e)
        {
            _emailAddress.Enabled = false;
            _password.Enabled     = false;
            _login.Enabled        = false;
            _login.Text           = "Logging in...";

            var emailAddress = _emailAddress.Text;
            var password     = _password.Text;

            var needsToFinalize = true;

            Task.Run(() =>
            {
                try
                {
                    var authenticated = _jamHostApiService.Authenticate(emailAddress, password, _computerInfoService.GetComputerInfo().Host);
                    if (authenticated.IsValid)
                    {
                        _computerInfoService.SetSessionInformation(authenticated.SessionId, authenticated.SecretKey);

                        AuthResult = authenticated;
                        this.Invoke(new Action(() =>
                        {
                            this.DialogResult = DialogResult.OK;
                            this.Close();
                            needsToFinalize = false;
                        }));
                    }
                    else
                    {
                        this.Invoke(new Action(() =>
                        {
                            _emailAddress.Enabled = true;
                            _password.Enabled     = true;
                            _login.Enabled        = true;
                            _login.Text           = "Login";
                            _error.Text           = authenticated.Error;
                        }));
                    }
                }
                catch (Exception ex)
                {
                    this.Invoke(new Action(() =>
                    {
                        _error.Text = ex.Message;
                    }));
                }
                finally
                {
                    if (needsToFinalize)
                    {
                        this.Invoke(new Action(() =>
                        {
                            _emailAddress.Enabled = true;
                            _password.Enabled     = true;
                            _login.Enabled        = true;
                            _login.Text           = "Login";
                        }));
                    }
                }
            });
        }