Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
api(sendPic): handle "Store email addresses in file" option earlier
Browse files Browse the repository at this point in the history
Change-Id: Ief9ae3fb9fdd176099d74a888aac26dd0e4738b9
  • Loading branch information
andi34 committed Jul 6, 2022
1 parent 2732e7b commit 11a297f
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions api/sendPic.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
require_once '../lib/db.php';
require_once '../lib/log.php';

if (empty($_POST['sendTo']) || empty($_POST['image']) || !PHPMailer::validateAddress($_POST['sendTo'])) {
if (empty($_POST['sendTo']) || !PHPMailer::validateAddress($_POST['sendTo'])) {
$LogData = [
'success' => false,
'error' => 'E-Mail address invalid',
Expand All @@ -24,6 +24,40 @@
die($LogString);
}

if (isset($_POST['send-link']) && $_POST['send-link'] === 'yes') {
if (!file_exists(MAIL_FILE)) {
$addresses = [];
} else {
$addresses = json_decode(file_get_contents(MAIL_FILE));
}

if (!in_array($_POST['sendTo'], $addresses)) {
$addresses[] = $_POST['sendTo'];
}

file_put_contents(MAIL_FILE, json_encode($addresses));

die(
json_encode([
'success' => true,
'saved' => true,
])
);
}

if (empty($_POST['image'])) {
$LogData = [
'success' => false,
'error' => 'Image not defined',
'php' => basename($_SERVER['PHP_SELF']),
];
$LogString = json_encode($LogData);
if ($config['dev']['enabled']) {
logError($LogData);
}
die($LogString);
}

$postImage = basename($_POST['image']);
if (!isImageInDB($postImage)) {
$LogData = [
Expand Down Expand Up @@ -96,27 +130,6 @@
die($LogString);
}

if (isset($_POST['send-link']) && $_POST['send-link'] === 'yes') {
if (!file_exists(MAIL_FILE)) {
$addresses = [];
} else {
$addresses = json_decode(file_get_contents(MAIL_FILE));
}

if (!in_array($_POST['sendTo'], $addresses)) {
$addresses[] = $_POST['sendTo'];
}

file_put_contents(MAIL_FILE, json_encode($addresses));

die(
json_encode([
'success' => true,
'saved' => true,
])
);
}

if ($mail->send()) {
die(
json_encode([
Expand Down

0 comments on commit 11a297f

Please sign in to comment.