fix email with a valid default
modified: app.py
This commit is contained in:
parent
d77457ebf1
commit
0ae20f7c05
1 changed files with 22 additions and 15 deletions
37
app.py
37
app.py
|
|
@ -149,23 +149,24 @@ def get_gravatar_url(email, size=100):
|
|||
return f"https://www.gravatar.com/avatar/{hash_code}?s={size}&d=identicon"
|
||||
|
||||
|
||||
def send_email(to_email, subject, body):
|
||||
log.info("======= Email Sent =======")
|
||||
log.info(f"To: {to_email}")
|
||||
log.info(f"Subject: {subject}")
|
||||
log.info(f"Body:\n{body}")
|
||||
log.info("==========================")
|
||||
|
||||
def send_email(to_email, subject, body, from_email=None):
|
||||
if from_email is None:
|
||||
from_email = os.environ.get("PYRALOGS_FROM_EMAIL", "master@master.unturf.com")
|
||||
msg = MIMEText(body)
|
||||
msg["Subject"] = subject
|
||||
msg["From"] = "noreply@example.com"
|
||||
msg["From"] = from_email
|
||||
msg["To"] = to_email
|
||||
|
||||
try:
|
||||
s = smtplib.SMTP(smtp_host, smtp_port)
|
||||
s.sendmail("noreply@example.com", [to_email], msg.as_string())
|
||||
s.sendmail(from_email, [to_email], msg.as_string())
|
||||
s.quit()
|
||||
except Exception as e:
|
||||
log = logging.getLogger(__name__)
|
||||
log.info("======= Email Sent =======")
|
||||
log.info(f"To: {to_email}")
|
||||
log.info(f"Subject: {subject}")
|
||||
log.info(f"Body:\n{body}")
|
||||
log.info("==========================")
|
||||
log.error(f"Error sending email: {e}")
|
||||
|
||||
|
||||
|
|
@ -204,10 +205,14 @@ def get_user_namespace_role(request):
|
|||
if not user or not namespace:
|
||||
return None
|
||||
s = request.dbsession
|
||||
association = s.query(NamespaceUserAssociation).filter(
|
||||
NamespaceUserAssociation.user_id == user.id,
|
||||
NamespaceUserAssociation.namespace_id == namespace.id
|
||||
).first()
|
||||
association = (
|
||||
s.query(NamespaceUserAssociation)
|
||||
.filter(
|
||||
NamespaceUserAssociation.user_id == user.id,
|
||||
NamespaceUserAssociation.namespace_id == namespace.id,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
if association:
|
||||
return association.role
|
||||
else:
|
||||
|
|
@ -1277,7 +1282,9 @@ def main(*config, **settings):
|
|||
# Add user, namespace, user_namespace_role to requests
|
||||
config.add_request_method(get_current_user, "user", reify=True)
|
||||
config.add_request_method(get_namespace, "namespace", reify=True)
|
||||
config.add_request_method(get_user_namespace_role, 'user_namespace_role', reify=True)
|
||||
config.add_request_method(
|
||||
get_user_namespace_role, "user_namespace_role", reify=True
|
||||
)
|
||||
|
||||
# Add namespace_dbsession to requests if namespace is set
|
||||
config.add_request_method(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue