diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d655cf2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +version: "3.7" + +services: + server: + image: fjortegan/nginx-fpm + ports: + - "8081:80" + volumes: + - ./src:/usr/share/nginx/html + links: + - fpm + + fpm: + image: fjortegan/php-xdebug + volumes: + - ./src:/var/www/html + # Sólo en máquinas Linux, comentar estas dos líneas en otros sistemas de lusers + extra_hosts: + - "host.docker.internal:host-gateway" + + db: + image: mariadb + #ports: + # - "3306:3306" + volumes: + - ./db-data:/var/lib/mysql/ + environment: + MYSQL_ROOT_PASSWORD: pestillo + MYSQL_USER: usuario + MYSQL_PASSWORD: cerrojo + + phpmyadmin: + image: phpmyadmin + ports: + - "8080:80" + environment: + - PMA_ARBITRARY=1 diff --git a/src/db/model.php b/src/db/model.php new file mode 100644 index 0000000..36c80fc --- /dev/null +++ b/src/db/model.php @@ -0,0 +1,30 @@ +conn = new PDO("mysql:host=db;dbname=quizzes", "root", "pestillo"); + $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + + public static function getInstance() { + if(!isset(self::$instance)) { + self::$instance = new Model(); + } + return self::$instance; + } + + public function crea_usuario($username, $password, $image = "anon.png") { + $statement = $this->conn->prepare("INSERT INTO usuarios (username, password) VALUES (:username, :password)"); + $statement->execute(array(":username" => $username, ":password" => crypt($password, "juas"))); + return $statement->rowCount(); + } + + public function check_user($username, $password) { + $statement = $this->conn->prepare("SELECT count(*) FROM usuarios WHERE username = :username AND password = :password"); + $statement->execute(array(":username" => $username, ":password" => crypt($password, "juas"))); + return $statement->fetch()[0] == 1; + } +} diff --git a/src/db/pdo.php b/src/db/pdo.php new file mode 100644 index 0000000..d1615c7 --- /dev/null +++ b/src/db/pdo.php @@ -0,0 +1,18 @@ + false, // turn off emulation mode for "real" prepared statements + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, //turn on errors in the form of exceptions + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, //make the default fetch be an associative array + ]; + + $conn=new PDO("mysql:host=$servidor;dbname=$bd;charset=utf8",$usuario,$clave,$options); +} catch(PDOException $e) { + echo "Error de conexión" . $e->getMessage(); +} diff --git a/src/index.php b/src/index.php new file mode 100644 index 0000000..acd6920 --- /dev/null +++ b/src/index.php @@ -0,0 +1,22 @@ + + +
+ + + +