Added setup options.
This commit is contained in:
parent
ff0e6e0093
commit
74054e69a4
@ -53,6 +53,11 @@ mail.smtp.password = mymailpassword
|
|||||||
# Server-related settings
|
# Server-related settings
|
||||||
server.timezone = 'Africa/Johannesburg'
|
server.timezone = 'Africa/Johannesburg'
|
||||||
|
|
||||||
|
# Setup options
|
||||||
|
setup.create_tables = true
|
||||||
|
setup.create_user = false
|
||||||
|
setup.blog_details = false
|
||||||
|
|
||||||
# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
|
# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
|
||||||
# Debug mode will enable the interactive debugging tool, allowing ANYONE to
|
# Debug mode will enable the interactive debugging tool, allowing ANYONE to
|
||||||
# execute malicious code after an exception is raised.
|
# execute malicious code after an exception is raised.
|
||||||
|
@ -53,6 +53,11 @@ mail.smtp.password = mymailpassword
|
|||||||
# Server-related settings
|
# Server-related settings
|
||||||
server.timezone = 'Africa/Johannesburg'
|
server.timezone = 'Africa/Johannesburg'
|
||||||
|
|
||||||
|
# Setup options (for when you run "paster setup-app config.ini")
|
||||||
|
setup.create_tables = true
|
||||||
|
setup.create_user = false
|
||||||
|
setup.blog_details = false
|
||||||
|
|
||||||
# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
|
# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
|
||||||
# Debug mode will enable the interactive debugging tool, allowing ANYONE to
|
# Debug mode will enable the interactive debugging tool, allowing ANYONE to
|
||||||
# execute malicious code after an exception is raised.
|
# execute malicious code after an exception is raised.
|
||||||
|
@ -23,9 +23,14 @@
|
|||||||
"""
|
"""
|
||||||
Setup the ScribeEngine application
|
Setup the ScribeEngine application
|
||||||
"""
|
"""
|
||||||
|
import os
|
||||||
|
import hashlib
|
||||||
|
import hmac
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from paste.deploy.converters import asbool
|
||||||
|
|
||||||
from scribeengine.config.environment import load_environment
|
from scribeengine.config.environment import load_environment
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -35,55 +40,50 @@ def setup_app(command, conf, vars):
|
|||||||
conf.local_conf['setup-app'] = True
|
conf.local_conf['setup-app'] = True
|
||||||
load_environment(conf.global_conf, conf.local_conf)
|
load_environment(conf.global_conf, conf.local_conf)
|
||||||
|
|
||||||
import os
|
|
||||||
import hashlib
|
|
||||||
import hmac
|
|
||||||
from scribeengine.model.meta import metadata, Session, engine
|
from scribeengine.model.meta import metadata, Session, engine
|
||||||
from scribeengine.model import Category, Permission, Post, Variable, \
|
from scribeengine.model import Category, Permission, Post, Variable, \
|
||||||
User, Role
|
User, Role
|
||||||
|
|
||||||
if os.name == 'posix':
|
if os.name == u'posix':
|
||||||
import readline
|
import readline
|
||||||
|
|
||||||
# Let's prompt the user for an e-mail address, password and nick for the first user in the system.
|
if asbool(conf.local_conf[u'setup.create_tables']):
|
||||||
print 'First User:'
|
# Create the tables if they don't already exist
|
||||||
email = raw_input('E-mail address [admin@scribeengine.org]: ')
|
metadata.create_all(bind=engine, checkfirst=True)
|
||||||
password = raw_input('Password [P@ssw0rd]: ')
|
|
||||||
nick = raw_input('Nick [Admin]: ')
|
|
||||||
|
|
||||||
if not email:
|
if asbool(conf.local_conf[u'setup.create_user']):
|
||||||
email = u'admin@scribeengine.org'
|
# Let's prompt the user for an e-mail address, password and nick for the
|
||||||
else:
|
# first user in the system.
|
||||||
email = unicode(email)
|
print 'First User:'
|
||||||
if not password:
|
email = raw_input('E-mail address [admin@scribeengine.org]: ')
|
||||||
password = u'P@ssw0rd'
|
password = raw_input('Password [P@ssw0rd]: ')
|
||||||
else:
|
nick = raw_input('Nick [Admin]: ')
|
||||||
password = unicode(password)
|
if not email:
|
||||||
if not nick:
|
email = u'admin@scribeengine.org'
|
||||||
nick = u'Admin'
|
else:
|
||||||
else:
|
email = unicode(email)
|
||||||
nick = unicode(nick)
|
if not password:
|
||||||
password = unicode(hmac.new(conf[u'security.salt'], password,
|
password = u'P@ssw0rd'
|
||||||
hashlib.sha256).hexdigest(), u'utf-8')
|
else:
|
||||||
|
password = unicode(password)
|
||||||
|
if not nick:
|
||||||
|
nick = u'Admin'
|
||||||
|
else:
|
||||||
|
nick = unicode(nick)
|
||||||
|
password = unicode(hmac.new(conf[u'security.salt'], password,
|
||||||
|
hashlib.sha256).hexdigest(), u'utf-8')
|
||||||
|
perm_addposts = Permission(name=u'Add Posts')
|
||||||
|
perm_editmyposts = Permission(name=u'Edit My Posts')
|
||||||
|
perm_delmyposts = Permission(name=u'Delete My Posts')
|
||||||
|
role_admin = Role(name=u'Administrator')
|
||||||
|
role_admin.permissions.extend([perm_addposts, perm_editmyposts, perm_delmyposts])
|
||||||
|
user = User(email=email, password=password, nick=nick)
|
||||||
|
user.roles.append(role_admin)
|
||||||
|
Session.add(user)
|
||||||
|
|
||||||
# Create the tables if they don't already exist
|
if asbool(conf.local_conf[u'setup.blog_details']):
|
||||||
metadata.create_all(bind=engine, checkfirst=True)
|
blog_title = Variable(key=u'blog title', value=u'ScribeEngine')
|
||||||
|
blog_slogan = Variable(key=u'blog slogan', value=u'open source blog software')
|
||||||
|
Session.add_all([blog_title, blog_slogan])
|
||||||
|
|
||||||
blog_title = Variable(key=u'blog title', value=u'ScribeEngine')
|
|
||||||
blog_slogan = Variable(key=u'blog slogan', value=u'open source blog software')
|
|
||||||
|
|
||||||
pylons_cat = Category(name=u'Pylons', url=u'pylons')
|
|
||||||
database_cat = Category(name=u'Database', url=u'database')
|
|
||||||
|
|
||||||
perm_addposts = Permission(name=u'Add Posts')
|
|
||||||
perm_editmyposts = Permission(name=u'Edit My Posts')
|
|
||||||
perm_delmyposts = Permission(name=u'Delete My Posts')
|
|
||||||
|
|
||||||
role_admin = Role(name=u'Administrator')
|
|
||||||
role_admin.permissions.extend([perm_addposts, perm_editmyposts, perm_delmyposts])
|
|
||||||
|
|
||||||
user = User(email=email, password=password, nick=nick)
|
|
||||||
user.roles.append(role_admin)
|
|
||||||
|
|
||||||
Session.add_all([blog_title, blog_slogan, user])
|
|
||||||
Session.commit()
|
Session.commit()
|
||||||
|
Reference in New Issue
Block a user