diff --git a/controller/Root.py b/controller/Root.py index 34b57ce..95df45f 100644 --- a/controller/Root.py +++ b/controller/Root.py @@ -34,7 +34,12 @@ class Root( object ): self.__database = database self.__settings = settings self.__notebooks = Notebooks( scheduler, database ) - self.__users = Users( scheduler, database, settings[ u"global" ].get( u"luminotes.http_url", u"" ) ) + self.__users = Users( + scheduler, + database, + settings[ u"global" ].get( u"luminotes.http_url", u"" ), + settings[ u"global" ].get( u"luminotes.https_url", u"" ), + ) @expose( view = Main_page ) def index( self ): diff --git a/controller/Users.py b/controller/Users.py index 9224ce4..6d42756 100644 --- a/controller/Users.py +++ b/controller/Users.py @@ -106,7 +106,7 @@ class Users( object ): """ Controller for dealing with users, corresponding to the "/users" URL. """ - def __init__( self, scheduler, database, http_url ): + def __init__( self, scheduler, database, http_url, https_url ): """ Create a new Users object. @@ -116,12 +116,15 @@ class Users( object ): @param database: database that users are stored in @type http_url: unicode @param http_url: base URL to use for non-SSL http requests, or an empty string + @type https_url: unicode + @param https_url: base URL to use for SSL http requests, or an empty string @rtype: Users @return: newly constructed Users """ self.__scheduler = scheduler self.__database = database self.__http_url = http_url + self.__https_url = https_url @expose( view = Json ) @update_auth @@ -287,19 +290,29 @@ class Users( object ): return # in addition to this user's own notebooks, add to that list the anonymous user's notebooks + self.__database.load( u"User anonymous", self.__scheduler.thread ) + anonymous = ( yield Scheduler.SLEEP ) + login_url = None + if user_id: - self.__database.load( u"User anonymous", self.__scheduler.thread ) - anonymous = ( yield Scheduler.SLEEP ) notebooks = anonymous.notebooks else: notebooks = [] + if len( anonymous.notebooks ) > 0: + anon_notebook = anonymous.notebooks[ 0 ] + login_note = anon_notebook.lookup_note_by_title( u"login" ) + if login_note: + login_url = "%s/notebooks/%s?note_id=%s" % ( self.__https_url, anon_notebook.object_id, login_note.object_id ) + notebooks += user.notebooks + yield dict( user = user, notebooks = notebooks, startup_notes = include_startup_notes and len( notebooks ) > 0 and notebooks[ 0 ].startup_notes or [], http_url = self.__http_url, + login_url = login_url, ) scheduler = property( lambda self: self.__scheduler ) diff --git a/controller/test/Test_users.py b/controller/test/Test_users.py index cd80550..cfb9362 100644 --- a/controller/test/Test_users.py +++ b/controller/test/Test_users.py @@ -38,7 +38,7 @@ class Test_users( Test_controller ): self.database.next_id( self.scheduler.thread ) self.anon_notebook = Notebook( ( yield Scheduler.SLEEP ), u"anon notebook" ) self.database.next_id( self.scheduler.thread ) - self.startup_note = Note( ( yield Scheduler.SLEEP ), u"contents go here" ) + self.startup_note = Note( ( yield Scheduler.SLEEP ), u"

login

" ) self.anon_notebook.add_note( self.startup_note ) self.anon_notebook.add_startup_note( self.startup_note ) @@ -164,6 +164,7 @@ class Test_users( Test_controller ): assert result[ u"user" ] == self.user assert result[ u"notebooks" ] == [ self.anon_notebook ] + self.notebooks assert result[ u"http_url" ] == self.settings[ u"global" ].get( u"luminotes.http_url" ) + assert result[ u"login_url" ] == None startup_notes = result[ "startup_notes" ] if include_startup_notes: @@ -184,6 +185,13 @@ class Test_users( Test_controller ): assert result[ u"notebooks" ] == [ self.anon_notebook ] assert result[ u"http_url" ] == self.settings[ u"global" ].get( u"luminotes.http_url" ) + login_note = self.anon_notebook.lookup_note_by_title( u"login" ) + assert result[ u"login_url" ] == u"%s/notebooks/%s?note_id=%s" % ( + self.settings[ u"global" ][ u"luminotes.https_url" ], + self.anon_notebook.object_id, + login_note.object_id, + ) + startup_notes = result[ "startup_notes" ] if include_startup_notes: assert len( startup_notes ) == 1 diff --git a/static/css/style.css b/static/css/style.css index 7ed9fc8..51ef116 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -157,6 +157,10 @@ ol li { font-size: 85%; } +#user_area a { + font-weight: bold; +} + #notebook_header_area { padding: 0.25em; -moz-border-radius: 0.5em 0.5em 0.5em 0; diff --git a/static/html/navigation.html b/static/html/navigation.html index a418d1a..0d0afb5 100644 --- a/static/html/navigation.html +++ b/static/html/navigation.html @@ -4,5 +4,4 @@ try it out - faq - meet the team - -contact info - -login +contact info diff --git a/static/js/Wiki.js b/static/js/Wiki.js index 3ddb2b5..6d417ad 100644 --- a/static/js/Wiki.js +++ b/static/js/Wiki.js @@ -50,14 +50,20 @@ Wiki.prototype.display_user = function ( result ) { this.populate( { "notebook" : result.notebooks[ 0 ], "startup_notes": result.startup_notes } ); } - if ( result.user.username == "anonymous" ) + var user_span = createDOM( "span" ); + replaceChildNodes( "user_area", user_span ); + + // if not logged in, display a login link + if ( result.user.username == "anonymous" && result.login_url ) { + appendChildNodes( user_span, createDOM( "a", { "href": result.login_url, "id": "login_link" }, "login" ) ); return; + } // display links for current notebook and a list of all notebooks that the user has access to - var span = createDOM( "span" ); - replaceChildNodes( "notebooks_area", span ); + var notebooks_span = createDOM( "span" ); + replaceChildNodes( "notebooks_area", notebooks_span ); - appendChildNodes( span, createDOM( "h3", "notebooks" ) ); + appendChildNodes( notebooks_span, createDOM( "h3", "notebooks" ) ); for ( var i in result.notebooks ) { var notebook = result.notebooks[ i ]; @@ -69,7 +75,7 @@ Wiki.prototype.display_user = function ( result ) { if ( notebook.object_id == this.notebook_id ) div_class += " current_notebook_name"; - appendChildNodes( span, createDOM( "div", { + appendChildNodes( notebooks_span, createDOM( "div", { "class": div_class }, createDOM( "a", { "href": "/notebooks/" + notebook.object_id, @@ -78,11 +84,9 @@ Wiki.prototype.display_user = function ( result ) { } // display the name of the logged in user and a logout link - span = createDOM( "span" ); - replaceChildNodes( "user_area", span ); - appendChildNodes( span, "logged in as " + result.user.username ); - appendChildNodes( span, " | " ); - appendChildNodes( span, createDOM( "a", { "href": result.http_url + "/", "id": "logout_link" }, "logout" ) ); + appendChildNodes( user_span, "logged in as " + result.user.username ); + appendChildNodes( user_span, " | " ); + appendChildNodes( user_span, createDOM( "a", { "href": result.http_url + "/", "id": "logout_link" }, "logout" ) ); var self = this; connect( "logout_link", "onclick", function ( event ) {