Example #1
0
        public async Task <IActionResult> Login([FromBody] UserModel user)
        {
            if (!await ValidateModel(user))
            {
                return(BadRequest());
            }

            var userEntity = await _mediator.Send(new GetUserByUsernameRequest { Username = user.Username });

            if (_cipherService.ValidatePasswordAgainstHash(user.Password, userEntity.PasswordSalt, userEntity.Password))
            {
                return(Ok(new TokenResult {
                    Token = _tokenService.BuildToken(user.Username)
                }));
            }
            return(BadRequest());
        }