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:
parent
7d8240f7be
commit
27581a0445
|
@ -5,10 +5,13 @@ import cherrypy
|
||||||
settings = {
|
settings = {
|
||||||
"global": {
|
"global": {
|
||||||
"server.thread_pool": 4,
|
"server.thread_pool": 4,
|
||||||
|
"session_filter.storage_type": "ram",
|
||||||
|
"session_filter.timeout": 60 * 24 * 365, # one year
|
||||||
"static_filter.root": os.getcwd(),
|
"static_filter.root": os.getcwd(),
|
||||||
"server.log_to_screen": True,
|
"server.log_to_screen": True,
|
||||||
"luminotes.launch_browser": True,
|
"luminotes.launch_browser": True,
|
||||||
"luminotes.db_host": None, # use local SQLite database
|
"luminotes.db_host": None, # use local SQLite database
|
||||||
|
"luminotes.auto_login_username": "desktopuser",
|
||||||
"luminotes.rate_plans": [
|
"luminotes.rate_plans": [
|
||||||
{
|
{
|
||||||
"name": "desktop",
|
"name": "desktop",
|
||||||
|
|
|
@ -9,6 +9,7 @@ from Groups import Groups
|
||||||
from Files import Files
|
from Files import Files
|
||||||
from Forums import Forums
|
from Forums import Forums
|
||||||
from Database import Valid_id, end_transaction
|
from Database import Valid_id, end_transaction
|
||||||
|
from Users import update_auth
|
||||||
from model.Note import Note
|
from model.Note import Note
|
||||||
from model.Notebook import Notebook
|
from model.Notebook import Notebook
|
||||||
from model.User import User
|
from model.User import User
|
||||||
|
@ -157,22 +158,39 @@ class Root( object ):
|
||||||
@strongly_expire
|
@strongly_expire
|
||||||
@end_transaction
|
@end_transaction
|
||||||
@grab_user_id
|
@grab_user_id
|
||||||
|
@update_auth
|
||||||
@validate(
|
@validate(
|
||||||
user_id = Valid_id( none_okay = True ),
|
user_id = Valid_id( none_okay = True ),
|
||||||
)
|
)
|
||||||
def index( self, user_id ):
|
def index( self, user_id ):
|
||||||
"""
|
"""
|
||||||
Provide the information necessary to display the web site's front page, potentially performing
|
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_url = self.__settings[ u"global" ].get( u"luminotes.https_url" )
|
||||||
https_proxy_ip = self.__settings[ u"global" ].get( u"luminotes.https_proxy_ip" )
|
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 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" )
|
referer = cherrypy.request.headerMap.get( u"Referer" )
|
||||||
if not referer:
|
if not referer:
|
||||||
user = self.__database.load( User, user_id )
|
user = self.__database.load( User, user_id )
|
||||||
|
|
||||||
if user and user.username:
|
if user and user.username:
|
||||||
first_notebook = self.__database.select_one( Notebook, user.sql_load_notebooks( parents_only = True, undeleted_only = True ) )
|
first_notebook = self.__database.select_one( Notebook, user.sql_load_notebooks( parents_only = True, undeleted_only = True ) )
|
||||||
if first_notebook:
|
if first_notebook:
|
||||||
|
|
|
@ -207,19 +207,19 @@ class Users( object ):
|
||||||
self.__payment_email = payment_email
|
self.__payment_email = payment_email
|
||||||
self.__rate_plans = rate_plans
|
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
|
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.
|
"welcome to your wiki" Note. This method does not commit the transaction to the database.
|
||||||
|
|
||||||
@type username: unicode (alphanumeric only)
|
@type username: unicode (alphanumeric only)
|
||||||
@param username: username to use for this new user
|
@param username: username to use for this new user
|
||||||
@type password: unicode
|
@type password: unicode or NoneType
|
||||||
@param password: password to use
|
@param password: password to use (optional, defaults to None)
|
||||||
@type password_repeat: unicode
|
@type password_repeat: unicode or NoneType
|
||||||
@param password_repeat: password to use, again
|
@param password_repeat: password to use, again (optional, defaults to None)
|
||||||
@type email_address: unicode
|
@type email_address: unicode or NoneType
|
||||||
@param email_address: user's email address
|
@param email_address: user's email address (optional, defaults to None)
|
||||||
@type initial_rate_plan: int or NoneType
|
@type initial_rate_plan: int or NoneType
|
||||||
@param initial_rate_plan: index of rate plan to start the user with before they even subscribe
|
@param initial_rate_plan: index of rate plan to start the user with before they even subscribe
|
||||||
(defaults to None)
|
(defaults to None)
|
||||||
|
@ -236,7 +236,7 @@ class Users( object ):
|
||||||
if user is not None:
|
if user is not None:
|
||||||
raise Signup_error( u"Sorry, that username is not available. Please try something else." )
|
raise Signup_error( u"Sorry, that username is not available. Please try something else." )
|
||||||
|
|
||||||
if len( email_address ) > 0:
|
if email_address:
|
||||||
try:
|
try:
|
||||||
email_address = valid_email_address( email_address )
|
email_address = valid_email_address( email_address )
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
@ -308,7 +308,7 @@ class Users( object ):
|
||||||
@raise Signup_error: passwords don't match or the username is unavailable
|
@raise Signup_error: passwords don't match or the username is unavailable
|
||||||
@raise Validation_error: one of the arguments is invalid
|
@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()
|
self.__database.commit()
|
||||||
|
|
||||||
# if there's an invite_id, then redeem that invite and redirect to the invite's notebook
|
# 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 )
|
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
|
# 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,
|
username,
|
||||||
password,
|
password,
|
||||||
password_repeat,
|
password_repeat,
|
||||||
|
|
|
@ -25,9 +25,10 @@ class Initializer( object ):
|
||||||
( u"enable JavaScript.html", False ),
|
( 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.database = database
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
|
self.desktop = desktop
|
||||||
self.main_notebook = None
|
self.main_notebook = None
|
||||||
self.anonymous = None
|
self.anonymous = None
|
||||||
|
|
||||||
|
@ -41,6 +42,8 @@ class Initializer( object ):
|
||||||
|
|
||||||
self.create_main_notebook()
|
self.create_main_notebook()
|
||||||
self.create_anonymous_user()
|
self.create_anonymous_user()
|
||||||
|
if desktop is True:
|
||||||
|
self.create_desktop_user()
|
||||||
self.database.commit()
|
self.database.commit()
|
||||||
|
|
||||||
def create_main_notebook( self ):
|
def create_main_notebook( self ):
|
||||||
|
@ -74,6 +77,19 @@ class Initializer( object ):
|
||||||
# give the anonymous user read-only access to the main notebook
|
# 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 )
|
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 ):
|
def main( args = None ):
|
||||||
nuke = False
|
nuke = False
|
||||||
|
@ -82,6 +98,7 @@ def main( args = None ):
|
||||||
from config import Common
|
from config import Common
|
||||||
|
|
||||||
cherrypy.config.update( Common.settings )
|
cherrypy.config.update( Common.settings )
|
||||||
|
desktop = False
|
||||||
|
|
||||||
if args and "-d" in args:
|
if args and "-d" in args:
|
||||||
from config import Development
|
from config import Development
|
||||||
|
@ -89,6 +106,7 @@ def main( args = None ):
|
||||||
elif args and "-l" in args:
|
elif args and "-l" in args:
|
||||||
from config import Desktop
|
from config import Desktop
|
||||||
settings = Desktop.settings
|
settings = Desktop.settings
|
||||||
|
desktop = True
|
||||||
else:
|
else:
|
||||||
from config import Production
|
from config import Production
|
||||||
settings = Production.settings
|
settings = Production.settings
|
||||||
|
@ -111,7 +129,7 @@ def main( args = None ):
|
||||||
host = host,
|
host = host,
|
||||||
ssl_mode = settings[ u"global" ].get( u"luminotes.db_ssl_mode" ),
|
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 ):
|
def fix_note_contents( contents, notebook_id, note_ids, settings ):
|
||||||
|
|
Reference in New Issue