Index: Dev/branches/rest-dojo-ui/client/index.html
===================================================================
--- Dev/branches/rest-dojo-ui/client/index.html	(revision 259)
+++ Dev/branches/rest-dojo-ui/client/index.html	(revision 260)
@@ -8,24 +8,6 @@
         <link type="text/css" href="dojox/grid/resources/claroGrid.css" rel="stylesheet" />
         <link type="text/css" href="rft/css/main.css" rel="stylesheet" />
-        <script data-dojo-config="async: true, parseOnLoad: false, tlmSiblingOfDojo: false, isDebug: true, baseUrl: '', packages: ['dojo','dijit', 'dojox', 'rft']" src="dojo/dojo.js"></script>
-        <script>
-            require([ 'dojo/parser', 'rft/ui/LoginDialog', 'dojo/dom', 'dojo/_base/connect', 'dojo/cookie', 'rft/content', 'dojo/domReady!', 'dijit/layout/ContentPane', 'dijit/MenuBar', 'dijit/MenuBarItem', 'rft/ui/MenuBarLink', 'rft/ui/Page' ], 
-            function(parser,LoginDialog,dom,connect,cookie,content) {
-                parser.parse();
-                
-                var session_cookie = cookie('rft_uid');
-                if ( !session_cookie ) {
-                    var login = new LoginDialog().placeAt(document.body);
-                    login.startup();
-                    login.show();
-                } else {
-                    content.initial();
-                }
-                
-                connect.connect(dom.byId('userinfo'),'click',function(){
-                    login.show();
-                });
-            });
-        </script>
+        <script type="text/javascript" src="dojo/dojo.js" data-dojo-config="async: true, parseOnLoad: false, tlmSiblingOfDojo: false, isDebug: true, baseUrl: '', packages: ['dojo','dijit', 'dojox', 'rft']"></script>
+        <script type="text/javascript" src="rft/run.js"></script>
     </head>
     <body class="claro">
Index: Dev/branches/rest-dojo-ui/client/pages/session.html
===================================================================
--- Dev/branches/rest-dojo-ui/client/pages/session.html	(revision 259)
+++ Dev/branches/rest-dojo-ui/client/pages/session.html	(revision 260)
@@ -1,4 +1,5 @@
 <div data-dojo-type="rft.ui.Page">
-    <script type="dojo/method" data-dojo-event="init" data-dojo-args="args">
+    <script type="dojo/method" data-dojo-event="init">
+        var that = this;
         require(['dojo/_base/json','dojo/dom','dojo/store/JsonRest','dojo/domReady!'],
             function(json,dom,JsonRest){
@@ -7,13 +8,13 @@
                     idProperty: 'uid'
                 });
-                store.get(args.uid).then(function(obj){
-                    dom.byId('page_session_form').innerHTML = json.toJson(obj);
+                store.get(that.args.uid).then(function(obj){
+                    that.page_session_form.innerHTML = json.toJson(obj);
                 });
             });
     </script>
-    <div class="largeFrame" id="page_session" style="width: 400px;">
+    <div class="largeFrame" style="width: 400px;">
         <div class="largeTitle">Session</div>
         <div class="content">
-            <div id="page_session_form"></div>
+            <div data-rft-attach-point="page_session_form"></div>
         </div>
     </div>
Index: Dev/branches/rest-dojo-ui/client/pages/sessions.html
===================================================================
--- Dev/branches/rest-dojo-ui/client/pages/sessions.html	(revision 259)
+++ Dev/branches/rest-dojo-ui/client/pages/sessions.html	(revision 260)
@@ -1,4 +1,5 @@
 <div data-dojo-type="rft.ui.Page">
-    <script type="dojo/method" data-dojo-event="init" data-dojo-args="args">
+    <script type="dojo/method" data-dojo-event="init">
+        var that = this;
         require(['dojo/store/JsonRest','dojox/grid/DataGrid',
             Â Â Â Â 'dojo/data/ObjectStore','dojo/domReady!'],
@@ -8,20 +9,19 @@
                 idProperty: 'uid'
             });
-            Â Â Â Â var grid = new DataGrid({
-                Â Â Â Â Â Â Â Â store: ObjectStore({objectStore: store}),
+        Â Â Â Â var grid = new DataGrid({
+        Â Â Â Â Â Â Â Â store: ObjectStore({objectStore: store}),
                 autoWidth: true,
                 autoHeight: true,
-                Â Â Â Â Â Â Â Â structure: [
-                    Â Â Â Â Â Â Â Â Â Â Â Â {name:"Title", field:"title", width: "200px"},
-                    Â Â Â Â Â Â Â Â Â Â Â Â {name:"Id", field:"uid", width: "200px"}
-                Â Â Â Â Â Â Â Â ]
-            Â Â Â Â }, "page_sessions_grid");
-            Â Â Â Â grid.startup();
+        Â Â Â Â Â Â Â Â structure: [
+            Â Â Â Â Â Â Â Â Â Â Â Â {name:"Title", field:"title", width: "200px"}
+        Â Â Â Â Â Â Â Â ]
+        Â Â Â Â }, that.page_sessions_grid);
+        Â Â Â Â grid.startup();
         });
     </script>
-    <div class="largeFrame" id="page_sessions" style="width: 400px;">
+    <div class="largeFrame" style="width: 400px;">
         <div class="largeTitle">Sessions</div>
         <div class="content">
-            <div id="page_sessions_grid"></div>
+            <div data-rft-attach-point="page_sessions_grid"></div>
         </div>
     </div>
Index: Dev/branches/rest-dojo-ui/client/rft/auth.js
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/auth.js	(revision 259)
+++ Dev/branches/rest-dojo-ui/client/rft/auth.js	(revision 260)
@@ -1,42 +1,67 @@
-define(['dojo/_base/Deferred','./api'],function(Deferred,api){
-    return new (function() {
-        var self = this;
-        var currentUser = null;
+define(['dojo/_base/Deferred','dojo/_base/xhr','dojo/_base/json'],
+    function(Deferred,xhr,json){
+        return new (function() {
+            var self = this;
+            var currentUser = null;
 
-        self.login = function(username,password) {
-            var d = new Deferred();
-            api.post("login",
-            {
-                username:username,
-                password:password
-            })
-            .then(function(data) {
-                currentUser = data;
-                d.resolve(data);
-            },function(){
-                d.reject(); 
-            });
-            return d.promise;
-        };
+            function post(path,args) {
+                return xhr.post({
+                    url: "../server/api.php"+path,
+                    handleAs: "json",
+                    headers: {
+                        "Content-Type": "application/json"
+                    },
+                    rawBody: json.toJson(args)
+                });
+            }
+
+            self.login = function(username,password) {
+                var d = new Deferred();
+                post("/login",
+                {
+                    username:username,
+                    password:password
+                })
+                .then(function(data) {
+                    currentUser = data;
+                    d.resolve(data);
+                },function(){
+                    d.reject(); 
+                });
+                return d.promise;
+            };
+
+            self.restore = function() {
+                var d = new Deferred();
+                post("/login",{})
+                .then(function(data) {
+                    currentUser = data;
+                    d.resolve(data);
+                },function(){
+                    d.reject(); 
+                });
+                return d.promise;
             
-        self.register = function(username,password) {
-            var d = new Deferred();
-            api.post("register",
-            {
-                username:username,
-                password:password
-            })
-            .then(function(data) {
-                currentUser = data;
-                d.resolve(data);
-            },function(){
-                d.reject(); 
-            });
-            return d.promise;
-        };
+            };
+
+            self.register = function(username,password) {
+                var d = new Deferred();
+                post("/register",
+                {
+                    username:username,
+                    password:password
+                })
+                .then(function(data) {
+                    currentUser = data;
+                    d.resolve(data);
+                },function(){
+                    d.reject(); 
+                });
+                return d.promise;
+            };
             
-        self.getUser = function(){
-            return currentUser;
-        };
-    })();
-});
+            self.getUser = function(){
+                return currentUser;
+            };
+        })();
+    });
Index: Dev/branches/rest-dojo-ui/client/rft/content.js
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/content.js	(revision 259)
+++ Dev/branches/rest-dojo-ui/client/rft/content.js	(revision 260)
@@ -1,4 +1,6 @@
-define(['dojo/_base/declare','dojo/_base/connect','dojo/_base/xhr','dojo/_base/lang','dojo/_base/Deferred','dojo/hash','dojo/io-query','dijit/registry','dijit','rft/util','rft/ui/Page'],
-    function(declare,connect,xhr,lang,Deferred,hash,uriQuery,registry,dijit,util,Page){
+define(['dojo/_base/declare','dojo/_base/connect','dojo/_base/xhr','dojo/dom-construct',
+    'dojo/dom-attr','dojo/_base/lang','dojo/_base/Deferred','dojo/hash',
+    'dojo/io-query','dojo/_base/json','dijit','rft/util'],
+    function(declare,connect,xhr,domConstruct,attr,lang,Deferred,hash,uriQuery,json,dijit,util){
         return new (function() {
             var self = this;
@@ -6,5 +8,5 @@
             
             var HRI = declare(null,{
-                constructor: function(){
+                constructor: function() {
                     this._path = '/';
                     this._args = {};
@@ -61,15 +63,14 @@
                 hash(newHash,replace);
                 xhr.get({
-                    url: 'pages'+hri.path()+'.html'
+                    url: 'pages'+hri.path()+'.html',
+                    failOk: true
                 })
                 .then(function(html){
-                    contentPane.set('content',html);
-                    var widgets = registry.findWidgets(contentPane.containerNode);
-                    for(var i in widgets) {
-                        if ( widgets[i].isInstanceOf(Page) ) {
-                            widgets[i].init(hri.args());
-                            break;
-                        }
-                    }
+                    var root = domConstruct.toDom(html)
+                    var props = json.toJson(hri.args());
+                    props = props.slice(1,props.length-2);
+                    if ( props )
+                        attr.set(root,'data-rft-props',props);
+                    contentPane.set('content',root);
                     d.resolve();
                 },function(){
@@ -82,16 +83,18 @@
             self.initial = function(path,args) {
                 if ( current ) {
-                    return;
+                    var dfd = new Deferred();
+                    dfd.resolved();
+                    return dfd.promise;
                 }
                 if ( hash() ) {
                     var hri = new HRI(hash());
-                    _goTo(hri, true);
+                    return _goTo(hri, true);
                 } else {
-                    _goTo(new HRI(path,args));
+                    return _goTo(new HRI(path,args));
                 }
             }
 
             self.goTo = function(path,args) {
-                _goTo(new HRI(path,args));
+                return _goTo(new HRI(path,args));
             }
 
Index: Dev/branches/rest-dojo-ui/client/rft/main.js
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/main.js	(revision 259)
+++ 	(revision )
@@ -1,3 +1,0 @@
-define(['require'], function(require) {
-    return {};
-});
Index: Dev/branches/rest-dojo-ui/client/rft/run.js
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/run.js	(revision 260)
+++ Dev/branches/rest-dojo-ui/client/rft/run.js	(revision 260)
@@ -0,0 +1,21 @@
+require(['dojo/_base/window','dojo/parser', 'rft/ui/LoginDialog', 
+    'dojo/dom', 'dojo/_base/connect', 'rft/auth', 'rft/content',
+    'dojo/domReady!', 'dijit/layout/ContentPane', 'dijit/MenuBar',
+    'dijit/MenuBarItem', 'rft/ui/MenuBarLink', 'rft/ui/Page'],
+    function(win,parser,LoginDialog,dom,connect,auth,content) {
+        parser.parse();
+
+        var login = new LoginDialog().placeAt(document.body);
+        login.startup();
+
+        auth.restore()
+        .then(function(user){
+            content.initial();
+        },function(){
+            login.show();
+        });
+
+        connect.connect(dom.byId('userinfo'),'click',function(){
+            login.show();
+        });
+    });
Index: Dev/branches/rest-dojo-ui/client/rft/ui/LoginDialog.html
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/ui/LoginDialog.html	(revision 259)
+++ Dev/branches/rest-dojo-ui/client/rft/ui/LoginDialog.html	(revision 260)
@@ -6,15 +6,16 @@
         </span>
     </div>
-    <form data-dojo-type="dijit.form.Form" data-dojo-attach-point="loginForm">
-        <fieldset>
-            <label for="username" class="loginLabel">Email</label>
-            <input data-dojo-type="dijit.form.TextBox" name="username" type="text" class="loginInput" />
-            <label for="password" class="loginLabel">Password</label>
-            <input data-dojo-type="dijit.form.TextBox" name="password" type="password" class="loginInput" />
-        </fieldset>
-    </form>
-    <button type="button" data-dojo-type="dijit.form.Button" data-dojo-attach-event="onClick:onLogin">Login</button>
-    <button type="button" data-dojo-type="dijit.form.Button" data-dojo-attach-event="onClick:onCancel">Cancel</button>
-    <div data-dojo-attach-point="loginErrors"></div>
-    <div data-dojo-attach-point="containerNode"></div>
+    <div data-dojo-attach-point="containerNode">
+        <form data-dojo-type="dijit.form.Form" data-dojo-attach-point="loginForm">
+            <fieldset>
+                <label for="username" class="loginLabel">Email</label>
+                <input data-dojo-type="dijit.form.TextBox" name="username" type="text" class="loginInput" />
+                <label for="password" class="loginLabel">Password</label>
+                <input data-dojo-type="dijit.form.TextBox" name="password" type="password" class="loginInput" />
+            </fieldset>
+        </form>
+        <button type="button" data-dojo-type="dijit.form.Button" data-dojo-attach-event="onClick:onLogin">Login</button>
+        <button type="button" data-dojo-type="dijit.form.Button" data-dojo-attach-event="onClick:onCancel">Cancel</button>
+        <div data-dojo-attach-point="loginErrors"></div>
+    </div>
 </div>
Index: Dev/branches/rest-dojo-ui/client/rft/ui/LoginDialog.js
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/ui/LoginDialog.js	(revision 259)
+++ Dev/branches/rest-dojo-ui/client/rft/ui/LoginDialog.js	(revision 260)
@@ -8,4 +8,9 @@
             title: "Login",
             baseClass: "rftLoginDialog",
+            show: function() {
+                this.loginErrors.innerHTML = '';
+                this.loginForm.reset();
+                this.inherited(arguments);
+            },
             onLogin: function() {
                 this.loginErrors.innerHTML = '';
@@ -15,5 +20,5 @@
                 .then(function() {
                     hide();
-                    content.initial("sessions");
+                    content.initial();
                 },function() {
                     this.loginErrors.innerHTML = 'Login failed.';
Index: Dev/branches/rest-dojo-ui/client/rft/ui/Page.js
===================================================================
--- Dev/branches/rest-dojo-ui/client/rft/ui/Page.js	(revision 259)
+++ Dev/branches/rest-dojo-ui/client/rft/ui/Page.js	(revision 260)
@@ -1,7 +1,23 @@
-define(['dojo/_base/declare','dijit/_WidgetBase','dijit/_Container'],
-function(declare,_WidgetBase,_Container){
-    return declare('rft.ui.Page',[_WidgetBase,_Container],{
-        init: function(args){
-        }
+define(['dojo/_base/declare','dojo/query','dojo/_base/json','dojo/dom-attr','dojo/_base/lang','dijit/registry','dijit/_WidgetBase','dijit/_Container'],
+    function(declare,query,json,attr,lang,registry,_WidgetBase,_Container){
+        return declare('rft.ui.Page',[_WidgetBase,_Container],{
+            postCreate: function() {
+                this.inherited(arguments);
+                this.args = {};
+                var props = attr.get(this.domNode,'data-rft-props');
+                if ( props ) {
+                    props = json.fromJson.call(this,'{'+props+'}');
+                    lang.mixin(this.args,props);
+                }
+            },
+            startup: function() {
+                this.inherited(arguments);
+                query('[data-rft-attach-point]').forEach(lang.hitch(this,function(node){
+                    var name = attr.get(node,'data-rft-attach-point');
+                    this[name] = registry.byNode(node) || node;
+                }));
+                this.init();
+            },
+            init: function(){}
+        });
     });
-});
Index: Dev/branches/rest-dojo-ui/server/api.php
===================================================================
--- Dev/branches/rest-dojo-ui/server/api.php	(revision 259)
+++ Dev/branches/rest-dojo-ui/server/api.php	(revision 260)
@@ -12,8 +12,13 @@
 use Tonic\Resource as Resource;
 
-function restore_session() {
+function set_session_cookie($response,$user) {
+    $response->addHeader('Set-Cookie', 'rft_uid=' . $user->uid . '; Max-Age: 3600; Path=' . $response->request->baseUri);
+}
+
+function restore_session($response) {
     if (isset($_COOKIE['rft_uid'])) {
         $user = Auth::restore($_COOKIE['rft_uid']);
         if ($user) {
+            set_session_cookie($response, $user);
             return $user;
         }
@@ -34,16 +39,18 @@
         $response = new Response($request);
 
-        if (!empty($request->data)) {
-            $data = json_decode($request->data);
-            $user = Auth::login($data->username, sha1($data->password));
-            if ($user) {
-                $response->addHeader('Set-Cookie', 'rft_uid=' . $user->uid . '; Path=' . $request->baseUri);
-                $response->body = json_encode($user);
-            } else {
+        $user = null;
+        $data = null;
+        if ( !empty($request->data) ) {
+            $data = json_decode($request->data,true);
+        }
+        if (!empty($data)) {
+            $user = Auth::login($data['username'], sha1($data['password']));
+            if (!$user) {
                 throw new ResponseException("Incorrect username and password", Response::UNAUTHORIZED);
             }
         } else {
-            throw new ResponseException("No login data provided", Response::BADREQUEST);
-        }
+            $user = restore_session($response);
+        }
+        $response->body = json_encode($user);
         return $response;
     }
@@ -64,9 +71,8 @@
 
     function get($request) {
-        restore_session();
-        $response = new Response($request);
+        $response = new Response($request);
+        restore_session($response);
 
         $type = $this->getType($request);
-
         $objects = $type::get(array());
         //$objects = array_map(function($val) { return array('uid' => $val->uid); }, $objects);
@@ -77,6 +83,6 @@
 
     function post($request) {
-        restore_session();
-        $response = new Response($request);
+        $response = new Response($request);
+        restore_session($response);
 
         $type = $this->getType($request);
@@ -128,9 +134,8 @@
 
     function get($request) {
-        restore_session();
-        $response = new Response($request);
+        $response = new Response($request);
+        restore_session($response);
 
         $info = $this->getTypeAndUid($request);
-
         $objects = $info['type']::get(array('uid' => $info['uid']));
         if (empty($objects)) {
@@ -143,6 +148,6 @@
 
     function put($request) {
-        restore_session();
-        $response = new Response($request);
+        $response = new Response($request);
+        restore_session($response);
 
         $info = $this->getTypeAndUid($request);
