/// <summary>
 /// Requests to login with the account server.
 /// </summary>
 /// <param name="username">The username</param>
 /// <param name="password">The password</param>
 public void LoginAccount(Account.AccountLoginRequestModel requestModel)
 {
     if (_connection.BeginLoginAccount(requestModel) != BeginRequestStatusCode.Ok)
     {
         MessageBox.Show("There was an error processing your request; please try again later.");
     }
 }
Пример #2
0
        /// <summary>
        /// Starts the login procedure to the account server.
        ///
        /// When the response (if any) is received, the listeners associated with OnLoginAccountResponse will be notified.
        /// </summary>
        /// <param name="requestModel">Data model for the login request</param>
        /// <returns>true if successfully started; false otherwise</returns>
        public BeginRequestStatusCode BeginLoginAccount(Account.AccountLoginRequestModel requestModel)
        {
            if (requestModel == null)
            {
                throw new ArgumentNullException("requestModel");
            }

            // Create the login form
            requestModel.PasswordHash = CalculateHashFor(requestModel.PasswordHash);
            string jsonModel = JsonConvert.SerializeObject(requestModel);

            byte[] contentBody = Encoding.UTF8.GetBytes(jsonModel);

            // Create the request
            var request = (HttpWebRequest)WebRequest.Create(LoginUrl);

            request.Method        = "POST";
            request.ContentType   = "application/json";
            request.ContentLength = contentBody.Length;

            try
            {
                var stream = request.GetRequestStream();
                stream.Write(contentBody, 0, contentBody.Length);
            }
            catch (WebException)
            {
                return(BeginRequestStatusCode.Error);
            }

            // Off it goes!
            try
            {
                request.BeginGetResponse(AsyncLoginAccountResponse, request);
            }
            catch (Exception)
            {
                return(BeginRequestStatusCode.Error);
            }

            return(BeginRequestStatusCode.Ok);
        }