Fixed some issues, added .env file

This commit is contained in:
João Vitória Silva
2023-12-01 23:02:18 +00:00
parent f26e194d2e
commit cfc0619c2c
14 changed files with 88 additions and 105 deletions

6
.gitignore vendored
View File

@@ -1,10 +1,8 @@
# Python # Python
backend/__pycache__/
backend/*/__pycache__/ backend/*/__pycache__/
backend/*.pyc backend/*.pyc
# Logs # Logs
backend/logs/ backend/logs/
backend/*.log backend/*.log
# Environment variables
backend/config/.env

View File

@@ -17,7 +17,7 @@ RUN apt-get update
EXPOSE 80 EXPOSE 80
# Define environment variables # Define environment variables
ENV APACHE_DOCUMENT_ROOT /var/www/html/public ENV APACHE_DOCUMENT_ROOT /var/www/html
# Enable Apache modules # Enable Apache modules
RUN a2enmod rewrite RUN a2enmod rewrite

14
backend/config/.env Normal file
View File

@@ -0,0 +1,14 @@
# .env
DB_HOST=mariadb
DB_PORT=3306
DB_USER=gearguardian
DB_PASSWORD=changeme
DB_DATABASE=gearguardian
SECRET_KEY=changeme123!
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
STRAVA_CLIENT_ID=changeme
STRAVA_CLIENT_SECRET=changeme
STRAVA_AUTH_CODE=changeme
JAEGER_HOST=jaeger
STRAVA_DAYS_ACTIVITIES_ONLINK=30

View File

@@ -1,46 +1,36 @@
version: '3' version: '3'
services: services:
gearguardian-frontend: # frontend logic
image: gearguardian-frontend:latest frontend:
container_name: frontend
image: ghcr.io/joaovitoriasilva/gearguardian/frontend:dev_29112023
environment:
- APACHE_DOCUMENT_ROOT=/var/www/html
volumes: volumes:
- ./app:/app - /home/joaovitoriasilva/Documents/containers/gearguardian/frontend:/var/www/html
- ./nginx.conf:/etc/nginx/conf.d/default.conf
ports: ports:
- "8080:80" - "8080:80"
networks:
- frontend_network
- backend_network
restart: unless-stopped restart: unless-stopped
# API logic # API logic
gearguardian-backend: backend:
container_name: gearguardian-backend container_name: backend
image: gearguardian-backend:latest image: ghcr.io/joaovitoriasilva/gearguardian/backend:dev_01122023
environment: environment:
- DB_HOST=<change me> #required - DB_PASSWORD=changeme
- DB_PORT=3306 #optional - will use port 3306 by default - SECRET_KEY=changeme
- DB_USER=<change me> #required - STRAVA_CLIENT_ID=changeme
- DB_PASSWORD=<change me> #required - STRAVA_CLIENT_SECRET=changeme
- DB_DATABASE=<change me> #required - STRAVA_AUTH_CODE=changeme
- SECRET_KEY=<change me> #required
- ALGORITHM=HS256 #optional - will use HS256 by default
- ACCESS_TOKEN_EXPIRE_MINUTES=30 #optional - will use 30 minutes by default
- STRAVA_CLIENT_ID=<change me> #required
- STRAVA_CLIENT_SECRET=<change me> #required
- STRAVA_AUTH_CODE=<change me> #required
- JAEGER_HOST=<change me> #required
- STRAVA_DAYS_ACTIVITIES_ONLINK=30 #optional - will use 30 days by default
ports: ports:
- "98:8000" - "98:80"
volumes: volumes:
- <host_path>/gearguardian-api:/app - /home/joaovitoriasilva/Documents/containers/gearguardian/backend:/app
env_file: env_file:
- ./app/config/.env # this will be removed. .env file will be moved to root folder - config/.env
depends_on: depends_on:
- mariadb - mariadb
- otel-collector - jaeger
networks:
- backend_network
restart: unless-stopped restart: unless-stopped
# mysql mariadb logic # mysql mariadb logic
@@ -48,30 +38,17 @@ services:
image: mariadb:latest image: mariadb:latest
container_name: mariadb container_name: mariadb
environment: environment:
- MYSQL_ROOT_PASSWORD=<change me> #required - MYSQL_ROOT_PASSWORD=123Testes@
- MYSQL_DATABASE=<change me> #required - MYSQL_DATABASE=gearguardian
- MYSQL_USER=<change me> #required - MYSQL_USER=gearguardian
- MYSQL_PASSWORD=<change me> #required - MYSQL_PASSWORD=123Testes@
ports: ports:
- "3306:3306" - "3306:3306"
volumes: volumes:
- <host_path>/mariadb:/var/lib/mysql - /home/joaovitoriasilva/Documents/containers/mariadb:/var/lib/mysql
networks:
- backend_network
restart: unless-stopped
otel-collector:
image: otel/opentelemetry-collector-contrib:latest
container_name: otel-collector
# Add any necessary configuration for the OpenTelemetry Collector here
volumes:
- <host_path>/otel-collector/otel-collector-config.yaml:/etc/otel-collector-config.yaml
ports:
- "4317:4317"
networks:
- backend_network
restart: unless-stopped restart: unless-stopped
# Jaeger for opentelemetry
jaeger: jaeger:
container_name: jaeger container_name: jaeger
image: jaegertracing/all-in-one:latest image: jaegertracing/all-in-one:latest
@@ -91,12 +68,22 @@ services:
- 14268:14268 - 14268:14268
- 14269:14269 - 14269:14269
- 9411:9411 - 9411:9411
networks: restart: unless-stopped
- backend_network
# phpmyadmin for DB manipulation
phpmyadmin:
container_name: phpmyadmin
image: phpmyadmin
ports:
- 81:80
environment:
- PMA_HOST=mariadb
- PMA_ARBITRARY=1
depends_on:
- mariadb
restart: unless-stopped restart: unless-stopped
networks: networks:
backend_network: default:
driver: bridge external: true
frontend_network: name: backend_network
driver: bridge

View File

@@ -1,15 +1,21 @@
<?php <?php
// Load the language file based on the user's preferred language // Check if the "preferred_language" key is set in the session
switch ($_SESSION["preferred_language"]) { if (isset($_SESSION["preferred_language"])) {
case 'en': // Load the language file based on the user's preferred language
$translationsTemplateTop = include $_SERVER['DOCUMENT_ROOT'].'/lang/inc/Template-Top/en.php'; switch ($_SESSION["preferred_language"]) {
break; case 'en':
case 'pt': $translationsTemplateTop = include $_SERVER['DOCUMENT_ROOT'].'/lang/inc/Template-Top/en.php';
$translationsTemplateTop = include $_SERVER['DOCUMENT_ROOT'].'/lang/inc/Template-Top/pt.php'; break;
break; case 'pt':
// ... $translationsTemplateTop = include $_SERVER['DOCUMENT_ROOT'].'/lang/inc/Template-Top/pt.php';
default: break;
$translationsTemplateTop = include $_SERVER['DOCUMENT_ROOT'].'/lang/inc/Template-Top/en.php'; // ...
default:
$translationsTemplateTop = include $_SERVER['DOCUMENT_ROOT'].'/lang/inc/Template-Top/en.php';
}
} else {
// Set a default language or handle the case when "preferred_language" is not set
$translationsTemplateTop = include $_SERVER['DOCUMENT_ROOT'].'/lang/inc/Template-Top/en.php';
} }
?> ?>

View File

@@ -443,5 +443,4 @@
return -2; return -2;
} }
} }
} }
?>

View File

@@ -172,5 +172,4 @@
return -2; return -2;
} }
} }
} }
?>

View File

@@ -4,7 +4,7 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* Get to call a API route */ /* Get to call a API route */
function callAPIRoute($endpoint, $multipleReturns, $callType, $dataFields){ function callAPIRoute($endpoint, $multipleReturns, $callType, $dataFields){
$api_url = 'http://192.168.2.80:98'; $api_url = 'http://127.0.1.1:98';
$responseArray = []; $responseArray = [];
// Initialize a new cURL session // Initialize a new cURL session
@@ -77,6 +77,4 @@
curl_close($ch); curl_close($ch);
return $responseArray; return $responseArray;
} }
?>

View File

@@ -34,18 +34,6 @@
/* Do a login */ /* Do a login */
function loginUser($username, $password, $neverExpires){ function loginUser($username, $password, $neverExpires){
#$api_url = 'http://192.168.2.80:98';
#$ch = curl_init();
#curl_setopt($ch, CURLOPT_URL, $api_url . '/token');
#curl_setopt($ch, CURLOPT_POST, 1);
#curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
# 'username' => $username,
# 'password' => $password,
# 'loginNeverExpires' => $neverExpires,
#]));
#curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
#$response = curl_exec($ch);
#curl_close($ch);
$response = callAPIRoute("/token", 0, 5, json_encode(array( $response = callAPIRoute("/token", 0, 5, json_encode(array(
'username' => $username, 'username' => $username,
'password' => $password, 'password' => $password,
@@ -107,5 +95,4 @@
return -2; return -2;
} }
} }
} }
?>

View File

@@ -32,7 +32,7 @@
function linkStrava($state){ function linkStrava($state){
// Example PHP code for the authentication link // Example PHP code for the authentication link
$client_id = '115321'; $client_id = '115321';
$redirect_uri = urlencode('https://api-gearguardian.jvslab.pt/strava/strava-callback'); $redirect_uri = urlencode('https://backend:98/strava/strava-callback');
$scope = 'read,read_all,profile:read_all,activity:read,activity:read_all'; // Set your required scope $scope = 'read,read_all,profile:read_all,activity:read,activity:read_all'; // Set your required scope
$strava_auth_url = "http://www.strava.com/oauth/authorize?client_id={$client_id}&response_type=code&redirect_uri={$redirect_uri}&approval_prompt=force&scope={$scope}&state={$state}"; $strava_auth_url = "http://www.strava.com/oauth/authorize?client_id={$client_id}&response_type=code&redirect_uri={$redirect_uri}&approval_prompt=force&scope={$scope}&state={$state}";
@@ -51,6 +51,4 @@
return -2; return -2;
} }
} }
} }
?>

View File

@@ -202,5 +202,4 @@
} }
} }
} }
} }
?>

View File

@@ -17,5 +17,4 @@
return -2; return -2;
} }
} }
} }
?>

View File

@@ -5,5 +5,4 @@
require_once $_SERVER['DOCUMENT_ROOT']."/inc/func/gear-funcs.php"; require_once $_SERVER['DOCUMENT_ROOT']."/inc/func/gear-funcs.php";
require_once $_SERVER['DOCUMENT_ROOT']."/inc/func/activities-funcs.php"; require_once $_SERVER['DOCUMENT_ROOT']."/inc/func/activities-funcs.php";
require_once $_SERVER['DOCUMENT_ROOT']."/inc/func/waypoints-funcs.php"; require_once $_SERVER['DOCUMENT_ROOT']."/inc/func/waypoints-funcs.php";
require_once $_SERVER['DOCUMENT_ROOT']."/inc/func/strava-funcs.php"; require_once $_SERVER['DOCUMENT_ROOT']."/inc/func/strava-funcs.php";
?>

View File

@@ -53,11 +53,11 @@
<main class="form-signin w-100 m-auto text-center p-5" style="max-width: 500px"> <main class="form-signin w-100 m-auto text-center p-5" style="max-width: 500px">
<!-- Info banners --> <!-- Info banners -->
<?php if($_GET["sessionExpired"] == 1){ ?> <?php if(isset($_GET["sessionExpired"]) && $_GET["sessionExpired"] == 1){ ?>
<div class="alert alert-warning alert-dismissible d-flex align-items-center" role="alert"> <div class="alert alert-warning alert-dismissible d-flex align-items-center" role="alert">
<i class="fa-solid fa-triangle-exclamation me-1"></i> <i class="fa-solid fa-triangle-exclamation me-1"></i>
<div> <div>
<?php if($_GET["sessionExpired"] == 1){ ?> <?php if(isset($_GET["sessionExpired"]) && $_GET["sessionExpired"] == 1){ ?>
<?php echo $translationsLogin['login_info_session expired']; ?>. <?php echo $translationsLogin['login_info_session expired']; ?>.
<?php } ?> <?php } ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>