Пример #1
0
        public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
        {
            if (string.IsNullOrWhiteSpace(context.UserName) || string.IsNullOrWhiteSpace(context.Password))
            {
                context.Result = new GrantValidationResult
                {
                    IsError          = true,
                    Error            = OidcConstants.TokenErrors.InvalidRequest,
                    ErrorDescription = "Bạn cần truyền đủ tên đăng nhập và mật khẩu",
                };

                return(Task.FromResult(0));
            }

            var user = _userRepository.GetUserInfo(context.UserName, context.Password);

            if (user?.UserId > 0)
            {
                context.Result = new GrantValidationResult(ConvertJson.Serialize(user),
                                                           OidcConstants.AuthenticationMethods.Password,
                                                           DateTime.UtcNow.ToVnTime(),
                                                           user?.Claims);

                return(Task.FromResult(0));
            }

            context.Result = new GrantValidationResult
            {
                IsError          = true,
                Error            = OidcConstants.TokenErrors.InvalidClient,
                ErrorDescription = "Tên đăng nhập hoặc mật khẩu của bạn không đúng"
            };

            return(Task.FromResult(0));
        }
Пример #2
0
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            var dictionary = Mapper.ToDictionary(logEvent);
            var json       = ConvertJson.Serialize(dictionary);

            builder.Append(json);
        }
Пример #3
0
        public void CanSerialiseToJsonAsExpected()
        {
            var data   = MakeTestData();
            var result = ConvertJson.Serialize(data);

            Assert.That(result, Is.EqualTo(ExpectedOutput));
        }
Пример #4
0
        public async Task <IActionResult> GetJson()
        {
            var studentList = await _baseService.GetAll().ToListAsync();

            var    std  = _mapper.Map <List <VMStudent> >(studentList);
            string json = ConvertJson.Serialize(std);

            return(Ok(json));
        }
        protected override string GetFormattedMessage(LogEventInfo logEvent)
        {
            var result = new Dictionary <string, object>();

            AppendDataFromAttributes(logEvent, result);
            AppendLogProperties(logEvent, result);
            AppendLogParameters(logEvent, result);
            AppendExceptionData(logEvent, result);

            return(ConvertJson.Serialize(result));
        }
Пример #6
0
        protected override string GetFormattedMessage(LogEventInfo logEvent)
        {
            var dictionary = Mapper.ToDictionary(logEvent);

            foreach (var property in Properties)
            {
                AddRenderedValue(logEvent, dictionary, property);
            }

            return(ConvertJson.Serialize(dictionary));
        }
Пример #7
0
        public async Task ValidateAsync(ExtensionGrantValidationContext context)
        {
            var token             = context.Request.Raw.Get("token");
            var socialNetworkType = context.Request.Raw.Get("social_network_type");

            if (string.IsNullOrWhiteSpace(token) || string.IsNullOrWhiteSpace(socialNetworkType))
            {
                context.Result = new GrantValidationResult
                {
                    IsError          = true,
                    Error            = OidcConstants.TokenErrors.InvalidRequest,
                    ErrorDescription = "Tham số truyền vào chưa đủ",
                };

                return;
            }

            var user = await _socialNetworkProvider.GetUserSocialNetworkByTokenAsync(GetSocialNetworkType(socialNetworkType), token);

            if (user == null || string.IsNullOrWhiteSpace(user.FullName))
            {
                context.Result = new GrantValidationResult
                {
                    IsError          = true,
                    Error            = OidcConstants.TokenErrors.InvalidRequest,
                    ErrorDescription = "Có lỗi khi kết nối đến tài khoản mạng xã hội của bạn",
                };

                return;
            }

            user.AccountType = socialNetworkType;
            user             = _userRepository.UpdateUserInfoFromSocialNetwork(user);

            if (user == null || user.UserId <= 0)
            {
                context.Result = new GrantValidationResult
                {
                    IsError          = true,
                    Error            = OidcConstants.TokenErrors.InvalidRequest,
                    ErrorDescription = "Cập nhật tài khoản vào hệ thống thất bại, vui lòng thử lại sau",
                };

                return;
            }

            context.Result = new GrantValidationResult(ConvertJson.Serialize(user),
                                                       OidcConstants.AuthenticationMethods.Password,
                                                       DateTime.UtcNow.ToVnTime(),
                                                       user?.Claims);
        }
Пример #8
0
        public async Task <IActionResult> Update()
        {
            VMAward vMAward = new VMAward()
            {
                Id   = 1,
                Name = "Champion"
            };

            apiSettings.Action = "update";
            apiSettings.Obj    = ConvertJson.Serialize(vMAward);
            bool result = await _apiHelper.PutRequest(apiPath, apiSettings);

            return(View());
        }
Пример #9
0
        public async Task <IActionResult> Insert()
        {
            FirstAppEFCore.DTO.VMLesson ls = new FirstAppEFCore.DTO.VMLesson()
            {
                Subject = "AI"
            };

            apiSettings.Action = "add";
            apiSettings.Id     = 0;
            apiSettings.Obj    = ConvertJson.Serialize(ls);
            await _apiHelper.PostRequest(apiPath, apiSettings);

            return(View());
        }
Пример #10
0
        public async Task <IActionResult> GetByName()
        {
            ApiHelper <List <VMStudent> > _apiHelper = new ApiHelper <List <VMStudent> >();
            Student std = new Student()
            {
                Name    = "MgMg",
                Address = "Mandalay"
            };

            apiSettings.Action = "getbyname";
            apiSettings.Obj    = ConvertJson.Serialize(std);
            List <VMStudent> vMStudents = await _apiHelper.PostRequest(apiPath, apiSettings);

            return(View(vMStudents));
        }
Пример #11
0
        public async Task <IActionResult> Insert()
        {
            VMStudent std = new VMStudent()
            {
                Name    = "MgMg",
                Address = "Mandalay"
            };

            apiSettings.Action = "add";
            apiSettings.Id     = 0;
            apiSettings.Obj    = ConvertJson.Serialize(std);
            await _apiHelper.PostRequest(apiPath, apiSettings);

            return(View());
        }
Пример #12
0
        public void SerialisationIsNotAffectedByChangeToGlobalSettings()
        {
            var existingDefaults = JsonConvert.DefaultSettings;

            try
            {
                JsonConvert.DefaultSettings = ADifferentJsonSerializerSettings;

                var data   = MakeTestData();
                var result = ConvertJson.Serialize(data);

                Assert.That(result, Is.EqualTo(ExpectedOutput));
            }
            finally
            {
                JsonConvert.DefaultSettings = existingDefaults;
            }
        }
Пример #13
0
        public void AChangeToGlobalSetttingGivesDifferentOutput()
        {
            var existingDefaults = JsonConvert.DefaultSettings;

            try
            {
                JsonConvert.DefaultSettings = ADifferentJsonSerializerSettings;

                var data   = MakeTestData();
                var result = ConvertJson.Serialize(data);

                var dataAffectedBySetttings = JsonConvert.SerializeObject(data);

                Assert.That(result, Is.Not.EqualTo(dataAffectedBySetttings));
            }
            finally
            {
                JsonConvert.DefaultSettings = existingDefaults;
            }
        }
        protected override string GetFormattedMessage(LogEventInfo logEvent)
        {
            var dictionary = Mapper.ToDictionary(logEvent);

            foreach (var property in Properties)
            {
                if (dictionary.ContainsKey(property.Name))
                {
                    dictionary.Add(PropertyNamePrefix + property.Name, property.Layout.Render(logEvent));
                }
                else
                {
                    dictionary.Add(property.Name, property.Layout.Render(logEvent));
                }
            }

            var json = ConvertJson.Serialize(dictionary);

            return(json);
        }
Пример #15
0
        public async Task <IActionResult> InsertList()
        {
            List <VMLesson> lessonList = new List <VMLesson>()
            {
                new VMLesson()
                {
                    Subject = "CO"
                },
                new VMLesson()
                {
                    Subject = "SE"
                },
            };

            apiSettings.Action = "addlist";
            apiSettings.Id     = 0;
            apiSettings.Obj    = ConvertJson.Serialize(lessonList);
            await _apiHelper.PostRequest(apiPath, apiSettings);

            return(View());
        }
        protected override void RenderFormattedMessage(LogEventInfo logEvent, StringBuilder target)
        {
            var result    = BuildPropertiesDictionary(logEvent);
            var orgLength = target.Length;

            try
            {
                // Ensure we are threadsafe
                var jsonSerializer = JsonSerializer;
                lock (jsonSerializer)
                {
                    // Serialize directly into StringBuilder
                    ConvertJson.Serialize(result, target, jsonSerializer);
                }
            }
            catch
            {
                _jsonSerializer = null;      // Do not reuse JsonSerializer, as it might have become broken
                target.Length   = orgLength; // Skip invalid JSON
                throw;
            }
        }
Пример #17
0
        protected override void Append(StringBuilder builder, LogEventInfo logEvent)
        {
            var dictionary = Mapper.ToDictionary(logEvent);

            var orgLength = builder.Length;

            try
            {
                // Ensure we are threadsafe
                var jsonSerializer = JsonSerializer;
                lock (jsonSerializer)
                {
                    // Serialize directly into StringBuilder
                    ConvertJson.Serialize(dictionary, builder, jsonSerializer);
                }
            }
            catch
            {
                _jsonSerializer = null;      // Do not reuse JsonSerializer, as it might have become broken
                builder.Length  = orgLength; // Skip invalid JSON
                throw;
            }
        }
        protected override string GetFormattedMessage(LogEventInfo logEvent)
        {
            var result = BuildPropertiesDictionaryFlattened(logEvent);

            return(ConvertJson.Serialize(result));
        }
        protected override string GetFormattedMessage(LogEventInfo logEvent)
        {
            Dictionary <string, object> dictionary = BuildPropertiesDictionary(logEvent);

            return(ConvertJson.Serialize(dictionary));
        }