Ver código fonte

Added an email settings test button and functionality.

Adam Day 2 anos atrás
pai
commit
9059f02448
2 arquivos alterados com 52 adições e 1 exclusões
  1. 26 0
      app.py
  2. 26 1
      templates/settings.html

+ 26 - 0
app.py

@@ -1114,6 +1114,32 @@ def system_log():
     return render_template('system_log.html', context=context)
 
 
+@app.route('/admin/settings/test/email', methods=['POST'])
+def test_email():
+    if not requires_auth():
+        return redirect(url_for('login'))
+
+    # Get form data
+    email = request.form.get('email')
+
+    # Get email settings from DB
+    smtp_host_setting = Settings.get(Settings.name == 'SMTP Host')
+    smtp_port_setting = Settings.get(Settings.name == 'SMTP Port')
+    smtp_username_setting = Settings.get(Settings.name == 'SMTP Username')
+    smtp_password_setting = Settings.get(Settings.name == 'SMTP Password')
+
+    smtp_host = smtp_host_setting.value
+    smtp_port = smtp_port_setting.value
+    smtp_username = smtp_username_setting.value
+    smtp_password = smtp_password_setting.value
+
+    emailer = Emailer(smtp_host, smtp_port, smtp_username, smtp_password)
+    emailer.send_email(email, 'ILS Password Reset Test',
+                       'This is a test email to verify that the email settings are correct.')
+
+    return redirect(request.referrer)
+
+
 @app.route('/admin/system/scheduler/enable')
 def enable_scheduler():
 

+ 26 - 1
templates/settings.html

@@ -22,7 +22,9 @@
   The scheduler is currently disabled. <a href="{{ url_for('enable_scheduler') }}">Click here to enable the scheduler.</a>
 </div>
 {% endif %}
-
+<div class="text-end">
+    <a href="#!" data-bs-toggle="modal" data-bs-target="#email-test" class="btn btn-secondary ms-1">Send Test Email</a>
+</div>
 <div class="row">
     <div class="col">
         <table class="table table-flush">
@@ -96,4 +98,27 @@
 </div>
 {% endfor %}
 
+<div class="modal fade" id="email-test" tabindex="-1">
+    <div class="modal-dialog modal-dialog-centered">
+        <div class="modal-content">
+            <form action="{{ url_for('test_email') }}" method="post">
+                <div class="modal-header bg-light">
+                    <h1 class="modal-title fs-5">Test Email Settings</h1>
+                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
+                </div>
+                <div class="modal-body">
+                    <div class="mb-3">
+                        <label for="value" class="form-label">Email Address to send to</label>
+                        <input type="text" class="form-control" id="email" name="email" value="" required>
+                    </div>
+                </div>
+                <div class="modal-footer bg-light">
+                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
+                    <input type="submit" class="btn btn-primary" value="Save">
+                </div>
+            </form>
+        </div>
+    </div>
+</div>
+
 {% endblock %}