public async Task Can_Login_as_Customer()
        {
            // arrange
            var user = UserBuilder.Create()
                       .WithRole(UserRole.Customer)
                       .WithEmail(HealthyJuicesConstants.DEFAULT_USER_LOGIN)
                       .Active()
                       .WithPassword(HealthyJuicesConstants.DEFAULT_USER_PASSWORD)
                       .Build(ArrangeRepositoryContext);

            var dto = new Login.Query(HealthyJuicesConstants.DEFAULT_USER_LOGIN, HealthyJuicesConstants.DEFAULT_USER_PASSWORD);

            var controller = new AuthorizationController(Mediator);

            // act
            var result = await controller.LoginAsync(dto);

            // assert
            result.AccessToken.Should().NotBeNullOrEmpty();
            result.User.Should().NotBeNull();
            result.User.Email.Should().Be(dto.Email);

            var subject = AssertRepositoryContext.Users.FirstOrDefault();

            subject.Should().NotBeNull();
            subject.Roles.Should().Be(UserRole.Customer);

            subject.Email.Should().Be(dto.Email);
            subject.Password.Text.Should().NotBeNullOrWhiteSpace();
            subject.Password.Salt.Should().NotBeNullOrWhiteSpace();
            subject.IsActive.Should().BeTrue();
            subject.IsRemoved.Should().BeFalse();
        }
        public async Task <ActionResult <User> > Login(Login.Query query)
        {
            var user = await Mediator.Send(query);

            SetTokenCookie(user.RefreshToken);
            return(user);
        }
示例#3
0
        public async Task <ActionResult <User> > Login(Login.Query query)
        {
            Console.WriteLine("IN UserController.cs ...............................Net Core");
            var user = await Mediator.Send(query);      //username and password

            SetTokenCookie(user.RefreshToken);
            return(user);
        }
示例#4
0
        public async Task <IActionResult> Login(Login.Query query)
        {
            var user = await Mediator.Send(query);

            if (user != null && user.IsSuccess)
            {
                setTokenCookie(user.Value.RefreshToken);
            }
            return(HandleResult(user));
        }
示例#5
0
        private Login.Query CreateRequest(string userName, string password)
        {
            Login.Query request = new Login.Query
            {
                Email    = userName,
                Password = password
            };

            return(request);
        }
示例#6
0
        public async Task <object> Login([FromBody] Login.Query data)
        {
            bool result = await _queryDispatcher.Dispatch <Login.Query, bool>(data);

            if (result)
            {
                return(GenerateJwtToken(data.Email));
            }
            return(Unauthorized());
        }
        public async Task <Response> Login(Login.Query login)
        {
            Response  result = new Response();
            UserModel user   = await this.mediator.Send(login);

            if (user != null)
            {
                result.add("jwt", TokenUtil.createToken(user.id));
            }
            return(result);
        }
示例#8
0
        public override async Task <LoginReply> Login(LoginRequest request, ServerCallContext context)
        {
            var query = new Login.Query()
            {
                Email = request.Email, Password = request.Password
            };
            var result = await this.mediator.Send(query);

            return(new LoginReply
            {
                DisplayName = result.DisplayName,
                Token = result.Token,
                Username = result.Username
            });
        }
示例#9
0
        public async void UserDetails_SendsQueryWithTheCorrectUserId()
        {
            var notification = new Login.Query()
            {
                Email    = "email",
                Password = "******"
            };

            const int userId   = 1;
            var       mediator = new Mock <IMediator>();
            var       sut      = new UserController();

            sut.Mediator = mediator.Object;
            await sut.Login(notification);

            mediator.Verify(x => x.Send(It.Is <Login.Query>(y => y == notification)), Times.Once);
        }
示例#10
0
        public async Task <ActionResult> Login(Login.Query query)
        {
            var user = await _mediator.Send(query);

            if (user == null)
            {
                return(Unauthorized());
            }

            //Build a token for our user to use throughout the application
            var claims = new[]
            {
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                new Claim(ClaimTypes.Name, user.Username)
            };

            var key = new SymmetricSecurityKey(Encoding.UTF8
                                               .GetBytes(_config.GetSection("AppSettings:Token").Value));

            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha512Signature);

            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject            = new ClaimsIdentity(claims),
                Expires            = DateTime.Now.AddDays(1),
                SigningCredentials = creds
            };

            var tokenHandler = new JwtSecurityTokenHandler();
            var token        = tokenHandler.CreateToken(tokenDescriptor);

            var userForDetails = _mapper.Map <UserForDetailsDto>(user);

            return(Ok(new
            {
                token = tokenHandler.WriteToken(token),
                userForDetails
            }));
        }
示例#11
0
        public async Task <ActionResult <User> > Login(Login.Query query)
        {
            var user = await _userManager.Users.FirstOrDefaultAsync(x => x.Email == query.Email);

            if (user == null)
            {
                return(Unauthorized("Invalid email"));
            }

            var result = await _signInManager.CheckPasswordSignInAsync(user, query.Password, false);

            if (result.Succeeded)
            {
                return(new User
                {
                    DisplayName = user.DisplayName,
                    Token = _jwtGenerator.CreateToken(user),
                    Username = user.UserName,
                    Id = user.Id
                });
            }

            return(Unauthorized("Invalid password"));
        }
        public async Task <LoginResponseDto> LoginAsync([FromBody] Login.Query query)
        {
            var response = await _mediator.Send(query);

            return(response);
        }
 public async Task <ActionResult <User> > Login(Login.Query query)
 {
     return(await _mediator.Send(new Login.Query {
         Email = query.Email, Password = query.Password
     }));
 }
 public async Task <ActionResult <User> > Login([FromBody] Login.Query query)
 {
     return(await _mediator.Send(query));
 }
示例#15
0
 public async Task <ActionResult <UserDto> > Login(Login.Query command) =>
 this.AppendUserRefreshTokenCookie(await this.Mediator.Send(command));
示例#16
0
 public async Task <ActionResult <User> > Login(Login.Query query)
 => await Mediator.Send(query);
示例#17
0
        public async void UserName_ShouldHave_Max_30Characters_Exception()
        {
            try
            {
                ////var request = CreateRequest("UserNameIsGreaterThanAllowed", "password");
                ////var mediator = new Mock<IMediator>();
                ////var response = mediator.Object.Send(request).Result;

                //var user = new UserViewModel
                //{
                //    viewModel.UserId = 100,
                //    viewModel.Username = "******",
                //    viewModel.Forename = "Steve",
                //    viewModel.Surname = "Gordon",
                //};

                //var mockMediator = new Mock<IMediator>();
                ////mediator.Setup(x => x.SendAsync(It.IsAny<UserQuery>())).Returns(user);

                //mockMediator.Setup(m => m.Send(It.IsAny<TransferNotificationCommand>(), default(CancellationToken))).Verifiable("Notification was not sent.");

                //var handler = new TransferHandler(mockMediator.Object);

                //var actual = await handler.Handle(message);

                //// mockMediator.Verify(x => x.Send(It.IsAny<CreateIsaTransferNotificationCommand>(), default(CancellationToken)), Times.Once());

                //var notification = new Login.Query()
                //{
                //    Email = "email",
                //    Password = "******"
                //};

                //mockMediator
                //    .Setup(m => m.Send(It.IsAny<Login.Query>(), It.IsAny<CancellationToken>()))
                //    .ReturnsAsync(new User()) //<-- return Task to allow await to continue
                //    .Verifiable("Notification was not sent.");



                //mockMediator.Verify(x => x.Send(It.IsAny<notification>(), It.IsAny<CancellationToken>()), Times.Once());

                var notification = new Login.Query()
                {
                    Email    = "email",
                    Password = "******"
                };

                //Arrange
                var mediator = new Mock <IMediator>();
                mediator.Setup(m => m.Send(It.IsAny <Login.Query>(), It.IsAny <CancellationToken>())).ReturnsAsync(It.IsAny <User>());

                //Act
                await mediator.Object.Send(new Login.Query());

                //Assert
                mediator.Verify(x => x.Send(It.IsAny <Login.Query>(), It.IsAny <CancellationToken>()));
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
示例#18
0
 public async Task <ActionResult <AppUserViewModel> > Login(Login.Query loginQuery) => await Mediator.Send(loginQuery);
示例#19
0
 public async Task <ActionResult <UserReturnObject> > Login(Login.Query query)
 {
     return(await _mediator.Send(query));
 }
示例#20
0
        public async Task <ActionResult <User> > Login(Login.Query query)
        {
            var result = await Mediator.Send(query);

            return(Ok(result));
        }
示例#21
0
        public async Task <ActionResult <AdminUser> > LoginAsAdminAsync([FromBody] Login.Query query)
        {
            var adminUser = await _mediator.Send(query);

            return(Ok(adminUser));
        }
示例#22
0
 public async Task <ActionResult <AuthenticationResponse> > Login(Login.Query loginQuery) =>
 await Mediator.Send(loginQuery);
示例#23
0
        public async Task <IActionResult> Login(Login.Query query)
        {
            var user = await _mediator.Send(query);

            return(Ok(user));
        }
示例#24
0
 public async Task <ActionResult <User> > Login(Login.Query query)
 {
     //the query parameter will contain our username and password
     return(await Mediator.Send(query));
 }
示例#25
0
 public async Task <ActionResult <User> > Login(Login.Query query) //query keep the data username and password or and email
 {
     return(await Mediator.Send(query));
 }
示例#26
0
 public async Task <ActionResult <LoginResponse> > Login([FromBody] Login.Query loginQuery) =>
 await Mediator.Send(loginQuery);
示例#27
0
 public async Task <ActionResult <User> > Login(Login.Query request) => await Mediator.Send(request);
示例#28
0
 public async Task <IActionResult> Login(Login.Query query)
 {
     return(Ok(await _mediator.Send(query)));
 }
示例#29
0
 public async Task <ActionResult <User> > Login(Login.Query query)
 {
     return(await Mediator.Send(query));
 }
示例#30
0
 public async Task <ActionResult <User> > Login(Login.Query query, CancellationToken cancellationToken)
 {
     return(await this.Mediator.Send(query, cancellationToken));
 }