query("SELECT count(*) as val from user")[0]["val"]; if ($intUserCount < 1) Respond::redirect("/user/register"); if (Request::posts("email", "password")) { $strEmail = Request::getPosted("email"); $strPassword = Request::getPosted("password"); $strHash = sha1($strPassword); $varUsers = $c->query( "SELECT * from user where email like ? and hash = ?", $strEmail, $strHash); if (count($varUsers) !== 1) throw new Exception("Zero or more than one user returned for credentials provided"); $strToken = sha1(microtime()); $c->query("CREATE table if not exists tokens ( id integer primary key autoincrement, email text not null, token text not null, expires timestamp null)"); $c->query( "INSERT into tokens (email, token) values (?, ?)", $strEmail, $strToken); Cookie::set("token", $strToken); BootstrapRender::message( "Successfully signed in", "info"); Respond::redirect("/user/info"); } } catch (Exception $x) { BootstrapRender::message($x->getMessage(), "danger"); } ?>