Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
RokuJoel
Binge Watcher

Re: Any pointers for registration code in asp or java

In order for someone to give you a complete solution, they would have to create one first, right? Most people are not going to go through all that work for free.

Would your auto mechanic give you his tools so that you can set up shop next door and compete?

I've given you everything that I created, for free, which took me several weeks (mostly without sleep) of research and study to come up with in the first place, on my own initiative and desire to learn. It can be modified by anyone who has a little bit of initiative and desire to learn, to do whatever they want with it. I'm giving it to you, because I'm mostly out of the indie software development business now.

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.

- Joel
0 Kudos
bandal
Visitor

Re: Any pointers for registration code in asp or java

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.
0 Kudos
kc8pql
Visitor

Re: Any pointers for registration code in asp or java

"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.

Sharing tools with friends, and giving away the tools that your livelihood depends on to the competition are two different things. Just saying... 🙂
____________________________________________________________________________________________________________
No, I don't work for Roku.
Netflix Player N1000X, XDS 2100X (premature death by lightning)
Roku2 XD 3050X, Roku2 XS 3100R, Roku2 4210R
0 Kudos
RokuChris
Roku Employee
Roku Employee

Re: Any pointers for registration code in asp or java

"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.


One possible BrightScript side is presented in this blog post (http://blog.roku.com/developer/2011/07/ ... e-account/). That's not to say that that code will work with Joel's backend as is. In fact, it probably won't. And that illustrates another point. No two cloud services are the same. Each content provider does it a little differently and has to customize their channel to work with their particular system. The concepts are similar in most cases, but the details of each implementation are left up to the developer since the number of possible variations is pretty much limitless.
0 Kudos
RokuJoel
Binge Watcher

Re: Any pointers for registration code in asp or java

"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.


I highly recommend StackOverflow and the StackExchange web network as an incredible tool for self education, and for solving problems (albeit in a rather piecemeal way) as you encounter them.

On the Brightscript side try to think out the various steps:

- > get a unique code from the server
- > check every 30 seconds or so if a user has entered that code
- > if the user has entered that code, then store the code in the Roku's permanent memory, and allow the user to proceed to view your content.


On the server side, you will want to associate the code with both the users account information, and the device's unique serial number. You will use the unique code as a "login" key for the device in the future, and the serial number will help to identify the device/user so that if the device is sold to another person, when they link that same device, you will know that you need to move the associated serial number out of the first user's record, to another user's record. You will look for that unique code (not the device's unique ID) in all http requests to your server for content, and reject any requests that don't have a code in your database.

Hope that helps a bit.

- Joel
0 Kudos
bandal
Visitor

Re: Any pointers for registration code in asp or java

Thanks for the updates.
0 Kudos
Biju
Visitor

Re: Any pointers for registration code in asp or java

Thank you for you response but still i didnot understand how to link the data base and roku devices?

how to get unique code and store the code in the Roku's permanent memory?
0 Kudos
Biju
Visitor

Re: Any pointers for registration code in asp or java

"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';


thanks for your reply but my private channel doesnot shows any code in roku screen so from where did i get these code. how this php code link with the roku devices and how can i give permission to veiw the content of my private channel
0 Kudos
RokuJoel
Binge Watcher

Re: Any pointers for registration code in asp or java

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.
0 Kudos
Biju
Visitor

Re: Any pointers for registration code in asp or java

"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.


thanks a lot for your quick response. In which file do i have to put these codes, currently im using sample videoplyer sdk.
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.