current status

This commit is contained in:
Göran Heinemann 2020-03-28 18:57:49 +01:00
parent 9916b97b28
commit 122791914f
8 changed files with 233 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.idea/

View File

@ -0,0 +1,30 @@
<?php
class Exercise
{
public $id, $name, $description, $amount, $type, $unit, $current;
/**
* Workout constructor.
* @param $id
* @param $name
* @param $description
* @param $amount
* @param $type
* @param $unit
* @param $current
*/
public function __construct($id, $name, $description, $amount, $type, $unit, $current = 0)
{
$this->id = $id;
$this->name = $name;
$this->description = $description;
$this->amount = $amount;
$this->type = $type;
$this->unit = $unit;
$this->current = $current;
}
}

View File

@ -0,0 +1,22 @@
<?php
class Workout
{
public $creator, $title, $id;
/**
* Workout constructor.
* @param $creator
* @param $title
* @param $id
*/
public function __construct($creator, $title, $id)
{
$this->creator = $creator;
$this->title = $title;
$this->id = $id;
}
}

37
html/api/index.php Normal file
View File

@ -0,0 +1,37 @@
<?php
include "../../config.php";
include "Models/Workout.php";
if (isset($_GET['token'])){
$sql = "SELECT * FROM tokens INNER JOIN users ON users.id=tokens.user WHERE token=?";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $_GET['token']);
if ($stmt->execute()){
if ($stmt->rowCount() == 1){
$userData = $stmt->fetchAll(PDO::FETCH_ASSOC);
$username = $userData[0]['username'];
$userID = $userData[0]['user'];
$sql = "SELECT * FROM workout_routines inner join users on workout_routines.creator=users.id WHERE public=1 or creator=?";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $userID);
if ($stmt->execute()){
$workoutRoutines = $stmt->fetchAll(PDO::FETCH_ASSOC);
$workouts = array();
foreach ($workoutRoutines as $routine){
$workouts[] = new Workout($routine['username'], $routine['title'], $routine['id']);
}
header('Content-Type: application/json');
echo json_encode($workouts);
}
}else{
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
}
}else{
var_dump($stmt->errorInfo());
}
//header('Content-Type: application/json');
}else{
}

60
html/api/workout.php Normal file
View File

@ -0,0 +1,60 @@
<?php
include "../../config.php";
include 'Models/Exercise.php';
if (isset($_GET['token'])){
$sql = "SELECT * FROM tokens INNER JOIN users ON users.id=tokens.user WHERE token=?";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $_GET['token']);
if ($stmt->execute()){
if ($stmt->rowCount() == 1){
$userData = $stmt->fetchAll(PDO::FETCH_ASSOC);
$username = $userData[0]['username'];
$userID = $userData[0]['user'];
if(isset($_GET['workout'])){
$sql = "SELECT exercises_in_workout.id, name, description, amount, type, unit FROM exercises_in_workout inner join workout_types on workout_types.id=exercises_in_workout.workout_type inner JOIN workout_type_measurements on workout_type_measurements.id=workout_types.measurement where exercises_in_workout.workout_routine=?";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $_GET['workout']);
if ($stmt->execute()){
$exercises = $stmt->fetchAll(PDO::FETCH_ASSOC);
$returnExercises = array();
foreach($exercises as $exercise){
$returnExercises[] = new Exercise($exercise['id'], $exercise['name'], $exercise['description'], $exercise['amount'], $exercise['type'], $exercise['unit']);
}
header('Content-Type: application/json');
echo json_encode($returnExercises);
}
}elseif(isset($_GET['routine'])){
$sql = "select * from current_routines inner join workout_routines on workout_routines.id=current_routines.workout_routine inner JOIN exercises_in_workout on exercises_in_workout.workout_routine=workout_routines.id inner join workout_types on workout_types.id=exercises_in_workout.workout_type inner join workout_type_measurements on workout_type_measurements.id=workout_types.measurement where current_routines.id=?";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $_GET['routine']);
if ($stmt->execute()){
$exercises = $stmt->fetchAll(PDO::FETCH_ASSOC);
$exercisesList = array();
foreach ($exercises as $exercise){
$exercisesList[] = new Exercise($exercise['workout_type'], $exercise['name'], $exercise['description'], $exercise['amount'], $exercise['type'], $exercise['unit'], $exercise['measurement']);
}
echo '<pre>';
var_dump($exercises);
echo '</pre>';
}
}elseif(isset($_GET['startWorkout'])){
$sql = "SELECT * FROM `workout_routines` inner join exercises_in_workout on exercises_in_workout.workout_routine=workout_routines.id inner join workout_types on workout_types.id=exercises_in_workout.workout_type where workout_routines.id=?";
}else{
}
}else{
var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
}
}else{
var_dump($stmt->errorInfo());
}
//header('Content-Type: application/json');
}else{
}

17
html/index.php Normal file
View File

@ -0,0 +1,17 @@
<?php
include "../config.php";
session_start();
if (isset($_SESSION['username'])){
$sql = "select current_routines.id, time, title from current_routines inner join workout_routines on workout_routines.id=current_routines.workout_routine inner join users on users.id=current_routines.user where users.username=?";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $_SESSION['username']);
if($stmt->execute()){
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
var_dump($data);
}else{
var_dump($stmt->errorInfo());
}
}else{
header("Location: login/");
}

33
html/login/index.php Normal file
View File

@ -0,0 +1,33 @@
<?php
include "../../config.php";
session_start();
if (isset($_POST['username']) and isset($_POST['password'])){
$sql = "SELECT * FROM users WHERE username=?";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $_POST['username']);
if ($stmt->execute()){
$data = $stmt->fetchAll(PDO::FETCH_ASSOC)[0];
$password = $data['password'];
if (password_verify($_POST['password'], $password)){
$_SESSION['username'] = $data['username'];
$_SESSION['email'] = $data['email'];
header("Location: ../");
}
}
}
?>
<html>
<head>
</head>
<body>
<form method="post">
<input type="text" name="username" placeholder="Username" required><br>
<input type="password" name="password" placeholder="Password" required><br>
<button onclick="submit">log in</button>
</form>
</body>
</html>

32
html/register/index.php Normal file
View File

@ -0,0 +1,32 @@
<?php
include "../../config.php";
if (isset($_POST['username']) and isset($_POST['email']) and isset($_POST['password'])){
$sql = "INSERT INTO `users`(`username`, `email`, `password`) VALUES (?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $_POST['username']);
$stmt->bindParam(2, $_POST['email']);
$saltedHash = password_hash($_POST['password'], PASSWORD_BCRYPT);
$stmt->bindParam(3, $saltedHash);
if (!$stmt->execute()){
var_dump($stmt->errorInfo());
}else{
header("Location: ../");
}
}
?>
<html>
<head>
</head>
<body>
<form method="post">
<input type="text" name="username" placeholder="Username" required><br>
<input type="email" name="email" placeholder="Email" required><br>
<input type="password" name="password" placeholder="Password" required><br>
<button onclick="submit">Register</button>
</form>
</body>
</html>