Пример #1
0
        public async Task <IHttpActionResult> ReceivingGameDataEcho(GameDataReceivingModel model)
        {
            StringBuilder message       = new StringBuilder();
            var           gameData      = MapGameData(model);
            var           hashFromModel = GetMd5HashString($"{model.session_id}_{model.idencard_number}_{model.earned_points}_{hashSecretKey}");

            message.AppendLine("Ожидаемый заголовок hash: " + hashFromModel);
            if (!Request.Headers.Contains("hash"))
            {
                message.AppendLine("Отсутcвует заголовок hash");
            }
            else
            {
                var hash = Request.Headers.GetValues("hash").First();
                message.AppendLine("Принятый заголовок hash: " + hash);
                if (hash == hashFromModel)
                {
                    message.AppendLine("Проверочный хэш правильный");
                }
                else
                {
                    message.AppendLine("Проверочный хэш не правильный");
                }
            }
            return(Json(new { model = gameData, message = message.ToString() }, DefaultSerializerSettings.Instance));
        }
Пример #2
0
        public async Task <IHttpActionResult> ReceivingGameData(GameDataReceivingModel model)
        {
            var gameData = MapGameData(model);
            await _gameDataService.ReceivingGameData(gameData);

            return(Ok());
        }
Пример #3
0
        public async Task <IHttpActionResult> ReceivingGameDataAuth(GameDataReceivingModel model)
        {
            if (!Request.Headers.Contains("hash"))
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }
            var hash          = Request.Headers.GetValues("hash").First();
            var gameData      = MapGameData(model);
            var hashFromModel = GetMd5HashString($"{model.session_id}_{model.idencard_number}_{model.earned_points.ToString(CultureInfo.InvariantCulture)}_{hashSecretKey}");

            if (hash != hashFromModel)
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }
            await _gameDataService.ReceivingGameData(gameData);

            return(Ok());
        }
Пример #4
0
 private DecodedGameData MapGameData(GameDataReceivingModel model)
 {
     return(new DecodedGameData
     {
         Id = Guid.NewGuid(),
         ReceivingDate = DateTime.UtcNow,
         SessionId = model.session_id,
         CardNumber = model.card_num,
         PlayerId = model.player_id,
         FirstName = model.first_name,
         LastName = model.last_name,
         MiddleName = model.middle_name,
         IdenCardId = model.idencard_number,
         MachId = model.mach_id,
         UpdateDate = DateTime.Parse(model.update_date),
         EarnedPoints = model.earned_points
     });
 }