예제 #1
0
파일: Rider.cs 프로젝트: Cycli/Cycli
        public bool RequestAuthorisation(string UserName, SecureString Password)
        {
            bool loggedIn = false;

            HttpClient httpClient = new HttpClient() { BaseAddress = new Uri(Properties.Settings.Default.CycliUrl) };
            httpClient.Timeout = new TimeSpan(0, 0, 0, 15, 0);
            UserCredentials u = new UserCredentials();
            // ############ DEBUG ///////
            u.username = UserName;
            u.password = ConvertToUnsecureString(Password);
            Console.WriteLine("Authorising " + u.username);
            try
            {
                // Getting the lease will kick off a recipient process at the server
                var response = httpClient.PostAsJsonAsync<UserCredentials>("api/credential/CheckUser/", u).Result;
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    loggedIn = response.Content.ReadAsAsync<bool>().Result;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Authorising " + u.username + "Connection failed");
            }
            return loggedIn;
        }
예제 #2
0
파일: Rider.cs 프로젝트: Cycli/Cycli
        public void RequestLease(string UserName, SecureString Password)
        {
            // Danger here!  It might be possible to kick off multiple
            // Lease requests before the server has time to respond
            // This way to disaster!
            // This monitor will prevent multiple calls by passing
            // through if we're already requesting a lease
            if (Monitor.TryEnter(_outputDatum))
            {

                HttpClient httpClient = new HttpClient() { BaseAddress = new Uri(Properties.Settings.Default.CycliUrl) };
                UserCredentials u = new UserCredentials();
                // ############ DEBUG ///////
                u.username = UserName;
                u.password = ConvertToUnsecureString(Password);
                Console.WriteLine("Authorising " + u.username);
                // Getting the lease will kick off a recipient process at the server
                var response = httpClient.PostAsJsonAsync<UserCredentials>("api/credential/getlease/", u)
                    .ContinueWith(p => LeaseReceived(p.Result), System.Threading.Tasks.TaskContinuationOptions.NotOnFaulted);
            }
        }