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); }
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); }
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)); }
private Login.Query CreateRequest(string userName, string password) { Login.Query request = new Login.Query { Email = userName, Password = password }; return(request); }
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); }
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 }); }
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); }
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 })); }
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)); }
public async Task <ActionResult <UserDto> > Login(Login.Query command) => this.AppendUserRefreshTokenCookie(await this.Mediator.Send(command));
public async Task <ActionResult <User> > Login(Login.Query query) => await Mediator.Send(query);
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; } }
public async Task <ActionResult <AppUserViewModel> > Login(Login.Query loginQuery) => await Mediator.Send(loginQuery);
public async Task <ActionResult <UserReturnObject> > Login(Login.Query query) { return(await _mediator.Send(query)); }
public async Task <ActionResult <User> > Login(Login.Query query) { var result = await Mediator.Send(query); return(Ok(result)); }
public async Task <ActionResult <AdminUser> > LoginAsAdminAsync([FromBody] Login.Query query) { var adminUser = await _mediator.Send(query); return(Ok(adminUser)); }
public async Task <ActionResult <AuthenticationResponse> > Login(Login.Query loginQuery) => await Mediator.Send(loginQuery);
public async Task <IActionResult> Login(Login.Query query) { var user = await _mediator.Send(query); return(Ok(user)); }
public async Task <ActionResult <User> > Login(Login.Query query) { //the query parameter will contain our username and password return(await Mediator.Send(query)); }
public async Task <ActionResult <User> > Login(Login.Query query) //query keep the data username and password or and email { return(await Mediator.Send(query)); }
public async Task <ActionResult <LoginResponse> > Login([FromBody] Login.Query loginQuery) => await Mediator.Send(loginQuery);
public async Task <ActionResult <User> > Login(Login.Query request) => await Mediator.Send(request);
public async Task <IActionResult> Login(Login.Query query) { return(Ok(await _mediator.Send(query))); }
public async Task <ActionResult <User> > Login(Login.Query query) { return(await Mediator.Send(query)); }
public async Task <ActionResult <User> > Login(Login.Query query, CancellationToken cancellationToken) { return(await this.Mediator.Send(query, cancellationToken)); }