Exemplo n.º 1
0
        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
            }));
        }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
        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));
            }
        }
Exemplo n.º 4
0
 public AuthController(Encryption enc,
                       ILoginUserCommand loginUser)
 {
     _enc       = enc;
     _loginUser = loginUser;
 }
Exemplo n.º 5
0
 public JwtManager(ILoginUserCommand loginUser)
 {
     this.loginUser = loginUser;
 }