add database connection
This commit is contained in:
parent
14597ebe28
commit
86a896f78b
|
@ -7,10 +7,17 @@ eg. https://example.com/stickup.
|
|||
"""
|
||||
server_domain = 'steelbea.me'
|
||||
url_prefix = '/stickup'
|
||||
|
||||
buckler = {
|
||||
'url': "https://steelbea.me/buckler",
|
||||
'app_id': 1,
|
||||
'app_key': """password""",
|
||||
'app_key': r"""password""",
|
||||
'login_url': "https://steelbea.me/buckler/login",
|
||||
}
|
||||
|
||||
mailserver_db = {
|
||||
'database': 'mailserver',
|
||||
'user': 'mailserver',
|
||||
'password': r"""password""",
|
||||
'host': 'localhost',
|
||||
'port': 5432,
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import jinja2
|
|||
import aiohttp_jinja2
|
||||
from aiohttp_jinja2 import render_template
|
||||
import uvloop
|
||||
import asyncpg
|
||||
|
||||
import config
|
||||
import buckler_aiohttp
|
||||
|
@ -19,13 +20,17 @@ routes = web.RouteTableDef()
|
|||
@routes.get('/', name='index')
|
||||
async def index(request):
|
||||
"""The index page."""
|
||||
async with request.app['pool'].acquire() as conn:
|
||||
user_id = int(request.cookies.get('userid'))
|
||||
email_addresses = await conn.fetch(
|
||||
"SELECT email FROM virtual_users WHERE buckler_id = $1",
|
||||
user_id)
|
||||
return render_template('index.html', request, locals())
|
||||
|
||||
|
||||
async def init_app():
|
||||
"""Initializes the application."""
|
||||
app = web.Application(middlewares=[buckler_aiohttp.buckler_session])
|
||||
#app = web.Application()
|
||||
aiohttp_jinja2.setup(
|
||||
app,
|
||||
trim_blocks=True,
|
||||
|
@ -33,6 +38,7 @@ async def init_app():
|
|||
undefined=jinja2.StrictUndefined,
|
||||
loader=jinja2.FileSystemLoader('templates'),
|
||||
)
|
||||
app['pool'] = await asyncpg.create_pool(**config.mailserver_db)
|
||||
app.router.add_routes(routes)
|
||||
app_wrap = web.Application()
|
||||
app_wrap.add_subapp(config.url_prefix, app)
|
||||
|
|
|
@ -7,5 +7,8 @@
|
|||
</head>
|
||||
<body>
|
||||
<h1>This is a stickup!</h1>
|
||||
{% for record in email_addresses %}
|
||||
<div>Your email address is {{ record['email'] }}</div>
|
||||
{% endfor %}
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue
Block a user