def app(): rv = App(__name__) rv.config.mailer.sender = '*****@*****.**' rv.config.auth.single_template = True rv.config.auth.hmac_key = "foobar" rv.pipeline = [SessionManager.cookies('foobar')] return rv
async def test_session_cookie(ctx): session_cookie = SessionManager.cookies(key='sid', secure=True, domain='localhost', cookie_name='foo_session') assert session_cookie.key == 'sid' assert session_cookie.secure is True assert session_cookie.domain == 'localhost' await session_cookie.open_request() assert ctx.session._expiration == 3600 await session_cookie.close_request() cookie = str(ctx.response.cookies) assert 'foo_session' in cookie assert 'Domain=localhost;' in cookie assert 'secure' in cookie.lower() ctx.request.cookies = ctx.response.cookies await session_cookie.open_request() assert ctx.session._expiration == 3600
) # create an admin group admins = auth.create_group("admin") # add user to admins group auth.add_membership(admins, user.id) db.commit() @app.command('setup') def setup(): setup_admin() #: pipeline app.pipeline = [ SessionManager.cookies('Walternate'), db.pipe, auth.pipe ] #: exposing functions @app.route("/") async def index(): posts = Post.all().select(orderby=~Post.date) return dict(posts=posts) @app.route("/post/<int:pid>") async def one(pid): def _validate_comment(form): # manually set post id in comment form form.params.post = pid
app.config.REST.min_pagesize = 10 app.config.REST.max_pagesize = 5000 # Config # app.config_from_yaml('app.yml') # app.config_from_yaml('db.yml', 'db') # app.config_from_yaml('mailer.yml', 'mailer') # app.config_from_yaml('auth.yml', 'auth') app.config.db.uri = 'sqlite://database.sqlite' db = Database(app, auto_migrate=False) # mailer = Mailer(app) auth = Auth(app, db, user_model=User) db.define_models([User, Post, Subscription]) app.pipeline = [ SessionManager.cookies('b795-18a878ae9368', expire=4 * 60 * 60), db.pipe, auth.pipe, ] auth_routes = auth.module(__name__) from backend.controllers import * # @auth_routes.after_login # def after_login(form): # redirect(url('main.index'))
) # create an admin group admins = auth.create_group("admin") # add user to admins group auth.add_membership(admins, user.id) db.commit() @app.command('setup') def setup(): setup_admin() #: pipeline app.pipeline = [ SessionManager.cookies('GreatScott'), db.pipe, auth.pipe ] #: exposing functions @app.route("/") async def index(): posts = Post.all().select(orderby=~Post.date) return dict(posts=posts) @app.route("/post/<int:pid>") async def one(pid): def _validate_comment(form): # manually set post id in comment form form.params.post = pid