コード例 #1
0
        public async Task Put_Should_Update_Return_Url()
        {
            ClientReturnUrl toUpdateReturnUrl = null;

            using (var context = new DaOAuthContext(_dbContextOptions))
            {
                toUpdateReturnUrl = context.ClientReturnUrls.Where(c => c.ClientId.Equals(_sammyClient.Id)).FirstOrDefault();
            }
            Assert.IsNotNull(toUpdateReturnUrl);

            var toUpdateReturnUrlDto = new UpdateReturnUrlDto()
            {
                IdReturnUrl = toUpdateReturnUrl.Id,
                ReturnUrl   = "http://updated.return.url"
            };

            var httpResponseMessage = await _client.PutAsJsonAsync("returnUrl", toUpdateReturnUrlDto);

            Assert.IsTrue(httpResponseMessage.IsSuccessStatusCode);

            ClientReturnUrl updatedReturnUrl = null;

            using (var context = new DaOAuthContext(_dbContextOptions))
            {
                updatedReturnUrl = context.ClientReturnUrls.Where(c => c.Id.Equals(toUpdateReturnUrl.Id)).SingleOrDefault();
            }
            Assert.IsNotNull(updatedReturnUrl);

            Assert.AreNotEqual(toUpdateReturnUrl.ReturnUrl, updatedReturnUrl.ReturnUrl);
            Assert.AreEqual(toUpdateReturnUrlDto.ReturnUrl, updatedReturnUrl.ReturnUrl);
        }
コード例 #2
0
        public void UpdateReturnUrl(UpdateReturnUrlDto toUpdate)
        {
            this.Validate(toUpdate);

            var resource = this.GetErrorStringLocalizer();

            if (!Uri.TryCreate(toUpdate.ReturnUrl, UriKind.Absolute, out var u))
            {
                throw new DaOAuthServiceException(resource["UpdateReturnUrlReturnUrlIncorrect"]);
            }

            using (var context = RepositoriesFactory.CreateContext())
            {
                var returnUrlRepo = RepositoriesFactory.GetClientReturnUrlRepository(context);
                var myReturnUrl   = returnUrlRepo.GetById(toUpdate.IdReturnUrl);

                if (myReturnUrl == null)
                {
                    throw new DaOAuthServiceException(resource["UpdateReturnUrlUnknowReturnUrl"]);
                }

                var userRepo = RepositoriesFactory.GetUserRepository(context);
                var user     = userRepo.GetByUserName(toUpdate.UserName);
                if (user == null || !user.IsValid)
                {
                    throw new DaOAuthServiceException(resource["UpdateReturnUrlInvalidUser"]);
                }

                var ucRepo = RepositoriesFactory.GetUserClientRepository(context);
                var uc     = ucRepo.GetUserClientByClientPublicIdAndUserName(myReturnUrl.Client.PublicId, toUpdate.UserName);
                if (uc == null)
                {
                    throw new DaOAuthServiceException(resource["UpdateReturnUrlBadUserNameOrClientId"]);
                }

                myReturnUrl.ReturnUrl = toUpdate.ReturnUrl;

                returnUrlRepo.Update(myReturnUrl);

                context.Commit();
            }
        }
コード例 #3
0
 public IActionResult Put(UpdateReturnUrlDto toUpdate)
 {
     toUpdate.UserName = User.Identity.Name;
     _service.UpdateReturnUrl(toUpdate);
     return(Ok());
 }