Added setup options.
This commit is contained in:
parent
ff0e6e0093
commit
74054e69a4
@ -53,6 +53,11 @@ mail.smtp.password = mymailpassword
|
||||
# Server-related settings
|
||||
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*
|
||||
# Debug mode will enable the interactive debugging tool, allowing ANYONE to
|
||||
# execute malicious code after an exception is raised.
|
||||
|
@ -53,6 +53,11 @@ mail.smtp.password = mymailpassword
|
||||
# Server-related settings
|
||||
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*
|
||||
# Debug mode will enable the interactive debugging tool, allowing ANYONE to
|
||||
# execute malicious code after an exception is raised.
|
||||
|
@ -23,9 +23,14 @@
|
||||
"""
|
||||
Setup the ScribeEngine application
|
||||
"""
|
||||
import os
|
||||
import hashlib
|
||||
import hmac
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
from paste.deploy.converters import asbool
|
||||
|
||||
from scribeengine.config.environment import load_environment
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -35,55 +40,50 @@ def setup_app(command, conf, vars):
|
||||
conf.local_conf['setup-app'] = True
|
||||
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 import Category, Permission, Post, Variable, \
|
||||
User, Role
|
||||
|
||||
if os.name == 'posix':
|
||||
if os.name == u'posix':
|
||||
import readline
|
||||
|
||||
# Let's prompt the user for an e-mail address, password and nick for the first user in the system.
|
||||
print 'First User:'
|
||||
email = raw_input('E-mail address [admin@scribeengine.org]: ')
|
||||
password = raw_input('Password [P@ssw0rd]: ')
|
||||
nick = raw_input('Nick [Admin]: ')
|
||||
if asbool(conf.local_conf[u'setup.create_tables']):
|
||||
# Create the tables if they don't already exist
|
||||
metadata.create_all(bind=engine, checkfirst=True)
|
||||
|
||||
if not email:
|
||||
email = u'admin@scribeengine.org'
|
||||
else:
|
||||
email = unicode(email)
|
||||
if not password:
|
||||
password = u'P@ssw0rd'
|
||||
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')
|
||||
if asbool(conf.local_conf[u'setup.create_user']):
|
||||
# Let's prompt the user for an e-mail address, password and nick for the
|
||||
# first user in the system.
|
||||
print 'First User:'
|
||||
email = raw_input('E-mail address [admin@scribeengine.org]: ')
|
||||
password = raw_input('Password [P@ssw0rd]: ')
|
||||
nick = raw_input('Nick [Admin]: ')
|
||||
if not email:
|
||||
email = u'admin@scribeengine.org'
|
||||
else:
|
||||
email = unicode(email)
|
||||
if not password:
|
||||
password = u'P@ssw0rd'
|
||||
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
|
||||
metadata.create_all(bind=engine, checkfirst=True)
|
||||
if asbool(conf.local_conf[u'setup.blog_details']):
|
||||
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()
|
||||
|
Reference in New Issue
Block a user