-
diff --git a/app/Http/Requests/Auth/PasswordResetRequest.php b/app/Http/Requests/Auth/PasswordResetRequest.php index b26a08e..b9b53f0 100644 --- a/app/Http/Requests/Auth/PasswordResetRequest.php +++ b/app/Http/Requests/Auth/PasswordResetRequest.php @@ -16,7 +16,24 @@ class PasswordResetRequest extends Request return [ 'token' => 'required', 'email' => 'required|email', - 'password' => 'required|confirmed|min:8' + 'password' => [ + 'required', + 'confirmed', + 'min:8', + 'regex:/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/' + ], + ]; + } + + /** + * Get custom messages for validator errors. + * + * @return array + */ + public function messages() + { + return [ + 'password.regex' => __('The password must be at least 8 characters long and contain at least one number and one special character (@$!%*?&).') ]; } diff --git a/app/Http/Requests/Auth/RegisterRequest.php b/app/Http/Requests/Auth/RegisterRequest.php index 9d07dd0..2134998 100644 --- a/app/Http/Requests/Auth/RegisterRequest.php +++ b/app/Http/Requests/Auth/RegisterRequest.php @@ -14,10 +14,15 @@ class RegisterRequest extends Request */ public function rules() { - $rules = [ + $rules = [ 'email' => 'required|email|unique:users,email', 'username' => 'required|unique:users,username', - 'password' => 'required|confirmed|min:8', + 'password' => [ + 'required', + 'confirmed', + 'min:8', + 'regex:/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/' + ], ]; if (setting('registration.captcha.enabled')) { @@ -36,10 +41,11 @@ class RegisterRequest extends Request * * @return array */ - public function messages() +public function messages() { return [ - 'tos.accepted' => __('You have to accept Terms of Service.') + 'tos.accepted' => __('You have to accept Terms of Service.'), + 'password.regex' => __('The password must be at least 8 characters long and contain at least one number and one special character (@$!%*?&).') ]; } diff --git a/app/Http/Requests/User/CreateUserRequest.php b/app/Http/Requests/User/CreateUserRequest.php index 52f82a6..201b565 100644 --- a/app/Http/Requests/User/CreateUserRequest.php +++ b/app/Http/Requests/User/CreateUserRequest.php @@ -17,7 +17,12 @@ class CreateUserRequest extends Request $rules = [ 'email' => 'required|email|unique:users,email', 'username' => 'nullable|unique:users,username', - 'password' => 'required|min:6|confirmed', + 'password' => [ + 'required', + 'confirmed', + 'min:8', + 'regex:/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/' + ], 'birthday' => 'nullable|date', 'role_id' => 'required|exists:roles,id', 'verified' => 'boolean' @@ -29,4 +34,16 @@ class CreateUserRequest extends Request return $rules; } + + /** + * Get custom messages for validator errors. + * + * @return array + */ + public function messages() + { + return [ + 'password.regex' => __('The password must be at least 8 characters long and contain at least one number and one special character (@$!%*?&).') + ]; + } } diff --git a/app/Http/Requests/User/UpdateLoginDetailsRequest.php b/app/Http/Requests/User/UpdateLoginDetailsRequest.php index f46f149..8e2811f 100644 --- a/app/Http/Requests/User/UpdateLoginDetailsRequest.php +++ b/app/Http/Requests/User/UpdateLoginDetailsRequest.php @@ -19,7 +19,24 @@ class UpdateLoginDetailsRequest extends Request return [ 'email' => 'required|email|unique:users,email,' . $user->id, 'username' => 'nullable|unique:users,username,' . $user->id, - 'password' => 'nullable|min:8|confirmed' + 'password' => [ + 'nullable', + 'confirmed', + 'min:8', + 'regex:/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/' + ], + ]; + } + + /** + * Get custom messages for validator errors. + * + * @return array + */ + public function messages() + { + return [ + 'password.regex' => __('The password must be at least 8 characters long and contain at least one number and one special character (@$!%*?&).') ]; } diff --git a/app/Http/Requests/User/UpdateUserRequest.php b/app/Http/Requests/User/UpdateUserRequest.php index a502ca5..c338e9a 100644 --- a/app/Http/Requests/User/UpdateUserRequest.php +++ b/app/Http/Requests/User/UpdateUserRequest.php @@ -21,11 +21,28 @@ class UpdateUserRequest extends Request return [ 'email' => 'email|unique:users,email,' . $user->id, 'username' => 'nullable|unique:users,username,' . $user->id, - 'password' => 'min:6|confirmed', + 'password' => [ + 'nullable', + 'confirmed', + 'min:8', + 'regex:/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/' + ], 'birthday' => 'nullable|date', 'role_id' => 'exists:roles,id', 'country_id' => 'exists:countries,id', 'status' => Rule::in(array_keys(UserStatus::lists())) ]; } + + /** + * Get custom messages for validator errors. + * + * @return array + */ + public function messages() + { + return [ + 'password.regex' => __('The password must be at least 8 characters long and contain at least one number and one special character (@$!%*?&).') + ]; + } } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index dd689ef..d9e2564 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -33,7 +33,10 @@ class EventServiceProvider extends ServiceProvider ], Verified::class => [ ActivateUser::class - ] + ], + \SocialiteProviders\Manager\SocialiteWasCalled::class => [ + 'SocialiteProviders\\Azure\\AzureExtendSocialite@handle', // Usa una stringa con @handle + ], ]; /** diff --git a/composer.json b/composer.json index b5bf334..6f46186 100644 --- a/composer.json +++ b/composer.json @@ -42,6 +42,7 @@ "laravel/ui": "^4.0", "laravelcollective/html": "^6.3", "proengsoft/laravel-jsvalidation": "^4.0.0", + "socialiteproviders/microsoft-azure": "^5.2", "spatie/laravel-query-builder": "^5.0", "vanguardapp/activity-log": "^5.0", "vanguardapp/announcements": "^5.0", diff --git a/composer.lock b/composer.lock index 545cbf3..e05a6aa 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0868d0ed54d8695b929de611fc8beeab", + "content-hash": "df98df06998bb59ef615306b9f0d421b", "packages": [ { "name": "akaunting/laravel-setting", @@ -4145,6 +4145,131 @@ }, "time": "2024-07-01T07:33:21+00:00" }, + { + "name": "socialiteproviders/manager", + "version": "v4.8.1", + "source": { + "type": "git", + "url": "https://github.com/SocialiteProviders/Manager.git", + "reference": "8180ec14bef230ec2351cff993d5d2d7ca470ef4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/SocialiteProviders/Manager/zipball/8180ec14bef230ec2351cff993d5d2d7ca470ef4", + "reference": "8180ec14bef230ec2351cff993d5d2d7ca470ef4", + "shasum": "" + }, + "require": { + "illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0", + "laravel/socialite": "^5.5", + "php": "^8.1" + }, + "require-dev": { + "mockery/mockery": "^1.2", + "phpunit/phpunit": "^9.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "SocialiteProviders\\Manager\\ServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "SocialiteProviders\\Manager\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Andy Wendt", + "email": "andy@awendt.com" + }, + { + "name": "Anton Komarev", + "email": "a.komarev@cybercog.su" + }, + { + "name": "Miguel Piedrafita", + "email": "soy@miguelpiedrafita.com" + }, + { + "name": "atymic", + "email": "atymicq@gmail.com", + "homepage": "https://atymic.dev" + } + ], + "description": "Easily add new or override built-in providers in Laravel Socialite.", + "homepage": "https://socialiteproviders.com", + "keywords": [ + "laravel", + "manager", + "oauth", + "providers", + "socialite" + ], + "support": { + "issues": "https://github.com/socialiteproviders/manager/issues", + "source": "https://github.com/socialiteproviders/manager" + }, + "time": "2025-02-24T19:33:30+00:00" + }, + { + "name": "socialiteproviders/microsoft-azure", + "version": "5.2.0", + "source": { + "type": "git", + "url": "https://github.com/SocialiteProviders/Microsoft-Azure.git", + "reference": "453d62c9d7e3b3b76e94c913fb46e68a33347b16" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/SocialiteProviders/Microsoft-Azure/zipball/453d62c9d7e3b3b76e94c913fb46e68a33347b16", + "reference": "453d62c9d7e3b3b76e94c913fb46e68a33347b16", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "^8.0", + "socialiteproviders/manager": "^4.4" + }, + "type": "library", + "autoload": { + "psr-4": { + "SocialiteProviders\\Azure\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Chris Hemmings", + "email": "chris@hemmin.gs" + } + ], + "description": "Microsoft Azure OAuth2 Provider for Laravel Socialite", + "keywords": [ + "azure", + "laravel", + "microsoft", + "oauth", + "provider", + "socialite" + ], + "support": { + "docs": "https://socialiteproviders.com/microsoft-azure", + "issues": "https://github.com/socialiteproviders/providers/issues", + "source": "https://github.com/socialiteproviders/providers" + }, + "time": "2024-03-15T03:02:10+00:00" + }, { "name": "spatie/laravel-package-tools", "version": "1.14.2", diff --git a/config/app.php b/config/app.php index 84ea40f..7e1da9c 100644 --- a/config/app.php +++ b/config/app.php @@ -198,7 +198,7 @@ return [ Illuminate\Pagination\PaginationServiceProvider::class, Illuminate\Pipeline\PipelineServiceProvider::class, Illuminate\Queue\QueueServiceProvider::class, -// Illuminate\Redis\RedisServiceProvider::class, + // Illuminate\Redis\RedisServiceProvider::class, Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, Illuminate\Session\SessionServiceProvider::class, Illuminate\Translation\TranslationServiceProvider::class, @@ -227,6 +227,7 @@ return [ Vanguard\Providers\RouteServiceProvider::class, Vanguard\Services\Auth\TwoFactor\AuthyServiceProvider::class, Vanguard\Providers\VanguardServiceProvider::class, + \SocialiteProviders\Manager\ServiceProvider::class, ], /* diff --git a/config/auth.php b/config/auth.php index 7fd7a5d..78fa04b 100644 --- a/config/auth.php +++ b/config/auth.php @@ -12,10 +12,10 @@ return [ */ 'social' => [ - 'providers' => ['facebook', 'twitter', 'google'] + 'providers' => ['azure'] ], - /* + /* |-------------------------------------------------------------------------- | JSON API |-------------------------------------------------------------------------- diff --git a/config/services.php b/config/services.php index 1c658f3..90a27cd 100644 --- a/config/services.php +++ b/config/services.php @@ -65,5 +65,11 @@ return [ 'authy' => [ 'key' => env('AUTHY_KEY') + ], + + 'azure' => [ + 'client_id' => env('AZURE_CLIENT_ID'), + 'client_secret' => env('AZURE_CLIENT_SECRET'), + 'redirect' => env('AZURE_REDIRECT_URI'), ] ]; diff --git a/public/userarea.zip b/public/userarea.zip new file mode 100644 index 0000000..2ce9d70 Binary files /dev/null and b/public/userarea.zip differ diff --git a/public/userarea/apilogic/api-to-temp - Copia050325.php b/public/userarea/apilogic/api-to-temp - Copia050325.php new file mode 100644 index 0000000..c7bb0a4 --- /dev/null +++ b/public/userarea/apilogic/api-to-temp - Copia050325.php @@ -0,0 +1,167 @@ +connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +// Check if POST request was received +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + // Array to collect messages about file processing + $file_messages = []; + + // Receive JSON from the laboratory via a field in the form (e.g., 'json_data') + if (isset($_POST['json_data'])) { + $json_data = $_POST['json_data']; + + // Decode JSON for optional validation + $decoded_data = json_decode($json_data, true); + + // If the JSON is valid + if (json_last_error() === JSON_ERROR_NONE) { + // Authenticate using key, secret_key, and reflab + if (!isset($decoded_data['key']) || !isset($decoded_data['secret_key']) || !isset($decoded_data['reflab'])) { + echo json_encode([ + "status" => "error", + "message" => "Missing authentication fields (key, secret_key, reflab)." + ]); + exit; + } + + $api_key = $decoded_data['key']; + $secret_key = $decoded_data['secret_key']; + $reflab = $decoded_data['reflab']; + + $query = "SELECT * FROM laboratories WHERE reflab = ? AND api_key = ?"; + $stmt = $conn->prepare($query); + $stmt->bind_param("ss", $reflab, $api_key); + $stmt->execute(); + $result = $stmt->get_result(); + + // Check if a valid laboratory was found with `reflab` and `api_key` + if ($result->num_rows > 0) { + $row = $result->fetch_assoc(); + + // Verify the status of the laboratory + if ($row['status'] !== 'active') { + echo json_encode([ + "status" => "error", + "message" => "Laboratory is inactive." + ]); + exit; + } + + // Verify the secret key using `password_verify` + if (!password_verify($secret_key, $row['api_secret'])) { + echo json_encode([ + "status" => "error", + "message" => "Invalid secret key." + ]); + exit; + } + } else { + // Check if the `reflab` is valid, but the `api_key` doesn't match + $query = "SELECT * FROM laboratories WHERE reflab = ?"; + $stmt = $conn->prepare($query); + $stmt->bind_param("s", $reflab); + $stmt->execute(); + $result = $stmt->get_result(); + + if ($result->num_rows > 0) { + echo json_encode([ + "status" => "error", + "message" => "Invalid API key." + ]); + } else { + echo json_encode([ + "status" => "error", + "message" => "Invalid reflab." + ]); + } + exit; + } + + // Generate a UUID to uniquely identify the record + $uuid = uniqid(); // Alternatively, use UUID() in MySQL + + // Extract some information from JSON + if (!isset($decoded_data['product']['products_refnumber'])) { + echo json_encode([ + "status" => "error", + "message" => "Missing product reference number." + ]); + exit; + } + + $product_refnumber = $decoded_data['product']['products_refnumber']; // Product number + $report_number = $decoded_data['product']['reports'][0]['reportsNumberLab'] ?? null; // Report number + $rating = $decoded_data['product']['reports'][0]['reportsRating'] ?? null; // Report rating (e.g., Pass/Fail) + $saved_at = date("Y-m-d H:i:s"); // Save date + + // Query to insert data into the temp_json_queue table + $stmt = $conn->prepare("INSERT INTO temp_json_queue (uuid, lab_id, json_data) VALUES (?, ?, ?)"); + $lab_id = 1; // Set lab_id to a fixed value for testing purposes + $stmt->bind_param("sss", $uuid, $lab_id, $json_data); + + if ($stmt->execute()) { + // Handle file uploads if they exist + if (!empty($_FILES)) { + include('process_files.php'); // Include file processing logic here + + // Retrieve any messages added in process_files.php for files + if (!empty($GLOBALS['file_messages'])) { + $file_messages = $GLOBALS['file_messages']; + } + } + + // Set a session variable to notify the report import + $_SESSION['new_report'] = [ + 'report_number' => $report_number, + 'rating' => $rating, + 'timestamp' => time() // You can use a timestamp to manage the expiration of the notification + ]; + + echo json_encode([ + "status" => "success", + "message" => "Data successfully saved.", + "uuid" => $uuid, + "product_refnumber" => $product_refnumber, // Product number + "report_number" => $report_number, // Report number + "rating" => $rating, // Report rating + "saved_at" => $saved_at, // Save date + "file_messages" => $file_messages // Include file messages + ]); + } else { + echo json_encode([ + "status" => "error", + "message" => "Failed to save data." + ]); + } + + $stmt->close(); + } else { + // If the JSON is invalid + echo json_encode([ + "status" => "error", + "message" => "Invalid JSON format." + ]); + } + } else { + echo json_encode([ + "status" => "error", + "message" => "Missing JSON data." + ]); + } +} else { + echo json_encode([ + "status" => "error", + "message" => "Invalid request method." + ]); +} + +// Close the database connection +$conn->close(); diff --git a/public/userarea/apilogic/api-to-temp.php b/public/userarea/apilogic/api-to-temp.php index c7bb0a4..f324c8d 100644 --- a/public/userarea/apilogic/api-to-temp.php +++ b/public/userarea/apilogic/api-to-temp.php @@ -23,73 +23,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { // If the JSON is valid if (json_last_error() === JSON_ERROR_NONE) { - // Authenticate using key, secret_key, and reflab - if (!isset($decoded_data['key']) || !isset($decoded_data['secret_key']) || !isset($decoded_data['reflab'])) { - echo json_encode([ - "status" => "error", - "message" => "Missing authentication fields (key, secret_key, reflab)." - ]); - exit; - } - - $api_key = $decoded_data['key']; - $secret_key = $decoded_data['secret_key']; - $reflab = $decoded_data['reflab']; - - $query = "SELECT * FROM laboratories WHERE reflab = ? AND api_key = ?"; - $stmt = $conn->prepare($query); - $stmt->bind_param("ss", $reflab, $api_key); - $stmt->execute(); - $result = $stmt->get_result(); - - // Check if a valid laboratory was found with `reflab` and `api_key` - if ($result->num_rows > 0) { - $row = $result->fetch_assoc(); - - // Verify the status of the laboratory - if ($row['status'] !== 'active') { - echo json_encode([ - "status" => "error", - "message" => "Laboratory is inactive." - ]); - exit; - } - - // Verify the secret key using `password_verify` - if (!password_verify($secret_key, $row['api_secret'])) { - echo json_encode([ - "status" => "error", - "message" => "Invalid secret key." - ]); - exit; - } - } else { - // Check if the `reflab` is valid, but the `api_key` doesn't match - $query = "SELECT * FROM laboratories WHERE reflab = ?"; - $stmt = $conn->prepare($query); - $stmt->bind_param("s", $reflab); - $stmt->execute(); - $result = $stmt->get_result(); - - if ($result->num_rows > 0) { - echo json_encode([ - "status" => "error", - "message" => "Invalid API key." - ]); - } else { - echo json_encode([ - "status" => "error", - "message" => "Invalid reflab." - ]); - } - exit; - } - - // Generate a UUID to uniquely identify the record - $uuid = uniqid(); // Alternatively, use UUID() in MySQL - - // Extract some information from JSON - if (!isset($decoded_data['product']['products_refnumber'])) { + // Check only for the required product_refnumber + if (!isset($decoded_data['product']) || !is_array($decoded_data['product']) || !isset($decoded_data['product'][0]['products_refnumber'])) { echo json_encode([ "status" => "error", "message" => "Missing product reference number." @@ -97,9 +32,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { exit; } - $product_refnumber = $decoded_data['product']['products_refnumber']; // Product number - $report_number = $decoded_data['product']['reports'][0]['reportsNumberLab'] ?? null; // Report number - $rating = $decoded_data['product']['reports'][0]['reportsRating'] ?? null; // Report rating (e.g., Pass/Fail) + // Generate a UUID to uniquely identify the record + $uuid = uniqid(); // Alternatively, use UUID() in MySQL + + // Extract some information from JSON + $product_refnumber = $decoded_data['product'][0]['products_refnumber']; + $report_number = $decoded_data['product'][0]['reports'][0]['reportsNumberLab'] ?? null; + $rating = $decoded_data['product'][0]['reports'][0]['reportsRating'] ?? null; $saved_at = date("Y-m-d H:i:s"); // Save date // Query to insert data into the temp_json_queue table diff --git a/public/userarea/apilogic/api-to-temp110325.php b/public/userarea/apilogic/api-to-temp110325.php new file mode 100644 index 0000000..115f44b --- /dev/null +++ b/public/userarea/apilogic/api-to-temp110325.php @@ -0,0 +1,168 @@ +connect_error) { + die("Connection failed: " . $conn->connect_error); +} + +// Check if POST request was received +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + // Array to collect messages about file processing + $file_messages = []; + + // Receive JSON from the laboratory via a field in the form (e.g., 'json_data') + if (isset($_POST['json_data'])) { + $json_data = $_POST['json_data']; + + // Decode JSON for optional validation + $decoded_data = json_decode($json_data, true); + + // If the JSON is valid + if (json_last_error() === JSON_ERROR_NONE) { + // Authenticate using key, secret_key, and reflab + if (!isset($decoded_data['key']) || !isset($decoded_data['secret_key']) || !isset($decoded_data['reflab'])) { + echo json_encode([ + "status" => "error", + "message" => "Missing authentication fields (key, secret_key, reflab)." + ]); + exit; + } + + $api_key = $decoded_data['key']; + $secret_key = $decoded_data['secret_key']; + $reflab = $decoded_data['reflab']; + + $query = "SELECT * FROM laboratories WHERE reflab = ? AND api_key = ?"; + $stmt = $conn->prepare($query); + $stmt->bind_param("ss", $reflab, $api_key); + $stmt->execute(); + $result = $stmt->get_result(); + + // Check if a valid laboratory was found with `reflab` and `api_key` + if ($result->num_rows > 0) { + $row = $result->fetch_assoc(); + + // Verify the status of the laboratory + if ($row['status'] !== 'active') { + echo json_encode([ + "status" => "error", + "message" => "Laboratory is inactive." + ]); + exit; + } + + // Verify the secret key using `password_verify` + if (!password_verify($secret_key, $row['api_secret'])) { + echo json_encode([ + "status" => "error", + "message" => "Invalid secret key." + ]); + exit; + } + } else { + // Check if the `reflab` is valid, but the `api_key` doesn't match + $query = "SELECT * FROM laboratories WHERE reflab = ?"; + $stmt = $conn->prepare($query); + $stmt->bind_param("s", $reflab); + $stmt->execute(); + $result = $stmt->get_result(); + + if ($result->num_rows > 0) { + echo json_encode([ + "status" => "error", + "message" => "Invalid API key." + ]); + } else { + echo json_encode([ + "status" => "error", + "message" => "Invalid reflab." + ]); + } + exit; + } + + // Generate a UUID to uniquely identify the record + $uuid = uniqid(); // Alternatively, use UUID() in MySQL + + // Extract some information from JSON + // Estrai products_refnumber dal primo elemento dell'array product + if (!isset($decoded_data['product']) || !is_array($decoded_data['product']) || !isset($decoded_data['product'][0]['products_refnumber'])) { + echo json_encode([ + "status" => "error", + "message" => "Missing product reference number." + ]); + exit; + } + + $product_refnumber = $decoded_data['product'][0]['products_refnumber']; + $report_number = $decoded_data['product'][0]['reports'][0]['reportsNumberLab'] ?? null; + $rating = $decoded_data['product'][0]['reports'][0]['reportsRating'] ?? null; + $saved_at = date("Y-m-d H:i:s"); // Save date + + // Query to insert data into the temp_json_queue table + $stmt = $conn->prepare("INSERT INTO temp_json_queue (uuid, lab_id, json_data) VALUES (?, ?, ?)"); + $lab_id = 1; // Set lab_id to a fixed value for testing purposes + $stmt->bind_param("sss", $uuid, $lab_id, $json_data); + + if ($stmt->execute()) { + // Handle file uploads if they exist + if (!empty($_FILES)) { + include('process_files.php'); // Include file processing logic here + + // Retrieve any messages added in process_files.php for files + if (!empty($GLOBALS['file_messages'])) { + $file_messages = $GLOBALS['file_messages']; + } + } + + // Set a session variable to notify the report import + $_SESSION['new_report'] = [ + 'report_number' => $report_number, + 'rating' => $rating, + 'timestamp' => time() // You can use a timestamp to manage the expiration of the notification + ]; + + echo json_encode([ + "status" => "success", + "message" => "Data successfully saved.", + "uuid" => $uuid, + "product_refnumber" => $product_refnumber, // Product number + "report_number" => $report_number, // Report number + "rating" => $rating, // Report rating + "saved_at" => $saved_at, // Save date + "file_messages" => $file_messages // Include file messages + ]); + } else { + echo json_encode([ + "status" => "error", + "message" => "Failed to save data." + ]); + } + + $stmt->close(); + } else { + // If the JSON is invalid + echo json_encode([ + "status" => "error", + "message" => "Invalid JSON format." + ]); + } + } else { + echo json_encode([ + "status" => "error", + "message" => "Missing JSON data." + ]); + } +} else { + echo json_encode([ + "status" => "error", + "message" => "Invalid request method." + ]); +} + +// Close the database connection +$conn->close(); diff --git a/public/userarea/class/db-functions.php b/public/userarea/class/db-functions.php new file mode 100644 index 0000000..509e483 --- /dev/null +++ b/public/userarea/class/db-functions.php @@ -0,0 +1,40 @@ +load(); + + $host = $_ENV['DB_HOST']; + $db = $_ENV['DB_DATABASE']; + $user = $_ENV['DB_USERNAME']; + $pass = $_ENV['DB_PASSWORD']; + $charset = 'utf8mb4'; + + $dsn = "mysql:host=$host;dbname=$db;charset=$charset"; + $options = [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false, + ]; + + try { + $this->pdo = new PDO($dsn, $user, $pass, $options); + } catch (PDOException $e) { + die("Database connection failed: " . $e->getMessage()); + } + } + + public function getConnection() + { + return $this->pdo; + } +} diff --git a/public/userarea/class/mailer.php b/public/userarea/class/mailer.php new file mode 100644 index 0000000..851e4cf --- /dev/null +++ b/public/userarea/class/mailer.php @@ -0,0 +1,61 @@ +load(); + +function sendEmail($to, $subject, $body, $attachments = [], $cc = [], $bcc = []) +{ + // Configurazione SMTP + $mail = new PHPMailer(true); + try { + // Configurazione server SMTP con dati da .env + $mail->isSMTP(); + $mail->Host = $_ENV['MAIL_HOST'] ?? 'smtp.example.com'; + $mail->SMTPAuth = true; + $mail->Username = $_ENV['MAIL_USERNAME'] ?? 'email@example.com'; + $mail->Password = $_ENV['MAIL_PASSWORD'] ?? 'password'; + $mail->SMTPSecure = $_ENV['MAIL_ENCRYPTION'] ?? PHPMailer::ENCRYPTION_STARTTLS; + $mail->Port = $_ENV['MAIL_PORT'] ?? 587; + + // Mittente + $mail->setFrom($_ENV['MAIL_FROM_ADDRESS'] ?? 'default@example.com', $_ENV['MAIL_FROM_NAME'] ?? 'Default Name'); + + // Destinatari principali + foreach ((array)$to as $recipient) { + $mail->addAddress($recipient); + } + + // Destinatari CC + foreach ((array)$cc as $recipient) { + $mail->addCC($recipient); + } + + // Destinatari BCC + foreach ((array)$bcc as $recipient) { + $mail->addBCC($recipient); + } + + // Allegati + foreach ((array)$attachments as $file) { + $mail->addAttachment($file); + } + + // Contenuto dell'email + $mail->isHTML(true); + $mail->Subject = $subject; + $mail->Body = $body; + + // Invia l'email + $mail->send(); + return ['success' => true, 'message' => 'Email inviata con successo.']; + } catch (Exception $e) { + return ['success' => false, 'message' => "Errore nell'invio dell'email: {$mail->ErrorInfo}"]; + } +} diff --git a/public/userarea/cssinclude.php b/public/userarea/cssinclude.php new file mode 100644 index 0000000..b439e93 --- /dev/null +++ b/public/userarea/cssinclude.php @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/public/userarea/include/headscript.php b/public/userarea/include/headscript.php index bec308e..838d6bb 100644 --- a/public/userarea/include/headscript.php +++ b/public/userarea/include/headscript.php @@ -4,11 +4,8 @@ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL | E_STRICT); -define('BASE_PATH', realpath(__DIR__ . '/../../..')); -define('BASE_URL', '/reportifynew/public/'); -define('USERAREA_PATH', '/reportifynew/public/userarea/'); -define('INCLUDE_PATH', BASE_URL . 'userarea/include/'); -define('ASSETS_PATH', BASE_URL . 'userarea/include/assets/'); +require_once __DIR__ . '/path_definition.php'; + // This should be equal to: PATH_TO_VANGUARD_FOLDER/extra/auth.php require_once(BASE_PATH . '/extra/auth.php'); @@ -75,11 +72,7 @@ if (isset($_SESSION["infobox"])) { ?> diff --git a/public/userarea/include/path_definition.php b/public/userarea/include/path_definition.php new file mode 100644 index 0000000..d4d95d6 --- /dev/null +++ b/public/userarea/include/path_definition.php @@ -0,0 +1,8 @@ + getConnection(); // Query 1: Numero totale di prodotti $totalProductsQuery = "SELECT COUNT(DISTINCT p.idproducts) AS totalProducts FROM products p WHERE 1=1"; -$totalProductsResult = $conn->query($totalProductsQuery); -$totalProducts = $totalProductsResult->fetch_assoc()['totalProducts']; +$stmt = $pdo->query($totalProductsQuery); +$totalProducts = $stmt->fetch(PDO::FETCH_ASSOC)['totalProducts']; // Query 2: Numero totale di report $totalReportsQuery = " SELECT COUNT(DISTINCT r.idreports) AS totalReports FROM reports r LEFT JOIN products p ON r.idproducts = p.idproducts"; -$totalReportsResult = $conn->query($totalReportsQuery); -$totalReports = $totalReportsResult->fetch_assoc()['totalReports']; +$stmt = $pdo->query($totalReportsQuery); +$totalReports = $stmt->fetch(PDO::FETCH_ASSOC)['totalReports']; // Query 3: Numero di report "fail" $failedReportsQuery = " @@ -22,39 +26,29 @@ $failedReportsQuery = " FROM reports r LEFT JOIN products p ON r.idproducts = p.idproducts WHERE UPPER(r.reportsRating) IN ('FAIL', 'F', 'DOESN\'T COMPLY')"; -$failedReportsResult = $conn->query($failedReportsQuery); -$failedReports = $failedReportsResult->fetch_assoc()['failedReports']; +$stmt = $pdo->query($failedReportsQuery); +$failedReports = $stmt->fetch(PDO::FETCH_ASSOC)['failedReports']; +// Query 4: Numero totale di test $totalTestsQuery = " SELECT COUNT(DISTINCT ap.idreports, ap.idPart, ap.result_TestName) AS totalTests FROM analysis_project ap LEFT JOIN result_project rp ON ap.idAnalysis_Project = rp.idanalysis_project LEFT JOIN reports r ON ap.idreports = r.idreports LEFT JOIN products p ON r.idproducts = p.idproducts"; -$totalTestsResult = $conn->query($totalTestsQuery); -$totalTests = $totalTestsResult->fetch_assoc()['totalTests']; -// Verifica connessione -if ($conn->connect_error) { - die("Connessione fallita: " . $conn->connect_error); -} -?> -query($totalTestsQuery); +$totalTests = $stmt->fetch(PDO::FETCH_ASSOC)['totalTests']; +// Query per ottenere i moduli attivi e disattivi $query = " SELECT idmodules, activemod FROM activemodules - WHERE idcompany = ? + WHERE idcompany = :idcompany "; -$stmt = $conn->prepare($query); -$stmt->bind_param("i", $idcompany); -$stmt->execute(); -$result = $stmt->get_result(); - +$stmt = $pdo->prepare($query); +$stmt->execute(['idcompany' => $idcompany]); $modulesStatus = []; -while ($row = $result->fetch_assoc()) { +while ($row = $stmt->fetch()) { $modulesStatus[$row['idmodules']] = $row['activemod']; } ?> @@ -72,14 +66,10 @@ while ($row = $result->fetch_assoc()) { - - - - + -
@@ -95,15 +85,13 @@ while ($row = $result->fetch_assoc()) { -