Example #1
0
        public async Task <ActionResult <dynamic> > Authenticate([FromBody] AuthDto model)
        {
            try
            {
                var user = userRepository.GetUserLogin(model.Login.ToLower());

                if (user == null)
                {
                    return(NotFound(new { message = "User not found with this login" }));
                }

                var isEqualPass = BCryptService.PasswordCompare(model.Password, user.Password);

                if (!isEqualPass)
                {
                    return(NotFound(new { message = "Password incorrect" }));
                }

                var token = TokenService.GenerateToken(user);
                user.Password = "";
                return(new
                {
                    user = user,
                    token = token
                });
            }
            catch (Exception ex)
            {
                return(CatchError(ex, "Authentication user"));
            }
        }