query("SELECT count(*) as val from user")[0]["val"]; if ($intUserCount < 1) { BootstrapRender::message( "Please create an administrator account.", "warning"); } if (Request::posts("email", "password", "repeat")) { $strEmail = Request::getPosted("email"); $strPassword = Request::getPosted("password"); $strRepeat = Request::getPosted("repeat"); if (!preg_match("/^[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+$/", $strEmail)) throw new Exception("Not a valid e-mail address"); if (Request::getPosted("password") !== Request::getPosted("repeat")) throw new Exception("Passwords do not match"); if (strlen($strPassword) < 6) throw new Exception("Password must be at least 6 characters"); $c->query( "CREATE table if not exists user ( id integer primary key autoincrement, email text not null unique, hash text not null)"); $varUsers = $c->query("SELECT * from user where email like ?", $strEmail); if (count($varUsers) > 0) throw new Exception("E-mail address in use"); $strHash = sha1($strPassword); $c->query( "INSERT into user (email, hash) values (?, ?)", $strEmail, $strHash); $intUserCount = $c->query("SELECT count(*) as val from user")[0]["val"]; if ($intUserCount == 1) { // Calling this ensures permission table: UserAuth::hasPermission("dummy"); $c->query( "INSERT into permission (email, name) values (?, 'admin')", $strEmail); } BootstrapRender::message("Registration was a success, please sign in to continue."); Respond::redirect("/user/signin"); } } catch (Exception $x) { BootstrapRender::message($x->getMessage(), "danger"); } ?>