witten
/
luminotes
Archived
1
0
Fork 0

For desktop version, creating default user and auto-logging that user in. Also set a larger session timeout for desktop version.

This commit is contained in:
Dan Helfman 2008-08-20 19:50:18 -07:00
parent 7d8240f7be
commit 27581a0445
4 changed files with 54 additions and 15 deletions

View File

@ -5,10 +5,13 @@ import cherrypy
settings = {
"global": {
"server.thread_pool": 4,
"session_filter.storage_type": "ram",
"session_filter.timeout": 60 * 24 * 365, # one year
"static_filter.root": os.getcwd(),
"server.log_to_screen": True,
"luminotes.launch_browser": True,
"luminotes.db_host": None, # use local SQLite database
"luminotes.auto_login_username": "desktopuser",
"luminotes.rate_plans": [
{
"name": "desktop",

View File

@ -9,6 +9,7 @@ from Groups import Groups
from Files import Files
from Forums import Forums
from Database import Valid_id, end_transaction
from Users import update_auth
from model.Note import Note
from model.Notebook import Notebook
from model.User import User
@ -157,22 +158,39 @@ class Root( object ):
@strongly_expire
@end_transaction
@grab_user_id
@update_auth
@validate(
user_id = Valid_id( none_okay = True ),
)
def index( self, user_id ):
"""
Provide the information necessary to display the web site's front page, potentially performing
a redirect to the https version of the page.
a redirect to the https version of the page or the user's first notebook.
"""
https_url = self.__settings[ u"global" ].get( u"luminotes.https_url" )
https_proxy_ip = self.__settings[ u"global" ].get( u"luminotes.https_proxy_ip" )
# if the server is configured to auto-login a particular user, log that user in and redirect to
# their first notebook
auto_login_username = self.__settings[ u"global" ].get( u"luminotes.auto_login_username" )
if auto_login_username:
user = self.__database.select_one( User, User.sql_load_by_username( auto_login_username ), use_cache = True )
if user and user.username:
first_notebook = self.__database.select_one( Notebook, user.sql_load_notebooks( parents_only = True, undeleted_only = True ) )
if first_notebook:
return dict(
redirect = u"/notebooks/%s" % first_notebook.object_id,
authenticated = user,
)
# if the user is logged in and the HTTP request has no referrer, then redirect to the user's
# first notebook
if user_id:
# if the user is logged in and the HTTP request has no referrer, then redirect to the user's first notebook
referer = cherrypy.request.headerMap.get( u"Referer" )
if not referer:
user = self.__database.load( User, user_id )
if user and user.username:
first_notebook = self.__database.select_one( Notebook, user.sql_load_notebooks( parents_only = True, undeleted_only = True ) )
if first_notebook:

View File

@ -207,19 +207,19 @@ class Users( object ):
self.__payment_email = payment_email
self.__rate_plans = rate_plans
def __create_user( self, username, password, password_repeat, email_address, initial_rate_plan = None ):
def create_user( self, username, password = None, password_repeat = None, email_address = None, initial_rate_plan = None ):
"""
Create a new User based on the given information. Start that user with their own Notebook and a
"welcome to your wiki" Note. This method does not commit the transaction to the database.
@type username: unicode (alphanumeric only)
@param username: username to use for this new user
@type password: unicode
@param password: password to use
@type password_repeat: unicode
@param password_repeat: password to use, again
@type email_address: unicode
@param email_address: user's email address
@type password: unicode or NoneType
@param password: password to use (optional, defaults to None)
@type password_repeat: unicode or NoneType
@param password_repeat: password to use, again (optional, defaults to None)
@type email_address: unicode or NoneType
@param email_address: user's email address (optional, defaults to None)
@type initial_rate_plan: int or NoneType
@param initial_rate_plan: index of rate plan to start the user with before they even subscribe
(defaults to None)
@ -236,7 +236,7 @@ class Users( object ):
if user is not None:
raise Signup_error( u"Sorry, that username is not available. Please try something else." )
if len( email_address ) > 0:
if email_address:
try:
email_address = valid_email_address( email_address )
except ValueError:
@ -308,7 +308,7 @@ class Users( object ):
@raise Signup_error: passwords don't match or the username is unavailable
@raise Validation_error: one of the arguments is invalid
"""
( user, notebook ) = self.__create_user( username, password, password_repeat, email_address )
( user, notebook ) = self.create_user( username, password, password_repeat, email_address )
self.__database.commit()
# if there's an invite_id, then redeem that invite and redirect to the invite's notebook
@ -401,7 +401,7 @@ class Users( object ):
raise Signup_error( 'Your current rate plan includes a maximum of %s users. Please upgrade your account for additional users.' % included_users_count )
# create a new user with the same rate plan as the currently logged-in user
( created_user, notebook ) = self.__create_user(
( created_user, notebook ) = self.create_user(
username,
password,
password_repeat,

View File

@ -25,9 +25,10 @@ class Initializer( object ):
( u"enable JavaScript.html", False ),
]
def __init__( self, database, host, settings, nuke = False ):
def __init__( self, database, host, settings, desktop, nuke = False ):
self.database = database
self.settings = settings
self.desktop = desktop
self.main_notebook = None
self.anonymous = None
@ -41,6 +42,8 @@ class Initializer( object ):
self.create_main_notebook()
self.create_anonymous_user()
if desktop is True:
self.create_desktop_user()
self.database.commit()
def create_main_notebook( self ):
@ -74,6 +77,19 @@ class Initializer( object ):
# give the anonymous user read-only access to the main notebook
self.database.execute( self.anonymous.sql_save_notebook( self.main_notebook.object_id, read_write = False, owner = False ), commit = False )
def create_desktop_user( self ):
from controller.Users import Users
users = Users(
self.database,
self.settings[ u"global" ].get( u"luminotes.http_url", u"" ),
self.settings[ u"global" ].get( u"luminotes.https_url", u"" ),
self.settings[ u"global" ].get( u"luminotes.support_email", u"" ),
self.settings[ u"global" ].get( u"luminotes.payment_email", u"" ),
self.settings[ u"global" ].get( u"luminotes.rate_plans", [] ),
)
users.create_user( u"desktopuser" )
def main( args = None ):
nuke = False
@ -82,6 +98,7 @@ def main( args = None ):
from config import Common
cherrypy.config.update( Common.settings )
desktop = False
if args and "-d" in args:
from config import Development
@ -89,6 +106,7 @@ def main( args = None ):
elif args and "-l" in args:
from config import Desktop
settings = Desktop.settings
desktop = True
else:
from config import Production
settings = Production.settings
@ -111,7 +129,7 @@ def main( args = None ):
host = host,
ssl_mode = settings[ u"global" ].get( u"luminotes.db_ssl_mode" ),
)
initializer = Initializer( database, host, settings, nuke )
initializer = Initializer( database, host, settings, desktop, nuke )
def fix_note_contents( contents, notebook_id, note_ids, settings ):