<?php loadlib('user'); # Don't bother if we're signed in (how did they get here anyway?) if (user_id()) { redirect('/'); } # Must POST login information if ('POST' != $_SERVER['REQUEST_METHOD']) { redirect('/start'); } # Try to login if (user_login(@$_POST['username'], @$_POST['password'])) { redirect('/home'); } else { Sd('username', @$_POST['username']); }
<?php Sd('title', 'Signup'); switch (Sd('create')) { case '1': Sd('error', 'Usernames must be between 4 and 40 characters.'); break; case '2': Sd('error', 'Please confirm your password.'); break; case '3': Sd('error', 'Passwords must be between 4 and 40 characters.'); break; case '4': Sd('error', 'Something went wrong here. Are you sure you’re not already registered?'); break; } return Snil(Sf('_signup.html.php'), p('Already have an account? ', a(array('href' => '/start#login'), 'Login')));
<?php loadlib('user'); # Don't bother if we're signed in (how did they get here anyway?) if (user_id()) { redirect('/'); } # Must POST login information if ('POST' != $_SERVER['REQUEST_METHOD']) { redirect('/'); } # Try to create a user if ($create = user_create(@$_POST['username'], @$_POST['email'], @$_POST['phone'], @$_POST['carrier'], @$_POST['password'], @$_POST['password2'])) { Sd('create', $create); Sd('username', @$_POST['username']); Sd('email', @$_POST['email']); } else { redirect('/'); }
<?php return html(div(array('id' => 'everything', 'class' => 'foo'), p('This is a ', strong(Sc('bold', true), 'bold'), span(Sc('bold', false), 'plain'), ' sentence.'), p(Sd('foo')), ul(Sforeach(array('asdf' => 'qwerty', 'foo' => 'bar', 'hooah' => 'woo'), li(Sd('_k'), ': ', Sd('_v'))))));
<?php Sd('title', 'Login'); Sd('error', 'Something went wrong. Are you sure that’s your password?'); return Snil(Sf('_login.html.php'), p('Need to create an account? ', a(array('href' => '/start#signup'), 'Signup')));
<?php # If no one is logged in, just show the login/signup form loadlib('user'); if (user_id()) { Sd('logged_in', true); } else { redirect('/start'); } if ('POST' == $_SERVER['REQUEST_METHOD'] && isset($_POST['code'])) { # Grab the SMS address to generate and compare the code $user = db_query("SELECT sms FROM users WHERE id = '" . user_id() . "' LIMIT 1;"); Sd('confirm', substr(sha1($SALT . $user[0]['sms']), 0, 6) == $_POST['code'] && db_query("UPDATE users SET confirm_sms = '1' WHERE id = '" . user_id() . "' LIMIT 1;")); } else { Sd('confirm', false); }
$key = $keys[0]; $value = $keys[1]; break; } $out = array(); foreach ($arr as $k => $v) { SometimesData::set($key, $k); SometimesData::set($value, $v); $s = clone $sometimes; $s->bind(); $out[] = $s; } SometimesData::delete($key); SometimesData::delete($value); return new Nil($out); } # A test, if run from the command line via `php sometimes.php` if ('cli' == php_sapi_name() && is_array($argv) && preg_match('!/' . basename(__FILE__) . '$!', realpath($argv[0]))) { # For the test, use templates in this directory $GLOBALS['SOMETIMES_TEMPLATEDIR'] = dirname(__FILE__); # Set a variable expected by foo.html.php Sd('foo', 'bar'); # Include and output foo.html.php under both possible conditions $doc = Sf('foo.html.php'); Sout($doc, Sc('bold')); echo "\n\n"; Sout($doc, Sc('bold', false)); echo "\n\n"; # Safely fail to include a non-existent file var_dump(Sf('does-not-exist.html.php')); }
<?php loadlib('user'); # Must have a hash in the URL if (1 != sizeof($URL_PARTS)) { Sd('confirm', false); } else { Sd('confirm', db_query("UPDATE users SET confirm_email = '1' WHERE\n\t\tSHA1(CONCAT('{$SALT}', email)) = '{$URL_PARTS[0]}' LIMIT 1;")); } Sd('logged_in', user_id() ? true : false);
<?php return Snil(form(array('action' => '/report', 'method' => 'post'), Sc('address'), h1(small('Currently: '), Sd('address'), br(), Snil(Sc('sweep', true), small('That street is swept: '), Sd('sweep'), ' ', Sif(Sc('inaccurate', true), '(inaccurate)'), Sif(Sc('inaccurate', false), small(small(input(array('type' => 'submit', 'value' => 'Report as inaccurate', 'class' => 'link')))))), Sif(Sc('sweep', false), Sc('impossible', true), small('This address was impossible to geocode')), Sif(Sc('sweep', false), Sc('impossible', false), small('Street sweeping information will be available shortly ', small(a(array('href' => '/home'), 'Refresh')))))), form(array('action' => Sd('URL'), 'method' => 'post'), p(label(array('for' => 'address'), 'My car is at...'), br(), input(array('id' => 'address', 'name' => 'address', 'type' => 'text', 'value' => Sd('new_address'), 'class' => 'text stretch')), br(), 'Only the closest street number and the street name, please.', br(), small('Don’t choose a corner address because SF GIS might return inaccurate street sweeping data. Make sure you use the proper side of the street so we can accurately predict the street sweeping schedule.')), p(input(array('type' => 'submit', 'value' => 'Update', 'class' => 'button')))), Sif(Sc('need_confirm_sms'), h2('Confirm your cell phone number for SMS'), form(array('action' => '/confirm/sms', 'method' => 'post'), p(label(array('for' => 'code'), 'SMS confirmation code:'), br(), input(array('id' => 'code', 'name' => 'code', 'type' => 'text', 'class' => 'text stretch')), br(), small('Enter the code sent to your cell phone to have reminders sent to your phone.')), p(input(array('type' => 'submit', 'value' => 'Confirm', 'class' => 'button'))))));
<?php return html(head(meta(array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=UTF-8')), meta(array('id' => 'viewport', 'name' => 'viewport', 'content' => 'width=320; initial-scale=1.0; ' . 'maximum-scale=1.0; user-scalable=0;')), title(Sc('title'), Sd('title'), ' — Where’s my car?'), title(Sc('title', false), 'Where’s my car?'), S('link', array(array('type' => 'text/css', 'rel' => 'stylesheet', 'href' => '/css/style.css')))), body(div(array('id' => 'head'), a(array('href' => '/'), 'Where’s my car?')), div(array('id' => 'content'), h1(Sc('title'), Sd('title')), p(array('class' => 'error'), Sc('error'), Sd('error')), p(array('class' => 'status'), Sc('status'), Sd('status')), p(array('class' => 'success'), Sc('success'), Sd('success')), Sl()), div(array('id' => 'foot'), p(Sc('logged_in'), a(array('href' => '/logout'), 'Logout')), p('By ', a(array('href' => 'http://rcrowley.org/'), 'Richard Crowley')))));
<?php Sd('title', '404'); return Snil(p(big('Oh noes!')));
<?php return form(array('action' => '/signup', 'method' => 'post'), p(label(array('for' => 'username'), 'Username:'******'id' => 'username', 'name' => 'username', 'type' => 'text', 'value' => Sd('username'), 'class' => 'text stretch'))), p(label(array('for' => 'email'), 'E-Mail:'), br(), input(array('id' => 'email', 'name' => 'email', 'type' => 'text', 'value' => Sd('email'), 'class' => 'text stretch'))), p(label(array('for' => 'phone'), 'Cell phone number:'), br(), input(array('id' => 'phone', 'name' => 'phone', 'type' => 'text', 'value' => Sd('phone'), 'class' => 'text stretch'))), p(label(array('for' => 'carrier'), 'Cell phone carrier:'), br(), select(array('id' => 'carrier', 'name' => 'carrier'), option(array('value' => '@txt.att.net'), 'AT&T'), option(array('value' => '@messaging.sprintpcs.com'), 'Sprint'), option(array('value' => '@tmomail.net'), 'T-Mobile'), option(array('value' => '@vtext.com'), 'Verizon'))), p(label(array('for' => 'password'), 'Password:'******'id' => 'password', 'name' => 'password', 'type' => 'password', 'class' => 'text stretch'))), p(label(array('for' => 'password2'), 'Confirm password:'******'id' => 'password2', 'name' => 'password2', 'type' => 'password', 'class' => 'text stretch'))), p(input(array('type' => 'submit', 'value' => 'Signup', 'class' => 'button'))));
<?php return form(array('action' => '/login', 'method' => 'post'), p(label(array('for' => 'username'), 'Username:'******'id' => 'username', 'name' => 'username', 'type' => 'text', 'value' => Sd('username'), 'class' => 'text stretch'))), p(label(array('for' => 'password'), 'Password:'******'id' => 'password', 'name' => 'password', 'type' => 'password', 'class' => 'text stretch'))), p(input(array('type' => 'submit', 'value' => 'Login', 'class' => 'button'))));
<?php # Firefox and most phones will cache aggressively without this header("Cache-Control: no-cache, must-revalidate\r\n"); # If no one is logged in, just show the login/signup form loadlib('user'); if (user_id()) { Sd('logged_in', true); } else { redirect('/start'); } # Update the address if requested loadlib('location'); if ('POST' == $_SERVER['REQUEST_METHOD'] && !location_set_address(@$_POST['address'])) { Sd('error', 'Error updating location.'); } $location = location_get(); if (is_array($location)) { Sd('address', $location['address']); if ($location['sweep_ts']) { Sd('sweep', date($DATEFORMAT, $location['sweep_ts'])); } Sd('impossible', (bool) $location['impossible']); Sd('inaccurate', (bool) $location['inaccurate']); } # See if we still need the SMS confirmation form $c = db_query("SELECT confirm_sms FROM users WHERE id = '" . user_id() . "' LIMIT 1;"); Sd('need_confirm_sms', !is_array($c) || !sizeof($c) || !$c[0]['confirm_sms']);
<?php # If no one is logged in, just show the login/signup form loadlib('user'); if (user_id()) { redirect('/home'); } else { Sd('logged_in', false); }
if (preg_match("!^{$pattern}(?:/|\\.(html|xml|json|rss|rdf|atom|php))?(?:\\?.*)?\$!", $_GET['__url__'], $URL_PARTS)) { $URL = array_shift($URL_PARTS); if (false === strpos($URL, '.')) { $FORMAT = 'html'; } else { $FORMAT = array_pop($URL_PARTS); } break; } } if (!isset($URL)) { $FILE = '404.php'; $URL = $_GET['__url__']; $URL_PARTS = array(); $FORMAT = 'html'; } unset($routes); unset($pattern); unset($_GET['__url__']); Sd('FILE', $FILE); Sd('URL', $URL); Sd('URL_PARTS', $URL_PARTS); Sd('FORMAT', $FORMAT); # Dispatch # Beyond the superglobals, these are passed to the called file: # FILE: the name of the file included to handle the request # URL: the complete request URL, minus the query string # URL_PARTS: array of matched sub-patterns in the URL # FORMAT: one (html|xml|json|rss|rdf|php) for determining output format require_once $FILE; Sout(Sl(reset(explode('.', $FILE)) . '.' . $FORMAT . '.php'));
<?php Sd('title', 'Confirm your cell phone number'); return Snil(p(Sc('confirm', true), array('class' => 'success'), 'Thanks!'), p(Sc('confirm', false), array('class' => 'error'), 'The codedidn’t match.'), p(a(array('href' => '/home'), 'Home')));