Your Digital Media Has Never Looked So Good

 
tboneus
Topic Author
Posts: 11
Joined: Wed Nov 17, 2010 3:06 pm

Any pointers for registration code in asp or java

Tue Nov 23, 2010 7:47 pm

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.
 
YungBlood
Posts: 133
Joined: Wed Jul 07, 2010 10:05 pm
Location: California
Contact:

Re: Any pointers for registration code in asp or java

Tue Nov 23, 2010 11:59 pm

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!
 
tboneus
Topic Author
Posts: 11
Joined: Wed Nov 17, 2010 3:06 pm

Re: Any pointers for registration code in asp or java

Thu Nov 25, 2010 7:38 am

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
 
dynamitemedia
Posts: 577
Joined: Wed Feb 03, 2010 7:49 am

Re: Any pointers for registration code in asp or java

Fri Nov 26, 2010 12:44 pm

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
 
tboneus
Topic Author
Posts: 11
Joined: Wed Nov 17, 2010 3:06 pm

Re: Any pointers for registration code in asp or java

Sat Nov 27, 2010 8:50 am

Yes, I have done some work with PHP so I would certainly be able to utilize a code example if you have one.
 
ncase
Posts: 2
Joined: Mon Dec 20, 2010 4:33 pm

Re: Any pointers for registration code in asp or java

Tue Dec 21, 2010 12:53 pm

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.
 
User avatar
RokuKevin
Roku Engineering
Posts: 796
Joined: Tue Sep 22, 2009 2:29 pm

Re: Any pointers for registration code in asp or java

Wed Dec 22, 2010 9:56 am

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
 
Biju
Posts: 28
Joined: Sun Jan 15, 2012 10:07 pm

Re: Any pointers for registration code in asp or java

Sat Jan 28, 2012 11:52 pm

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
 
User avatar
RokuJoel
Posts: 1758
Joined: Mon Nov 14, 2011 5:22 pm

Re: Any pointers for registration code in asp or java

Sun Jan 29, 2012 4:41 am

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';
 
bandal
Posts: 260
Joined: Sat Oct 15, 2011 2:17 pm

Re: Any pointers for registration code in asp or java

Sun Jan 29, 2012 3:47 pm

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.
 
User avatar
RokuJoel
Posts: 1758
Joined: Mon Nov 14, 2011 5:22 pm

Re: Any pointers for registration code in asp or java

Sun Jan 29, 2012 4:11 pm

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
 
bandal
Posts: 260
Joined: Sat Oct 15, 2011 2:17 pm

Re: Any pointers for registration code in asp or java

Sun Jan 29, 2012 4:21 pm

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.
 
User avatar
kc8pql
** Valued Community Member **
Posts: 9026
Joined: Fri Jan 23, 2009 3:54 pm
Location: US

Re: Any pointers for registration code in asp or java

Sun Jan 29, 2012 5:34 pm

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
 
User avatar
RokuChris
Posts: 1166
Joined: Mon Aug 30, 2010 1:45 pm

Re: Any pointers for registration code in asp or java

Sun Jan 29, 2012 7:03 pm

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.
 
User avatar
RokuJoel
Posts: 1758
Joined: Mon Nov 14, 2011 5:22 pm

Re: Any pointers for registration code in asp or java

Sun Jan 29, 2012 7:27 pm

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

Who is online

Users browsing this forum: No registered users and 4 guests