Add an endpoint to set new authorized FROM email address

[MAILPOET-2804]
This commit is contained in:
Jan Jakeš
2020-03-25 12:34:57 +01:00
committed by Veljko V
parent b94dc6c542
commit 3cdd224e14
4 changed files with 128 additions and 4 deletions

View File

@ -75,6 +75,25 @@ class Settings extends APIEndpoint {
}
}
public function setAuthorizedFromAddress($data = []) {
$address = $data['address'] ?? null;
if (!$address) {
return $this->badRequest([
APIError::BAD_REQUEST => WPFunctions::get()->__('No email address specified.', 'mailpoet'),
]);
}
$address = trim($address);
try {
$this->authorizedEmailsController->setFromEmailAddress($address);
} catch (\InvalidArgumentException $e) {
return $this->badRequest([
APIError::UNAUTHORIZED => WPFunctions::get()->__('Cant use this email yet! Please authorize it first.', 'mailpoet'),
]);
}
return $this->successResponse();
}
private function onSettingsChange($oldSettings, $newSettings) {
// Recalculate inactive subscribers
$oldInactivationInterval = $oldSettings['deactivate_subscriber_after_inactive_days'];