highlight newly created gen-email

This commit is contained in:
Son NK 2019-08-30 22:42:06 +02:00
parent 3e0bc27bad
commit 62c3b4cd02
5 changed files with 31 additions and 7 deletions

View File

@ -86,3 +86,6 @@ FACEBOOK_CLIENT_SECRET = os.environ["FACEBOOK_CLIENT_SECRET"]
# in seconds # in seconds
AVATAR_URL_EXPIRATION = 3600 * 24 * 7 # 1h*24h/d*7d=1week AVATAR_URL_EXPIRATION = 3600 * 24 * 7 # 1h*24h/d*7d=1week
# session key
HIGHLIGHT_GEN_EMAIL_ID = "highlight_gen_email_id"

View File

@ -50,7 +50,7 @@
</thead> </thead>
<tbody> <tbody>
{% for gen_email in gen_emails %} {% for gen_email in gen_emails %}
<tr> <tr {% if gen_email.id == highlight_gen_email_id %} class="highlight-row" {% endif %}>
<td> <td>
<div> <div>
<a href="mailto: {{ gen_email.email }}">{{ gen_email.email }}</a> <a href="mailto: {{ gen_email.email }}">{{ gen_email.email }}</a>
@ -77,7 +77,7 @@
{% if gen_email.enabled %} {% if gen_email.enabled %}
<button class="btn btn-secondary btn-sm" <button class="btn btn-secondary btn-sm"
{% if loop.index ==1 %} {% if loop.index ==1 %}
data-intro="By triggering the test email, data-intro="By triggering the test email,
SimpleLogin server will send an email to this alias SimpleLogin server will send an email to this alias
and this email should arrive to your personal email inbox 🚀" and this email should arrive to your personal email inbox 🚀"
{% endif %} {% endif %}

View File

@ -1,9 +1,9 @@
from flask import render_template, redirect, url_for, flash, request from flask import render_template, redirect, url_for, flash, request, session
from flask_login import login_required, current_user from flask_login import login_required, current_user
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from wtforms import StringField, validators from wtforms import StringField, validators
from app.config import EMAIL_DOMAIN from app.config import EMAIL_DOMAIN, HIGHLIGHT_GEN_EMAIL_ID
from app.dashboard.base import dashboard_bp from app.dashboard.base import dashboard_bp
from app.extensions import db from app.extensions import db
from app.log import LOG from app.log import LOG
@ -43,10 +43,13 @@ def custom_alias():
else: else:
# create the new alias # create the new alias
LOG.d("create custom alias %s for user %s", full_email, current_user) LOG.d("create custom alias %s for user %s", full_email, current_user)
GenEmail.create(email=full_email, user_id=current_user.id, custom=True) gen_email = GenEmail.create(
email=full_email, user_id=current_user.id, custom=True
)
db.session.commit() db.session.commit()
flash(f"Email alias {full_email} has been created", "success") flash(f"Email alias {full_email} has been created", "success")
session[HIGHLIGHT_GEN_EMAIL_ID] = gen_email.id
return redirect(url_for("dashboard.index")) return redirect(url_for("dashboard.index"))

View File

@ -1,8 +1,9 @@
from flask import render_template, request, redirect, url_for, flash from flask import render_template, request, redirect, url_for, flash, session
from flask_login import login_required, current_user from flask_login import login_required, current_user
from sqlalchemy.orm import joinedload from sqlalchemy.orm import joinedload
from app import email_utils from app import email_utils
from app.config import HIGHLIGHT_GEN_EMAIL_ID
from app.dashboard.base import dashboard_bp from app.dashboard.base import dashboard_bp
from app.extensions import db from app.extensions import db
from app.log import LOG from app.log import LOG
@ -12,6 +13,13 @@ from app.models import GenEmail, ClientUser
@dashboard_bp.route("/", methods=["GET", "POST"]) @dashboard_bp.route("/", methods=["GET", "POST"])
@login_required @login_required
def index(): def index():
# after creating a gen email, it's helpful to highlight it
highlight_gen_email_id = session.get(HIGHLIGHT_GEN_EMAIL_ID)
# reset as it should not persist
if highlight_gen_email_id:
del session[HIGHLIGHT_GEN_EMAIL_ID]
# User generates a new email # User generates a new email
if request.method == "POST": if request.method == "POST":
if request.form.get("form-name") == "trigger-email": if request.form.get("form-name") == "trigger-email":
@ -44,6 +52,7 @@ SimpleLogin team.
LOG.d("generate new email %s for user %s", gen_email, current_user) LOG.d("generate new email %s for user %s", gen_email, current_user)
flash(f"Email {gen_email.email} has been created", "success") flash(f"Email {gen_email.email} has been created", "success")
session[HIGHLIGHT_GEN_EMAIL_ID] = gen_email.id
else: else:
flash(f"You need to upgrade your plan to create new email.", "warning") flash(f"You need to upgrade your plan to create new email.", "warning")
@ -95,5 +104,8 @@ SimpleLogin team.
) )
return render_template( return render_template(
"dashboard/index.html", client_users=client_users, gen_emails=gen_emails "dashboard/index.html",
client_users=client_users,
gen_emails=gen_emails,
highlight_gen_email_id=highlight_gen_email_id,
) )

View File

@ -40,4 +40,10 @@
border-radius: 50%; border-radius: 50%;
margin-top: 10px; margin-top: 10px;
}
/* highlighted table row */
.highlight-row {
background-color: #eee;
font-weight: bolder;
} }