Example #1
0
            from config import sensitiveParams_stub as sensitiveParams
        else:
            logger.fatal("No users in the database and not suitable parameters to fill them in!")
            exit(1)
    logger.info("Setting secret key from sensitiveParams config file!")
    app.secret_key = sensitiveParams._secretKey
else:
    # Set a temporary secret key. It can be set from the database later
    app.secret_key = str(os.urandom(50))

# Enable debugging if set in configuration
if serverParameters.debug == True:
    app.debug = True

# Setup Bcrypt
app.config["BCRYPT_LOG_ROUNDS"] = serverParameters.bcryptLogRounds
bcrypt = Bcrypt(app)

# Setup login manager
loginManager = LoginManager()
loginManager.init_app(app)

# Tells the manager where to redirect when login is required.
loginManager.login_view = "login"

###################################################
@loginManager.user_loader
def load_user(user):
    """ Used to remember the user so that they don't need to login again each time they visit the site. """
    return auth.User.getUser(user, db)
Example #2
0
from flask import Flask
from flask.ext.mongoengine import MongoEngine
from flask.ext.bcrypt import Bcrypt
from flask.ext import login
from flask.ext.babelex import Babel
import settings

app = Flask(settings.APP_NAME)
app.config.from_object(settings)

login_manager = login.LoginManager()

app.config["BCRYPT_LOG_ROUNDS"] = 1

db = MongoEngine(app)
bcrypt = Bcrypt(app)
babel = Babel(app)


@babel.localeselector
def get_locale():
    # Put your logic here. Application can store locale in
    # user profile, cookie, session, etc.
    return "zh_CN"