71 lines
1.8 KiB
PHP
Executable File
71 lines
1.8 KiB
PHP
Executable File
<?php declare(strict_types=1); namespace IR\App\Webservices; if (!defined('IR_START')) exit('<pre>No direct script access allowed</pre>');
|
|
|
|
use Exception;
|
|
use IR\App\Helpers\Authentication;
|
|
use IR\App\Models\Admin\User;
|
|
use IR\Core\Application;
|
|
use IR\Core\Base;
|
|
|
|
/**
|
|
* @name Subscribers
|
|
* @description Subscribers Controller
|
|
*/
|
|
class Subscribers extends Base {
|
|
/**
|
|
* @app
|
|
* @readwrite
|
|
*/
|
|
public $app;
|
|
|
|
private $authenticatedUser;
|
|
|
|
/**
|
|
* @name init
|
|
* @description initializing process before the action method executed
|
|
* @once
|
|
* @protected
|
|
*/
|
|
public function init() {
|
|
$this->app = Application::getCurrent();
|
|
$this->authenticatedUser = new User([
|
|
'id' => 0,
|
|
'production_id' => 0,
|
|
'master_access' => 'Enabled',
|
|
'status' => 'Activated',
|
|
'first_name' => 'iResponse',
|
|
'last_name' => 'Tracking User',
|
|
'email' => 'tracking@domain.com',
|
|
'is_tracking_user' => true
|
|
]);
|
|
Authentication::registerUser($this->authenticatedUser);
|
|
Authentication::checkUserRoles();
|
|
$this->app->database('clients')->connect();
|
|
}
|
|
|
|
/**
|
|
* @name subscribe
|
|
* @description the subscribe action
|
|
* @before init
|
|
*/
|
|
public function subscribe($parameters = []) {
|
|
$email = $this->app->utils->arrays->get($parameters,'email');
|
|
|
|
$email = htmlspecialchars($email, ENT_QUOTES, 'UTF-8');
|
|
|
|
try {
|
|
|
|
$db = Application::getCurrent()->database("clients");
|
|
$db->execute(
|
|
"insert into specials.subscribers(email) values ('" . $email . "')"
|
|
);
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
echo json_encode(['status' => 'success']);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
|
echo json_encode(['status' => $e->getMessage()]);
|
|
}
|
|
}
|
|
} |