Example #1
0
if (isset($_GET['redirect'])) {
    $_POST['redirect'] = $_GET['redirect'];
}
if (!isset($_POST['redirect'])) {
    $_POST['redirect'] = $_SERVER['REQUEST_URI'];
    if ($_POST['redirect'] == '/user/login') {
        $_POST['redirect'] = '/user';
    }
}
if (!Validator::validate($_POST['redirect'], 'header')) {
    $_POST['redirect'] = '/user';
}
if (!User::require_login()) {
    if (!$this->internal && !empty($_POST['username'])) {
        echo '<p>' . __('Incorrect email or password, please try again.') . '</p>';
    }
    $_POST['signup_handler'] = false;
    echo $tpl->render('user/login', $_POST);
} else {
    $customer = saasy\App::customer();
    if (!$customer) {
        $acct = saasy\Account::query()->where('user', User::val('id'))->single();
        if ($acct && !$acct->error) {
            $customer = new saasy\Customer($acct->customer);
            if (!$customer->error) {
                $this->redirect('//' . $customer->domain() . '/');
            }
        }
    }
    $this->redirect($_POST['redirect']);
}
Example #2
0
<?php

/**
 * Loads the REST API for the member accounts.
 */
// Authorize user
if (!saasy\App::authorize($page, $tpl)) {
    return;
}
$this->restful(new saasy\API());
Example #3
0
<?php

/**
 * Custom user sign up form that also creates an initial
 * customer and owner account.
 */
$conf = saasy\App::conf();
$www = $conf['App Settings']['include_www'] ? "www." : "";
// Sign up at base domain
$customer = saasy\App::customer();
if ($customer) {
    $this->redirect($this->is_https() ? 'https://' . $www . saasy\App::base_domain() . '/user/signup' : 'http://' . $www . saasy\App::base_domain() . '/user/signup');
}
$form = new Form('post', $this);
$page->title = __('Sign Up');
echo $form->handle(function ($form) use($page, $tpl) {
    $date = gmdate('Y-m-d H:i:s');
    $verifier = md5(uniqid(mt_rand(), 1));
    $u = new User(array('name' => $_POST['name'], 'email' => $_POST['email'], 'password' => User::encrypt_pass($_POST['password']), 'expires' => $date, 'type' => 'member', 'signed_up' => $date, 'updated' => $date, 'userdata' => json_encode(array('verifier' => $verifier))));
    $u->put();
    Versions::add($u);
    if (!$u->error) {
        // Create customer and account
        $customer = new saasy\Customer(array('name' => $_POST['customer_name'], 'subdomain' => $_POST['subdomain'], 'level' => 1));
        $customer->put();
        $acct = new saasy\Account(array('user' => $u->id, 'customer' => $customer->id, 'type' => 'owner', 'enabled' => 1));
        $acct->put();
        try {
            Mailer::send(array('to' => array($_POST['email'], $_POST['name']), 'subject' => __('Please confirm your email address'), 'text' => $tpl->render('saasy/email/verification', array('verifier' => $verifier, 'email' => $_POST['email'], 'name' => $_POST['name'], 'domain' => $customer->domain()))));
        } catch (Exception $e) {
            @error_log('Email failed (saasy/signup): ' . $e->getMessage());
Example #4
0
<?php

/**
 * This is a sample Elefant bootstrap file that includes
 * the SAASy initializations. Copy the lines below into
 * a file named bootstrap.php in the root of your
 * Elefant installation.
 */
// Pre-initialize the cache
$cache = Cache::init(conf('Cache'));
// Initialize the app
saasy\App::bootstrap($controller);