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
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());
            $u->userdata = array();
            $u->put();
        }
        $_POST['username'] = $_POST['email'];
        User::require_login();
        $form->controller->redirect($form->controller->is_https() ? 'https://' . $customer->domain() . '/' : 'http://' . $customer->domain() . '/');
    }
    @error_log('Error creating profile: ' . $u->error);
    $page->title = __('An Error Occurred');
    echo '<p>' . __('Please try again later.') . '</p>';