Exemple #1
0
        /// <summary>
        /// Gets the <see cref="IEnumerable{T}"/> needed to use the <see cref="GetOperatorStats"/> extensions
        /// </summary>
        /// <param name="client">The <see cref="ApiClient"/> to use</param>
        public static IEnumerable <OperatorStats> GetOperatorInfo(this ApiClient client)
        {
            var request  = new OperatorInfoRequest();
            var response = client.Perform <JArray>(request);

            return(FromArray(response));
        }
Exemple #2
0
        public OperatorInfoResponse OperatorInfo(OperatorInfoRequest request)
        {
            Log.Information("LCManagerPartner OperatorInfo {Operator}", request.Operator);
            var result      = new ServerOperatorInfo();
            var returnValue = result.ProcessRequest(cnn, request);

            return(returnValue);
        }
Exemple #3
0
        public ActionResult Login(UserModel user, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                string     connectionString = ConfigurationManager.ConnectionStrings["Partner"].ConnectionString;
                HttpClient httpClient       = new HttpClient
                {
                    BaseAddress = new Uri(connectionString)
                };
                httpClient.DefaultRequestHeaders.Clear();
                httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                var pairs = new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("username", user.Login),
                    new KeyValuePair <string, string>("password", user.Password),
                    new KeyValuePair <string, string>("grant_type", "password")
                };

                var content = new FormUrlEncodedContent(pairs);

                Log.Information("LCManagerUI. Send auth request for user:{login}", user.Login);
                HttpResponseMessage responseMessage = httpClient.PostAsync("ManagerLogin", content).Result;
                Log.Information("LCManagerUI. Response message IsSuccessStatusCode={state}", responseMessage.IsSuccessStatusCode);
                if (responseMessage.IsSuccessStatusCode)
                {
                    Token token = responseMessage.Content.ReadAsAsync <Token>().Result;
                    #region Обязательно записываем токен в куки
                    Response.SetCookie(new HttpCookie("lcmanager_token")
                    {
                        Value   = token.access_token,
                        Expires = DateTime.Now.AddDays(Convert.ToInt32(ConfigurationManager.AppSettings["jwt_token_cookie_expiration"]))
                    });
                    #endregion

                    Log.Information("LCManagerUI. Set refresh_token to cookie. Token = {token}", token.refresh_token);
                    #region Записываем refresh_token в куки
                    Response.SetCookie(new HttpCookie("lcmanager_refresh_token")
                    {
                        Value   = token.refresh_token,
                        Expires = DateTime.Now.AddDays(Convert.ToInt32(ConfigurationManager.AppSettings["jwt_refresh_token_cookie_expiration"]))
                    });
                    #endregion

                    #region Получаем информацию об операторе и записываем в куки
                    OperatorInfoRequest operatorInfoRequest = new OperatorInfoRequest
                    {
                        Operator = JwtProps.GetOperator()
                    };

                    HttpResponseMessage httpResponseMessage = HttpClientService.PostAsync("api/values/OperatorInfo", operatorInfoRequest).Result;
                    if (httpResponseMessage.IsSuccessStatusCode)
                    {
                        OperatorInfoResponse operatorInfoResponse = httpResponseMessage.Content.ReadAsAsync <OperatorInfoResponse>().Result;
                        Response.SetCookie(new HttpCookie("operatorName")
                        {
                            Value   = operatorInfoResponse.OperatorName,
                            Expires = DateTime.Now.AddDays(365)
                        });
                    }
                    #endregion
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(user));
        }