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: 
tboneus
Visitor

Any pointers for registration code in asp or java

Hi guys, I was looking at the registration example in the samples folder of the SDK and have been trying to implement the server code to complete the transaction. Essentially, looking at the docks there appears to be a SOAP xml style transmission when the user clicks to register, then the server parses the xml which would be checked against a database resulting in another xml packer being sent back to the box.

Has anyone tried to implement the server side of the code? I know there were no examples in the SDK but does anyone know of some suitable code in ASP.net or java that could be used for this at least so I could get some kind of two way communication going between the Roku and the server. It is described in the SDK as "rendezvous style registration" but I have been unsuccessful in finding out any more information.

To give a little background, my reason for this is so that I could possibly carry a database and business logic on the server and therefore use the Roku essentially as an interface but leave all the grunt work to a dedicated server. I have a lot of code that accesses a personal database and provides a lot of multimedia functionality in a windows based app but it would be ideal to utilize a server and the roku, thus eliminating the need for a computer to be on all the time.

Any thoughts gratefully received.
0 Kudos
23 REPLIES 23
YungBlood
Streaming Star

Re: Any pointers for registration code in asp or java

First, I can't say anything about java or asp... I don't like java, and I know nothing about asp. Since you are asking about those languages, I assume you know them. I can tell you the theory behind one of my projects that use a registration code.

I have a database with 2 tables dealing with the reg code. One table is my user table. The other is a temp table. In the roku settings config, I call a script on my server. The script generates random codes until it finds one that is not in either table. The script then places the code in my temp table, along with an expiration time. The script also sends the code back to roku. Roku displays the code to the user, and tells them to enter the code into their profile on the web site. Roku keeps checking the site to see if that code has been entered. Once the user enters it, roku will recognize it, and welcome the user.

When the user enters a code into their profile, the server checks the temp database. If the code is in there, it takes it out, and places the code into the users record. If the code is not in the temp database, it gets rejected. The server scripts also clean out any temp codes that are older than their expiration time. If roku finds that the code has expired, it tells the user it can get a new code.

All my server scripts return simple text, no xml. On roku, I use roUrlTransfer GetToString(). For simplicity, I pass all the values through the address like this: http.seturl("http://www.someserver.com/roku/testreg.cgi?reg=" + code + "&key=" + pass) Then when I call http.gettostring() I get back "true" or "false". So it's easy for roku to handle, and there's no extra code on the server.

Obviously, you need to make sure that the scripts roku calls are secure if you are doing this across the internet. That can be dealt with by ssl or other handshake methods.

Although I can't release my code, I can write out the basics in pseudo code if it would help.
YungBlood

Bringing more fun to Roku!
0 Kudos
tboneus
Visitor

Re: Any pointers for registration code in asp or java

Thanks for the reply. Good point about simplifying the problem initially by using text rather than xml. I will take your suggestion using roUrlTransfer GetToString() and give it another go using after the holidays. Cgi is not my area of expertise so I will need to come up with something possibly is javascript to carry out a similar function.

Thankyou
0 Kudos
dynamitemedia
Binge Watcher

Re: Any pointers for registration code in asp or java

I used Php to do it all are you familiar with PHP?


I use PHP for everything, its simple and you can always find help with it if you get stuck.
Twitter: iptvmyway facebook: iptvmyay
Channels: Warriors of War, Go Fight Live, Heading Outdoorz, IPTVmyway
0 Kudos
tboneus
Visitor

Re: Any pointers for registration code in asp or java

Yes, I have done some work with PHP so I would certainly be able to utilize a code example if you have one.
0 Kudos
ncase
Visitor

Re: Any pointers for registration code in asp or java

I'd love to see some example PHP code for the Roku device to site membership "rendezvous" device linking. The Roku documentation seems pretty limited on this topic.
0 Kudos
RokuKevin
Visitor

Re: Any pointers for registration code in asp or java

Did you look at the register example app in the SDK? It' a rendezvous linking implementation and does show typical requests and responses you app would make with your server.

The example uses static XML files on the server, but in your server implementation you would create similar dynamic XML as the responses. You would use whatever language you wanted to do this (PHP, Java, C#...) and the code would be custom to every developer as you would need to integrate with your authorization scheme and connect to tables in your schema.

The other sources of info in the docs are the DeviceRegistrationAndLinking guide and the roCodeRegistrationScreen documentation in section 4.12 of the Component Reference.

--Kevin
0 Kudos
Biju
Visitor

Re: Any pointers for registration code in asp or java

"dynamitemedia" wrote:
I used Php to do it all are you familiar with PHP?


I use PHP for everything, its simple and you can always find help with it if you get stuck.


Do you have the sample php code for linking to roku
0 Kudos
RokuJoel
Binge Watcher

Re: Any pointers for registration code in asp or java

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';
0 Kudos
bandal
Visitor

Re: Any pointers for registration code in asp or java

Thanks Joel,

It's a start, but why not give us all a complete solution for registration from the Roku to the Webservices side with device checks and sql checks and so forth?

Then all of us on the forum that want to get our channels up faster can do it.

Is it that no one wants to share the knowledge or wants to keep all to themselves? Whatever code is used we can work around it to make sure it works.

This is the last part of my design and for 3 months now can't get it going between my Roku and Website as I am not a great programmer. I think I speak for many here. We are the enslaved aliens right now who can't escape.
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.