public IActionResult Authenticate([FromBody] LoginUserModel loginUserModel, [FromServices] ILoginUserCommand loginUserCommand) { var user = loginUserCommand.Execute(loginUserModel); if (user == null) { return(BadRequest("Something went wrong")); } var tokenHandler = new JwtSecurityTokenHandler(); var key = Encoding.ASCII.GetBytes(_authentication.Secret); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim(ClaimTypes.Name, user.Id.ToString()) }), Expires = DateTime.UtcNow.AddDays(2), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) }; var token = tokenHandler.CreateToken(tokenDescriptor); var tokenString = tokenHandler.WriteToken(token); // return basic user info (without password) and token to store client side return(Ok(new { User = user, Token = tokenString })); }
public AccountController(ILoginUserCommand loginUser, IGetProjectionsCommand getProjections, IGetReservationsCommand getReservations, IGetProjectionCommand getProjection, IGetHallsCommand getHalls, IGetSeatsCommand getSeats, IGetUserCommand getUser, IAddReservationCommand addReservation, ITakenSeatsCommand takenSeats, IAddUserCommand addUser, IUpdateUserProfileCommand updateUser, IGetRolesCommand getRoles, IUpdateUserPasswordCommand updateUserPassword) { this.loginUser = loginUser; this.getProjections = getProjections; this.getReservations = getReservations; this.getProjection = getProjection; this.getHalls = getHalls; this.getSeats = getSeats; this.getUser = getUser; this.addReservation = addReservation; this.takenSeats = takenSeats; this.addUser = addUser; this.updateUser = updateUser; this.getRoles = getRoles; this.updateUserPassword = updateUserPassword; }
public async Task <IActionResult> Login(LoginUserRequest user, [FromServices] ILoginUserCommand command) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { UserResponse response = await command.ExecuteAsync(user); return(Ok(response)); } catch (IncorrectPasswordOrEmailExeption exception) { return(BadRequest(exception.Message)); } }
public AuthController(Encryption enc, ILoginUserCommand loginUser) { _enc = enc; _loginUser = loginUser; }
public JwtManager(ILoginUserCommand loginUser) { this.loginUser = loginUser; }