private OkObjectResult GetCashBoxesData(DtoToken dtoToken) { var user = _userManager.Users.FirstOrDefault(i => i.UserToken == dtoToken.Token); var kkm = _applicationContext.Kkms.First(k => k.Id == user.KkmId); var shiftNumber = 1; if (_applicationContext.Shifts.Any(s => s.KkmId == kkm.Id)) { shiftNumber = _applicationContext.Shifts.Last().Number; } var wrapper = new Wrapper { Data = new Data { List = new List <List> { new List { UniqueNumber = kkm.SerialNumber, RegistrationNumber = kkm.FnsKkmId, IdentificationNumber = kkm.DeviceId.ToString(), Name = kkm.Name, IsOffline = false, CurrentStatus = 1, Shift = shiftNumber } } } }; return(Ok(JsonConvert.SerializeObject(wrapper))); }
public ActionResult Get([FromBody] DtoToken dtoToken) { try { Log.Information("Cashbox|Post"); Log.Information($"Получение списка касс пользователя: {_userManager}"); var caseError = _validationHelper.TokenValidator(_userManager, dtoToken.Token); if (caseError == 0) { return(GetCashBoxesData(dtoToken)); } return(Json(_errorHelper.GetErrorRequest((int)caseError))); } catch (UserNullException) { return(Ok(_errorHelper.GetErrorRequest((int)ErrorEnums.UNKNOWN_ERROR))); } catch (Exception e) { Log.Error($"Неизвестная ошибка: {e.StackTrace}"); return(Ok(_errorHelper.GetErrorRequest((int)ErrorEnums.UNKNOWN_ERROR))); } }
public DtoToken Get(string username, string password) { var token = new DtoToken(); _client.BaseUrl = _baseUrl ?? new Uri(HttpContext.Current.Request.Cookies["toemsBaseUrl"].Value); _request.Method = Method.POST; _request.Resource = string.Format("{0}", _resource); _request.AddParameter("grant_type", "password"); _request.AddParameter("userName", username); _request.AddParameter("password", password); var response = _client.Execute <DtoToken>(_request); if (response == null) { _log.Error("Could Not Complete Token Request. The Response was empty." + _request.Resource); token.error_description = "Did Not Receive A Response From The Auth Server."; return(token); } if (response.Data != null) { token = response.Data; } if (response.ErrorException != null) { _log.Error("Error Obtaining Token: " + response.ErrorException); } switch (response.StatusCode) { case HttpStatusCode.OK: break; case HttpStatusCode.NotFound: case 0: token.error_description = "Could Not Contact API"; break; case HttpStatusCode.BadRequest: token.error_description = JsonConvert.DeserializeObject <DtoToken>(response.Content).error_description; break; default: token.error_description = "Unknown Error Obtaining Token"; _log.Error("Error Obtaining Token: " + response.Content); break; } return(token); }
public TestServiceOne(DtoToken dtoToken) { _dtoToken = dtoToken; }
public BllResponse Login([FromBody] DtoLogin loginModel) { try { var StatusCode = StatusCodes.Status204NoContent; var ResultMessage = ""; object ResultData = ""; var user = _kullaniciBL.Login(loginModel); if (user != null && user.KullaniciBilgileri != null) { var claims = new[] { new Claim(JwtRegisteredClaimNames.Sub, user.KullaniciBilgileri.KullaniciKodu.ToString()), new Claim(JwtRegisteredClaimNames.Jti, user.KullaniciBilgileri.KullaniciID.ToString()), }; var claimsIdentity = new ClaimsIdentity(claims, "Token"); var claimList = new List <Claim>(); if (user.KullaniciYetkileri != null) { foreach (var item in user.KullaniciYetkileri) { claimList.Add(new Claim("roles", item.YetkiID.ToString())); } } var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Tokens:Key"])); var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256); var token = new JwtSecurityToken(_config["Tokens:Issuer"], _config["Tokens:Issuer"], claimsIdentity.Claims, expires: DateTime.Now.AddMinutes(30), signingCredentials: creds); var tokenHandler = new { token = new JwtSecurityTokenHandler().WriteToken(token) }; var result = new DtoToken { Token = tokenHandler.token, UserDto = user }; ResultData = result; ResultMessage = "Token created successfully"; StatusCode = StatusCodes.Status200OK; } else { ResultData = null; ResultMessage = "No such user!"; StatusCode = StatusCodes.Status406NotAcceptable; } return(new BllResponse { Data = ResultData, Message = ResultMessage, StatusCode = StatusCode }); } catch (Exception ex) { return(new BllResponse { StatusCode = StatusCodes.Status500InternalServerError, Message = $"Error:{ex.Message}", Data = null }); } }