Skip to content

Commit

Permalink
Merge pull request #7 from HelloAsso/feature/update-validation
Browse files Browse the repository at this point in the history
Update validation process
  • Loading branch information
emnbdx authored Nov 7, 2024
2 parents 6b3d1c9 + 3371c1e commit fcc8015
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 52 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=
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
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"
}
}
56 changes: 55 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions validate_grant_authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
}
catch (Exception $e)
{
throw new Exception("Erreur de MAJ en base de données : $e->getMessage()");
throw new Exception("Erreur de MAJ en base de données : " . $e->getMessage());
}
}
else
Expand All @@ -61,9 +61,26 @@
);

echo 'Votre compte ' . $tokenDataGrantAuthorization['organization_slug'] . ' à bien été lié à HelloAssoCharityStream, vous pouvez fermer cette page.';

$mailchimp = new \MailchimpTransactional\ApiClient();
$mailchimp->setApiKey(Config::getInstance()->mandrillApi);

$mailchimp->messages->send([
"message" => [
"from_email" => "contact@helloasso.io",
"from_name" => "HelloAsso",
"subject" => "Une association vient de valider sa mire" ,
"html" => "<p>L'association " . $tokenDataGrantAuthorization['organization_slug'] . " vient de valider sa mire d'authorisation sur l'environnement " . Config::getInstance()->webSiteDomain . "</p>",
"to" => [
[
"email" => "helloasso.stream@helloasso.org "
]
],
]
]);
}
catch (Exception $e)
{
throw new Exception("Erreur lors de l'insertion en base de données : $e->getMessage()");
throw new Exception("Erreur lors de l'insertion en base de données : " . $e->getMessage());
}
}

0 comments on commit fcc8015

Please sign in to comment.