"bandal" wrote:
With so many out there that have created the wheel over and over in various ways, I would think more would want to share the tools with friends.
"RokuJoel" wrote:
As to why the Brightscript side isn't included, that is because I created that part for a paying client and I would have to spend hours of my personal time sanitizing it and making it generic in order to share it with you.
"bandal" wrote:
Thanks for the quick response. I have the desire and initiative, but it seems it is taking me longer to learn than I thought. With so many out there that have created the wheel over and over in various ways, I would think more would want to share the tools with friends. I will try your examples to see what I get.
"RokuJoel" wrote:
Here is some very very rough php/mysql code I hacked together last year to create a demo linking app. It is lacking in several areas, for example, it does not associate the device unique id with the linking code, linking is done with a token and the user email address. I'm not checking that the generated code is unique at the time it is generated, I think I'm checking that somewhere though, if not, then the code is hoping that the sheer size of the range of random numbers will avoid a collision. Of course, you need a server with php/mysql and a little bit of know-how.
The following code is mostly the intellectual property of Joel Braverman (c) 2011 and not the property of Roku, inc, and is provided by Joel Braverman without support or warranty for unlimited modification and redistribution throughout the entire universe by all entities and beings, with the sole restriction that it may not be used for evil purposes, for example taking over a galaxy or enslaving furry aliens on the moons of Endor would be a violation of the license:
form used to link device to server, index.html:
<html>
<body>
<form action="savecode.php" method="post">
Please Enter Firstname: <input type="text" name="firstname" /><br>
Please Enter Lastname: <input type="text" name="lastname" /><br>
Please Enter an email address: <input type="text" name="email" /><br>
Please enter a password: <input type="text" name="password" /><br>
Please enter the Code displayed on your Roku Screen: <input type="text" name="code" /><br>
<input type="submit" value="Click to store code"/>
</form>
</body>
</html>
Store the code in a MySQL database, savecode.php:
<?
// Define settings
$dbserver = "mysql"; // Change as required
$dbname = "mydatabase"; // Whatever DB you have access to
$dbuser = "myusername"; // User to connect to DB as
$dbpass = "mypassword";// Password for DB user
// Connect to DB
$dbconn = mysql_connect("mysql","myusername","mypassword");
if (!$dbconn) die("Error connecting to database!");
if (!mysql_select_db($dbname)) die("Error selecting database $dbname");
// Get args
$email = !empty($_REQUEST['email']) ? mysql_real_escape_string($_REQUEST['email']) : "";
$password = !empty($_REQUEST['password']) ? mysql_real_escape_string($_REQUEST['password']) : "";
$code = !empty($_REQUEST['code']) ? mysql_real_escape_string($_REQUEST['code']) : "";
$firstname = !empty($_REQUEST['firstname']) ? mysql_real_escape_string($_REQUEST['firstname']) : "";
$lastname = !empty($_REQUEST['lastname']) ? mysql_real_escape_string($_REQUEST['lastname']) : "";
// Verify args
if (empty($email)) die("Missing or invalid paramater 1");
if (empty($password)) die("Missing or invalid paramater 2");
if (empty($code)) die("Missing or invalid paramater 3");
if (empty($firstname)) die("Missing or invalid paramater 4");
if (empty($lastname)) die("Missing or invalid paramater 5");
// Store data
$sql = "INSERT INTO `mydatabase`.`users` (`firstname`, `lastname`, `email`, `password`, `code`) VALUES ('$firstname','$lastname','$email','$password','$code')";
$result = mysql_query($sql);
if (!$result) die(mysql_errno($link) . ": " . mysql_error($link));
?>
url the Roku uses to check if the user has entered their unique code, checkcode.php
<?
// Define settings
$dbserver = "mysql"; // Change as required
$dbname = "mydatabase"; // Whatever DB you have access to
$dbuser = "myusername"; // User to connect to DB as
$dbpass = "mypassword";// Password for DB user
$code="";
// Connect to DB
$dbconn = mysql_connect("mysql","myusername","mypassword");
if (!$dbconn) die("Error connecting to database!");
if (!mysql_select_db($dbname)) die("Error selecting database $dbname");
// Get args
$code = !empty($_REQUEST['code']) ? mysql_real_escape_string($_REQUEST['code']) : "";
// Verify args
if (empty($code)) die("Missing or invalid Code");
$sql = "SELECT * FROM `users` WHERE code =\"" . $code."\"";
//echo "sql follows";
//echo "<br>";
//echo $sql;
// Get a specific result from the "example" table
$result = mysql_query($sql) or die(mysql_error());
// get the first (and hopefully only) entry from the result
$row = mysql_fetch_array($result);
// Print out the contents of each row into a table
echo $row['code'];
?>
generate a random code for linking: makepin.php
<?php
$random=rand(1679616, 60466175);
print base_convert($random,10,36);
?>
mysql database structure - not sure if the devices table is actually used by the php code:-- phpMyAdmin SQL Dump
-- version 2.11.9.6
-- http://www.phpmyadmin.net
--
-- Host: mysql
-- Generation Time: Jan 29, 2012 at 03:14 AM
-- Server version: 4.1.14
-- PHP Version: 5.2.12
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `mydatabase`
--
-- --------------------------------------------------------
--
-- Table structure for table `udevices`
--
CREATE TABLE IF NOT EXISTS `udevices` (
`email` varchar(100) NOT NULL default '',
`dev1` varchar(10) NOT NULL default '',
`dev2` varchar(10) NOT NULL default '',
`dev3` varchar(10) NOT NULL default '',
`dev4` varchar(10) NOT NULL default '',
`dev5` varchar(10) NOT NULL default '',
PRIMARY KEY (`email`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`firstname` varchar(50) NOT NULL default '',
`lastname` varchar(50) NOT NULL default '',
`email` varchar(100) NOT NULL default '',
`password` varchar(25) NOT NULL default '',
`code` varchar(6) NOT NULL default '',
PRIMARY KEY (`email`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='no comment';
xfer=createobject("roURLtransfer")
xfer.seturl("http://myserver.com/makepin.php")
screen=createobject("roCodeRegistrationScreen")
screen.addfocaltext("please visit http://myserver.com/roku to link your device")
screen.setregistrationcode(xfer.gettostring())
screen.show()
sub main()
screen=createobject("roposterscreen")
screen.show()
if register() =0 then return
screen.setcontentlist(getmyauthorizedcontent())
...
"RokuJoel" wrote:
To get the code from the server, you would do something like:xfer=createobject("roURLtransfer")
xfer.seturl("http://myserver.com/makepin.php")
screen=createobject("roCodeRegistrationScreen")
screen.addfocaltext("please visit http://myserver.com/roku to link your device")
screen.setregistrationcode(xfer.gettostring())
screen.show()
You would use checkcode.php to check if the user had entered the code. If the have then you return from your registration function with a number representing success or failure of registration, so if it returns 0 you exit your channel (because the user canceled registration), if it returns 1 you continue and display the content.
So the opening of your program might look like:
sub main()
screen=createobject("roposterscreen")
screen.show()
if register() =0 then return
screen.setcontentlist(getmyauthorizedcontent())
...
the reason for loading the Posterscreen first is to prevent the channel from exiting after successful registration.