Exemple #1
0
function call($command, $user)
{
    \app\log('calling func');
    if (!empty($user)) {
        $command_type = 'receiver';
    } else {
        $command_type = 'sender';
    }
    $path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'commands';
    $tpl_path = $path . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $command_type;
    $file = $path . DIRECTORY_SEPARATOR . $command_type . DIRECTORY_SEPARATOR . $command . '.php';
    $template = $tpl_path . DIRECTORY_SEPARATOR . $command . '.phtml';
    \app\log($file);
    if (!file_exists($file)) {
        \app\log('Command ' . $command . ' not implemented for ' . $command_type);
        exit('Command ' . $command . ' not implemented for ' . $command_type);
    }
    include $file;
    \app\log($file);
    $function = "\\command\\" . $command;
    $result = $function();
    \app\log($result);
    if (!empty($result)) {
        \app\log('sending');
        \app\run('email', 'send', array($result, $template));
    } else {
        \app\log('nothing to send');
        exit('nothing to send');
    }
}
Exemple #2
0
function send($result, $template, $subject = 'sibip')
{
    \app\log('sending prep');
    $config = \configuration\load();
    $mailgun = new \Mailgun\Mailgun($config['key']);
    $domain = $config['domain'];
    \app\log('composed');
    $mailgun->sendMessage($domain, array('from' => '*****@*****.**', 'to' => \app\run('input', 'post', 'sender'), 'subject' => $subject, 'text' => \email\composeText($result), 'html' => \email\composeHTML($template, $result)));
}
Exemple #3
0
function store()
{
    $email = R::dispense('email');
    foreach (\app\run('input', 'keys', 'post') as $key) {
        $element = str_replace('-', '_', $key);
        $email->{$element} = \app\run('input', 'post', $key);
    }
    R::store($email);
    return null;
}
Exemple #4
0
function status()
{
    $sender = \app\run('input', 'post', 'sender');
    $recipient = \app\run('input', 'post', 'recipient');
    $emails = R::find('email', ' sender = ? or recipient = ? ', [$sender, $recipient]);
    $result = '<dl>';
    foreach ($emails as $email) {
        $result .= '<dt>' . $email->subject . '</dt>';
        $result .= '<dd>' . $email->body_plain . '</dd>';
    }
    $result .= '</dl>';
    return $result;
}
Exemple #5
0
function index_page()
{
    $path = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'templates';
    $tpl_path = $path . DIRECTORY_SEPARATOR . 'email' . DIRECTORY_SEPARATOR;
    $config = \configuration\load();
    $registration = \app\run('input', 'post', 'email');
    if ($registration) {
        $string = \app\run('input', 'generateRandomString', 10);
        $subject = '#' . $string . '#';
        $result = ['code' => '#' . $string . '#'];
        $template = $tpl_path . 'register.phtml';
        \app\run('email', 'send', [$result, $template, $subject]);
    }
    return array('today' => date("Y-m-d"));
}
Exemple #6
0
function verify_signature()
{
    $config = \app\run('configuration', 'load');
    $timestamp = \app\run('input', 'post', 'timestamp');
    $token = \app\run('input', 'post', 'token');
    $signature = \app\run('input', 'post', 'signature');
    if (empty($timestamp) || empty($token) || empty($signature)) {
        \app\log('incomplete');
        exit('incomplete');
    }
    $data = $timestamp . $token;
    $code = hash_hmac('sha256', $data, $config['key']);
    if ($code == $signature) {
        return true;
    }
    \app\log('nope');
    exit('nope');
}
Exemple #7
0
<?php

require '../vendor/autoload.php';
require '../app/app.php';
\app\run();
Exemple #8
-2
function check($data)
{
    $recipient = \app\run('input', 'post', 'recipient');
    $user = R::findOne('user', ' email = ?', [$recipient]);
    if (empty($user)) {
        return false;
    }
    return $user;
}