ソースを参照

Merge pull request #37 from simple-login/disable-suffix-option

Disable suffix option
Son Nguyen Kim 5 年 前
コミット
204ccd34c9

+ 4 - 0
.env.example

@@ -29,6 +29,10 @@ EMAIL_SERVERS_WITH_PRIORITY=[(10, "email.hostname.")]
 # these emails are ignored when computing stats
 # IGNORED_EMAILS = ["my_email@domain.com"]
 
+# By default, new aliases must end with ".{random_word}". This is to avoid a person taking all "nice" aliases.
+# this option doesn't make sense in self-hosted. Set this variable to disable this option.
+# DISABLE_ALIAS_SUFFIX=1
+
 # the DKIM private key used to compute DKIM-Signature
 DKIM_PRIVATE_KEY_PATH=local_data/dkim.key
 

+ 4 - 0
README.md

@@ -291,6 +291,7 @@ EMAIL_SERVERS_WITH_PRIORITY=[(10, "app.mydomain.com.")]
 DKIM_PRIVATE_KEY_PATH=/dkim.key
 DKIM_PUBLIC_KEY_PATH=/dkim.pub.key
 DB_URI=postgresql://myuser:mypassword@sl-db:5432/simplelogin
+DISABLE_ALIAS_SUFFIX=1
 ```
 
 
@@ -378,6 +379,9 @@ At this step, you should also setup the SSL for Nginx. [Certbot](https://certbot
 
 If all of the above steps are successful, open http://app.mydomain.com/ and create your first account!
 
+By default, new accounts are not premium so don't have unlimited alias. To make your account premium, 
+please go to the database, table "users" and set "lifetime" column to "1" or "TRUE". 
+
 ## Contributing
 
 All work on SimpleLogin happens directly on GitHub.

+ 3 - 0
app/config.py

@@ -58,6 +58,9 @@ if os.environ.get("IGNORED_EMAILS"):
 else:
     IGNORED_EMAILS = []
 
+# disable the alias suffix, i.e. the ".random_word" part
+DISABLE_ALIAS_SUFFIX = "DISABLE_ALIAS_SUFFIX" in os.environ
+
 DKIM_PRIVATE_KEY_PATH = get_abs_path(os.environ["DKIM_PRIVATE_KEY_PATH"])
 DKIM_PUBLIC_KEY_PATH = get_abs_path(os.environ["DKIM_PUBLIC_KEY_PATH"])
 DKIM_SELECTOR = b"dkim"

+ 1 - 1
app/dashboard/templates/dashboard/custom_alias.html

@@ -35,7 +35,7 @@
           <div class="col-sm-6 align-self-center" style="height:1.5rem">
             <input type="hidden" name="email-suffix" value="{{ email_suffix }}">
             <h4>
-              .{{ email_suffix }}@{{ EMAIL_DOMAIN }}
+              {{ email_suffix }}@{{ EMAIL_DOMAIN }}
             </h4>
           </div>
         </div>

+ 12 - 10
app/dashboard/views/custom_alias.py

@@ -1,7 +1,7 @@
 from flask import render_template, redirect, url_for, flash, request, session
 from flask_login import login_required, current_user
 
-from app.config import EMAIL_DOMAIN, HIGHLIGHT_GEN_EMAIL_ID
+from app.config import EMAIL_DOMAIN, HIGHLIGHT_GEN_EMAIL_ID, DISABLE_ALIAS_SUFFIX
 from app.dashboard.base import dashboard_bp
 from app.extensions import db
 from app.log import LOG
@@ -27,18 +27,20 @@ def custom_alias():
             email_prefix = convert_to_id(email_prefix)
             email_suffix = request.form.get("email-suffix")
 
-            # verify email_suffix
-            if not word_exist(email_suffix):
-                flash(
-                    "nice try :). The suffix is there so no one can take all the *nice* aliases though",
-                    "warning",
-                )
-                return redirect(url_for("dashboard.custom_alias"))
+            # verify email_suffix: do not verify when DISABLE_ALIAS_SUFFIX is set
+            if not DISABLE_ALIAS_SUFFIX:
+                # email suffix must be in the format ".{word}"
+                if email_suffix[0] != "." or not word_exist(email_suffix[1:]):
+                    flash(
+                        "nice try :). The suffix is there so no one can take all the *nice* aliases though",
+                        "warning",
+                    )
+                    return redirect(url_for("dashboard.custom_alias"))
 
             if not email_prefix:
                 error = "alias prefix cannot be empty"
             else:
-                full_email = f"{email_prefix}.{email_suffix}@{EMAIL_DOMAIN}"
+                full_email = f"{email_prefix}{email_suffix}@{EMAIL_DOMAIN}"
                 # check if email already exists
                 if GenEmail.get_by(email=full_email) or DeletedAlias.get_by(
                     email=full_email
@@ -95,7 +97,7 @@ def custom_alias():
                 session[HIGHLIGHT_GEN_EMAIL_ID] = gen_email.id
                 return redirect(url_for("dashboard.index"))
 
-    email_suffix = random_word()
+    email_suffix = "" if DISABLE_ALIAS_SUFFIX else "." + random_word()
     return render_template(
         "dashboard/custom_alias.html",
         error=error,