Esempio n. 1
0
        public async Task get_with_authorized_user_should_retrieve_the_right_user(string url)
        {
            var client = _factory.CreateClient();


            var command = new SignInUserCommand {
                Email = "*****@*****.**", Password = "******"
            };
            var httpContent =
                new StringContent(JsonConvert.SerializeObject(command), Encoding.UTF8, "application/json");

            var response = await client.PostAsync(url + "/auth", httpContent);

            string responseContent = await response.Content.ReadAsStringAsync();

            response.EnsureSuccessStatusCode();

            var tokenResponse = JsonConvert.DeserializeObject <TokenResponse>(responseContent);

            client.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", tokenResponse.Token);

            var restrictedResponse = await client.GetAsync(url);

            restrictedResponse.EnsureSuccessStatusCode();
            restrictedResponse.StatusCode.ShouldBe(HttpStatusCode.OK);
        }
Esempio n. 2
0
        public async Task <IActionResult> SignIn(SignInUserCommand request)
        {
            var token = await _mediator.Send(request);

            if (token == null)
            {
                return(BadRequest());
            }
            return(Ok(token));
        }
Esempio n. 3
0
        public async Task <ActionResult <JsonWebToken> > LoginUser([FromBody] SignInUserCommand signInUserCommand,
                                                                   CancellationToken ct)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            return(await Mediator.Send(signInUserCommand, ct));
        }
Esempio n. 4
0
        public async Task <IActionResult> SignIn([FromBody] SignInUserCommand command)
        {
            var response = await _mediator.Send(command);

            if (response.Error != null)
            {
                return(BadRequest(response.Error));
            }
            return(Ok(response.Result));
        }
Esempio n. 5
0
        public ActionResult SignIn([FromBody] UserSignInInput signInInput)
        {
            if (signInInput == null)
            {
                return(BadRequest("Wrong input parameters"));
            }

            var token = new SignInUserCommand(signInInput, _signingEncodingKey)
                        .Execute(_userRepository);

            return(Ok(token));
        }
Esempio n. 6
0
        public async Task <IActionResult> SignIn([FromBody] SignInUserCommand command)
        {
            var result = await _dispatcher.DispatchAsync(command);

            if (result.Succeeded)
            {
                return(Ok(result));
            }
            else
            {
                return(BadRequest(result));
            }
        }
Esempio n. 7
0
        public async Task sign_in_should_retrieve_bad_request_with_invalid_password(string url)
        {
            var client = _factory.CreateClient();

            var command = new SignInUserCommand {
                Email = "*****@*****.**", Password = "******"
            };
            var httpContent =
                new StringContent(JsonConvert.SerializeObject(command), Encoding.UTF8, "application/json");

            var response = await client.PostAsync(url, httpContent);

            string responseContent = await response.Content.ReadAsStringAsync();

            response.StatusCode.ShouldBe(HttpStatusCode.BadRequest);
            responseContent.ShouldNotBeEmpty();
        }
Esempio n. 8
0
        public async Task sign_in_should_retrieve_a_token(string url)
        {
            var client = _factory.CreateClient();

            var command = new SignInUserCommand {
                Email = "*****@*****.**", Password = "******"
            };
            var httpContent =
                new StringContent(JsonConvert.SerializeObject(command), Encoding.UTF8, "application/json");

            var response = await client.PostAsync(url, httpContent);

            string responseContent = await response.Content.ReadAsStringAsync();

            response.EnsureSuccessStatusCode();

            response.StatusCode.ShouldBe(HttpStatusCode.OK);
            responseContent.ShouldNotBeEmpty();
        }
 public ActionResult SignIn(SignInUserCommand input)
 {
     return(TryPush(input, setting => { setting.SuccessResult = () => RedirectToAction("Index", "Home"); }));
 }