diff --git a/aslite/db.py b/aslite/db.py index deb59ab..55f1916 100644 --- a/aslite/db.py +++ b/aslite/db.py @@ -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 diff --git a/serve.py b/serve.py index b1d629f..4be8555 100644 --- a/serve.py +++ b/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')) diff --git a/static/style.css b/static/style.css index 5c5da9e..8450f63 100644 --- a/static/style.css +++ b/static/style.css @@ -242,3 +242,7 @@ body { margin: 10px 40px 0 40px; font-size: 16px; } +#profilewrap { + margin: 10px 40px 0 40px; + font-size: 14px; +} \ No newline at end of file diff --git a/templates/profile.html b/templates/profile.html index 3764af0..679943e 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -4,11 +4,28 @@ {% endblock %} {% block content %} -
+
{% if user %}
Logged in user: {{ user }}
+
+
+ Email recommendations +
+ 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. +
+
+
+ + +
+
+
+
Log out