Skip to content

Commit

Permalink
Merge pull request #8 from HelloAsso/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
emnbdx authored Nov 7, 2024
2 parents 9caea0d + c851fde commit 6bdefba
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 95 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ CLIENT_ID=
CLIENT_SECRET=

ENCRYPTION_KEY=

WEBSITE_DOMAIN=http://localhost:3000
WEBSITE_DOMAIN=http://localhost:3000
MANDRILL_API=
3 changes: 2 additions & 1 deletion .github/workflows/php-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
envkey_CLIENT_SECRET: ${{ secrets.PROD_CLIENT_SECRET }}
envkey_ENCRYPTION_KEY: ${{ secrets.PROD_ENCRYPTION_KEY }}
envkey_WEBSITE_DOMAIN: ${{ vars.PROD_WEBSITE_DOMAIN }}
envkey_MANDRILL_API: ${{ vars.PROD_MANDRILL_API }}
file_name: .env

- name: SFTP Deploy
Expand All @@ -71,5 +72,5 @@ jobs:
.git*
composer.*
package*
README.MD
*.MD
3 changes: 2 additions & 1 deletion .github/workflows/php-sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
envkey_CLIENT_SECRET: ${{ secrets.SANDBOX_CLIENT_SECRET }}
envkey_ENCRYPTION_KEY: ${{ secrets.SANDBOX_ENCRYPTION_KEY }}
envkey_WEBSITE_DOMAIN: ${{ vars.SANDBOX_WEBSITE_DOMAIN }}
envkey_MANDRILL_API: ${{ vars.SANDBOX_MANDRILL_API }}
file_name: .env

- name: SFTP Deploy
Expand All @@ -71,5 +72,5 @@ jobs:
.git*
composer.*
package*
README.MD
*.MD
15 changes: 4 additions & 11 deletions admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,10 @@
// Générer un GUID unique pour le nouveau Charity Stream
$guid = bin2hex(random_bytes(16)); // Utilisation de bin2hex pour obtenir une chaîne hexadécimale

// Check if form exist
$data = $apiWrapper->GetDonationForm($organizationSlug, $formSlug);

if(!$data) {
echo '<div class="alert alert-danger" role="alert">Ce formulaire n\'existe pas</div>';
} else {
// Appeler la fonction pour créer le Charity Stream
$_SESSION[$guid . 'password'] = $repository->createCharityStreamDB($guid, $ownerEmail, $formSlug, $organizationSlug, $title);
header("Location: /admin/index.php");
exit();
}
// Appeler la fonction pour créer le Charity Stream
$_SESSION[$guid . 'password'] = $repository->createCharityStreamDB($guid, $ownerEmail, $formSlug, $organizationSlug, $title);
header("Location: /admin/index.php");
exit();
}

if (isset($_POST['refresh_password'])) {
Expand Down
35 changes: 0 additions & 35 deletions app/ApiWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,41 +338,6 @@ function exchangeAuthorizationCode($code, $redirect_uri, $codeVerifier)

// Organizations

function GetDonationForm($organizationSlug, $donationSlug)
{
$accessToken = $this->getGlobalTokensAndRefreshIfNecessary();
if (!$accessToken || !isset($accessToken['access_token'])) {
http_response_code(401);
echo json_encode(['error' => 'Jeton d\'accès API non trouvé ou expiré.']);
exit;
}

$curl = curl_init();

// Construire l'URL avec ou sans continuationToken
$url = $this->apiUrl . '/organizations/' . $organizationSlug . '/forms/donation/' . $donationSlug . '/public';

curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . $accessToken['access_token']
),
));

$response = curl_exec($curl);
curl_close($curl);

$response_data = json_decode($response, true);
return $response_data;
}

function GetDonationFormOrders($organizationSlug, $donationSlug, $accessToken, $continuationToken = null, $from = null)
{
$curl = curl_init();
Expand Down
2 changes: 2 additions & 0 deletions app/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Config
public $haUrl = null;
public $haIps = null;
public $webSiteDomain = null;
public $mandrillApi = null;

private function getDb()
{
Expand Down Expand Up @@ -70,6 +71,7 @@ private function __construct()
$this->haUrl = $_ENV['HA_URL'];
$this->haIps = isset($_ENV['HA_IPS']) ? explode(",", $_ENV['HA_IPS']) : [];
$this->webSiteDomain = $_ENV['WEBSITE_DOMAIN'];
$this->mandrillApi = $_ENV['MANDRILL_API'];
}

public static function getInstance()
Expand Down
26 changes: 21 additions & 5 deletions app/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function updateAlertBoxWidgetDB($guidBinary, $postData, $image = null, $sound =
$guidBinary
]);

if(isset($image)) {
if (isset($image)) {
$stmt = $this->db->prepare('
UPDATE ' . $this->prefix . 'widget_alert_box
SET image = ?
Expand All @@ -90,7 +90,7 @@ function updateAlertBoxWidgetDB($guidBinary, $postData, $image = null, $sound =
]);
}

if(isset($sound)) {
if (isset($sound)) {
$stmt = $this->db->prepare('
UPDATE ' . $this->prefix . 'widget_alert_box
SET sound = ?
Expand All @@ -106,15 +106,15 @@ function updateAlertBoxWidgetDB($guidBinary, $postData, $image = null, $sound =
function createCharityStreamDB($guid, $owner_email, $form_slug, $organization_slug, $title)
{
$password = Helpers::generateRandomString(30);

$query = 'INSERT INTO ' . $this->prefix . 'users (email, password)
VALUES (:email, :password)';
$stmt = $this->db->prepare($query);
$stmt->execute([
':email' => $owner_email,
':password' => password_hash($password, PASSWORD_DEFAULT)
]);

$query = 'INSERT INTO ' . $this->prefix . 'charity_stream (guid, owner_email, form_slug, organization_slug, title, state)
VALUES (:guid, :owner_email, :form_slug, :organization_slug, :title, 1)';
$stmt = $this->db->prepare($query);
Expand Down Expand Up @@ -181,7 +181,7 @@ function getUser($email)
function updateUserPassword($email)
{
$password = Helpers::generateRandomString(30);

$query = 'UPDATE ' . $this->prefix . 'users
SET password = :password
WHERE email = :email';
Expand Down Expand Up @@ -288,6 +288,22 @@ function getAccessTokensDB($organization_slug)
return null;
}

function getAccessTokensToRefresh()
{
$stmt = $this->db->prepare('SELECT *
FROM ' . $this->prefix . 'access_token_partner_organization
WHERE organization_slug IS NOT NULL
AND refresh_token_expires_at > now()
AND refresh_token_expires_at <= DATE_ADD(NOW(), INTERVAL 24 HOUR);');
$stmt->execute();

if ($stmt->rowCount() > 0) {
return $stmt->fetchAll();
}

return null;
}


function getAuthorizationCodeByIdDB($id)
{
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"require": {
"vlucas/phpdotenv": "^5.6",
"microsoft/azure-storage-blob": "^1.5",
"league/mime-type-detection": "^1.15"
"league/mime-type-detection": "^1.15",
"mailchimp/transactional": "^1.0"
}
}
Loading

0 comments on commit 6bdefba

Please sign in to comment.