add ability to store an email for a user for recommendations
This commit is contained in:
parent
970a9e24cf
commit
49995465df
@ -124,6 +124,11 @@ def get_last_active_db(flag='r', autocommit=True):
|
||||
ladb = SqliteDict(DICT_DB_FILE, tablename='last_active', flag=flag, autocommit=autocommit)
|
||||
return ladb
|
||||
|
||||
def get_email_db(flag='r', autocommit=True):
|
||||
assert flag in ['r', 'c']
|
||||
edb = SqliteDict(DICT_DB_FILE, tablename='email', flag=flag, autocommit=autocommit)
|
||||
return edb
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
"""
|
||||
our "feature store" is currently just a pickle file, may want to consider hdf5 in the future
|
||||
|
||||
23
serve.py
23
serve.py
@ -8,6 +8,7 @@ ideas:
|
||||
"""
|
||||
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
from random import shuffle
|
||||
|
||||
@ -19,7 +20,7 @@ from flask import render_template
|
||||
from flask import g # global session-level object
|
||||
from flask import session
|
||||
|
||||
from aslite.db import get_papers_db, get_metas_db, get_tags_db, get_last_active_db
|
||||
from aslite.db import get_papers_db, get_metas_db, get_tags_db, get_last_active_db, get_email_db
|
||||
from aslite.db import load_features
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
@ -291,6 +292,9 @@ def inspect():
|
||||
@app.route('/profile')
|
||||
def profile():
|
||||
context = default_context()
|
||||
with get_email_db() as edb:
|
||||
email = edb.get(g.user, '')
|
||||
context['email'] = email
|
||||
return render_template('profile.html', **context)
|
||||
|
||||
@app.route('/stats')
|
||||
@ -406,3 +410,20 @@ def login():
|
||||
def logout():
|
||||
session.pop('user', None)
|
||||
return redirect(url_for('profile'))
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# user settings and configurations
|
||||
|
||||
@app.route('/register_email', methods=['POST'])
|
||||
def register_email():
|
||||
email = request.form['email']
|
||||
|
||||
if g.user:
|
||||
# do some basic input validation
|
||||
proper_email = re.match(r'^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$', email, re.IGNORECASE)
|
||||
if email == '' or proper_email: # allow empty email, meaning no email
|
||||
# everything checks out, write to the database
|
||||
with get_email_db(flag='c') as edb:
|
||||
edb[g.user] = email
|
||||
|
||||
return redirect(url_for('profile'))
|
||||
|
||||
@ -242,3 +242,7 @@ body {
|
||||
margin: 10px 40px 0 40px;
|
||||
font-size: 16px;
|
||||
}
|
||||
#profilewrap {
|
||||
margin: 10px 40px 0 40px;
|
||||
font-size: 14px;
|
||||
}
|
||||
@ -4,11 +4,28 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="wrap">
|
||||
<div id="profilewrap">
|
||||
|
||||
{% if user %}
|
||||
<div>
|
||||
<div>Logged in user: {{ user }}</div>
|
||||
<br>
|
||||
<div>
|
||||
<b>Email recommendations</b>
|
||||
<div>
|
||||
Users can receive regular new paper recommendations via email based on their tags.
|
||||
(This is still being developed, may not be running or may be unreliable.)
|
||||
Register your email address below to receive these recommendations.
|
||||
To stop the recommendations simply delete your email address.
|
||||
</div>
|
||||
<div>
|
||||
<form action="{{ url_for('register_email') }}" method="post">
|
||||
<input type="text" name="email" placeholder="Email address" value="{{ email }}">
|
||||
<input type="submit" value="Set">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<div>
|
||||
<a href="{{ url_for('logout') }}">Log out</a>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user