witten
/
luminotes
Archived
1
0
Fork 0

Moved login link to the top of the page; now present dependent on whether you're already logged in.

This commit is contained in:
Dan Helfman 2007-08-30 23:57:56 +00:00
parent 0f401829e7
commit bcade394e9
6 changed files with 50 additions and 17 deletions

View File

@ -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 ):

View File

@ -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 )

View File

@ -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"<h3>login</h3>" )
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

View File

@ -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;

View File

@ -4,5 +4,4 @@
<a href="/notebooks/%s?note_id=new" target="_top">try it out</a> -
<a href="/notebooks/%s?note_id=new">faq</a> -
<a href="/notebooks/%s?note_id=new">meet the team</a> -
<a href="/notebooks/%s?note_id=new">contact info</a> -
<a href="/notebooks/%s?note_id=new" target="_top">login</a>
<a href="/notebooks/%s?note_id=new">contact info</a>

View File

@ -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 ) {