예제 #1
0
function invite_codes_create($email, $more = array())
{
    if ($invite = invite_codes_get_by_email($email)) {
        return array('ok' => 1, 'invite' => $invite);
    }
    $code = null;
    $tries = 0;
    while (!$code) {
        $code = random_string(12);
        $tries += 1;
        if (invite_codes_get_by_code($code)) {
            $code = null;
        }
        if ($tries == 50) {
            break;
        }
    }
    if (!$code) {
        return array('ok' => 0, 'error' => 'Failed to generate code');
    }
    $invite = array('email' => $email, 'code' => $code, 'created' => time());
    if (isset($more['invited_by'])) {
        $invite['invited_by'] = intval($more['invited_by']);
    }
    $hash = array();
    foreach ($invite as $k => $v) {
        $hash[$k] = AddSlashes($v);
    }
    $rsp = db_insert('InviteCodes', $hash);
    if ($rsp['ok']) {
        $rsp['invite'] = $invite;
    }
    return $rsp;
}
예제 #2
0
    error_404();
}
loadlib("invite_codes");
loadlib("rfc822");
$crumb_key = 'god_generate_invite';
$GLOBALS['smarty']->assign("crumb_key", $crumb_key);
$crumb_ok = crumb_check($crumb_key);
if ($crumb_ok) {
    $email = post_str("email");
    $code = post_str("code");
    if ($code) {
        $ensure_sent = 0;
        if ($invite = invite_codes_get_by_code($code, $ensure_sent)) {
            $template = 'email_invite_user.txt';
            invite_codes_send_invite($invite, $template);
            $invite = invite_codes_get_by_code($code, $ensure_sent);
            $GLOBALS['smarty']->assign_by_ref("invite", $invite);
            $GLOBALS['smarty']->assign("invite_sent", 1);
        } else {
            $GLOBALS['error'] = "Invalid invite code";
        }
    } else {
        if (!$email) {
            $GLOBALS['error'] = "Missing email";
        } else {
            if (!rfc822_is_valid_email_address($email)) {
                $GLOBALS['error'] = "Invalid email ({$email})";
            } else {
                if ($invite = invite_codes_get_by_email($email)) {
                    $GLOBALS['smarty']->assign_by_ref("invite", $invite);
                } else {
예제 #3
0
    } else {
        $GLOBALS['error']['invalid_code'] = 1;
    }
}
# User is trying to request an invite code?
$crumb_key = 'invite';
$GLOBALS['smarty']->assign("crumb_key", $crumb_key);
$crumb_ok = crumb_check($crumb_key);
if ($crumb_ok) {
    $code = post_str("code");
    $email = post_str("email");
    # just in case the jquery doesn't work or something...
    $code = $code == "3x4mpl3c0d3" ? null : $code;
    $email = $email == "*****@*****.**" ? null : $email;
    if ($code) {
        if ($invite = invite_codes_get_by_code($code)) {
            invite_codes_signin($invite, $redir);
            exit;
        } else {
            $GLOBALS['error']['invalid_code'] = 1;
        }
    } else {
        if ($email) {
            $email = post_str("email");
            if (!rfc822_is_valid_email_address($email)) {
                $GLOBALS['error']['invalid_email'] = 1;
            } else {
                $rsp = invite_codes_create($email);
                if ($rsp['ok']) {
                    $invite = $rsp['invite'];
                    if ($invite['sent']) {
예제 #4
0
    error_404();
}
$crumb_key = 'god_invite';
$GLOBALS['smarty']->assign("crumb_key", $crumb_key);
$crumb_ok = crumb_check($crumb_key);
if ($crumb_ok && post_str("delete")) {
    $rsp = invite_codes_delete($invite);
    if ($rsp['ok']) {
        header("location: /god/invites.php");
        exit;
    }
    $GLOBALS['error']['delete_failed'] = 1;
    $GLOBALS['error']['details'] = $rsp['error'];
} else {
    if ($crumb_ok && post_str("send")) {
        $more = array('send_email' => 1, 'invited_by' => $GLOBALS['cfg']['user']['id']);
        $rsp = invite_codes_invite_user($invite['email'], $more);
        if ($rsp['ok']) {
            $GLOBALS['smarty']->assign_by_ref("invite", $rsp['invite']);
            # refresh so we get an updated 'sent' date
            $invite = invite_codes_get_by_code($invite['code'], 0);
        } else {
            $GLOBALS['error'] = $rsp['error'];
        }
        $GLOBALS['smarty']->assign_by_ref("sent", $rsp);
    } else {
    }
}
$GLOBALS['smarty']->assign_by_ref("invite", $invite);
$GLOBALS['smarty']->display("page_god_invite.txt");
exit;