예제 #1
0
        public Authentication FindAuthentication(FindAuthenticationCommand model)
        {
            Authentication result  = null;
            MySqlCommand   command = new MySqlCommand($"SELECT username,displayName,email,token FROM users WHERE username=@username AND password=@password", _connection);

            command.Parameters.AddWithValue("@username", model.UserId);
            command.Parameters.AddWithValue("@password", Extensions.EncryptString(model.Password));

            using (IDataReader reader = command.ExecuteReader())
            {
                if (reader.Read())
                {
                    result = PopulateAuthentition(reader);
                }
            }

            return(result);
        }
예제 #2
0
        public IHttpActionResult AuthenticateUser([FromBody] FindAuthenticationCommand command)
        {
            if (command == null)
            {
                return(BadRequest(DefaultMessages.InvalidBody));
            }
            ValidationError error = new FindTokenCommandValidator().Validate(command);

            if (error.IsInvalid)
            {
                return(BadRequest(error.Error));
            }
            UsersRepository repository     = new UsersRepository(Connection);
            Authentication  authentication = repository.FindAuthentication(command);

            if (authentication == null)
            {
                return(BadRequest("Usuário ou senha inválidos."));
            }
            return(Ok(authentication));
        }