diff --git a/cps/admin.py b/cps/admin.py index d7eee06c..3bb747db 100644 --- a/cps/admin.py +++ b/cps/admin.py @@ -190,10 +190,10 @@ def update_view_configuration(): return view_configuration() -@admi.route("/ajax/editdomain", methods=['POST']) +@admi.route("/ajax/editdomain/", methods=['POST']) @login_required @admin_required -def edit_domain(): +def edit_domain(allow): # POST /post # name: 'username', //name of field (column in db) # pk: 1 //primary key (record id) @@ -206,14 +206,14 @@ def edit_domain(): return "" -@admi.route("/ajax/adddomain", methods=['POST']) +@admi.route("/ajax/adddomain/", methods=['POST']) @login_required @admin_required -def add_domain(): +def add_domain(allow): domain_name = request.form.to_dict()['domainname'].replace('*', '%').replace('?', '_').lower() - check = ub.session.query(ub.Registration).filter(ub.Registration.domain == domain_name).first() + check = ub.session.query(ub.Registration).filter(ub.Registration.domain == domain_name).filter(ub.Registration.allow == allow).first() if not check: - new_domain = ub.Registration(domain=domain_name) + new_domain = ub.Registration(domain=domain_name, allow=allow) ub.session.add(new_domain) ub.session.commit() return "" @@ -227,18 +227,18 @@ def delete_domain(): ub.session.query(ub.Registration).filter(ub.Registration.id == domain_id).delete() ub.session.commit() # If last domain was deleted, add all domains by default - if not ub.session.query(ub.Registration).count(): - new_domain = ub.Registration(domain="%.%") + if not ub.session.query(ub.Registration).filter(ub.Registration.allow==1).count(): + new_domain = ub.Registration(domain="%.%",allow=1) ub.session.add(new_domain) ub.session.commit() return "" -@admi.route("/ajax/domainlist") +@admi.route("/ajax/domainlist/") @login_required @admin_required -def list_domain(): - answer = ub.session.query(ub.Registration).all() +def list_domain(allow): + answer = ub.session.query(ub.Registration).filter(ub.Registration.allow == allow).all() json_dumps = json.dumps([{"domain": r.domain.replace('%', '*').replace('_', '?'), "id": r.id} for r in answer]) js = json.dumps(json_dumps.replace('"', "'")).lstrip('"').strip('"') response = make_response(js.replace("'", '"')) @@ -605,6 +605,7 @@ def edit_user(user_id): else: flash(_(u"Found an existing account for this e-mail address."), category="error") return render_title_template("user_edit.html", translations=translations, languages=languages, + mail_configured = config.get_mail_server_configured(), new_user=0, content=content, downloads=downloads, registered_oauth=oauth_check, title=_(u"Edit User %(nick)s", nick=content.nickname), page="edituser") if "nickname" in to_save and to_save["nickname"] != content.nickname: @@ -616,11 +617,11 @@ def edit_user(user_id): return render_title_template("user_edit.html", translations=translations, languages=languages, + mail_configured=config.get_mail_server_configured(), new_user=0, content=content, downloads=downloads, registered_oauth=oauth_check, - title=_(u"Edit User %(nick)s", - nick=content.nickname), + title=_(u"Edit User %(nick)s", nick=content.nickname), page="edituser") if "kindle_mail" in to_save and to_save["kindle_mail"] != content.kindle_mail: @@ -633,6 +634,7 @@ def edit_user(user_id): flash(_(u"An unknown error occured."), category="error") return render_title_template("user_edit.html", translations=translations, languages=languages, new_user=0, content=content, downloads=downloads, registered_oauth=oauth_check, + mail_configured=config.get_mail_server_configured(), title=_(u"Edit User %(nick)s", nick=content.nickname), page="edituser") diff --git a/cps/helper.py b/cps/helper.py index d879a7fd..ff6fbb98 100644 --- a/cps/helper.py +++ b/cps/helper.py @@ -701,9 +701,13 @@ def speaking_language(languages=None): # from https://code.luasoftware.com/tutorials/flask/execute-raw-sql-in-flask-sqlalchemy/ def check_valid_domain(domain_text): domain_text = domain_text.split('@', 1)[-1].lower() - sql = "SELECT * FROM registration WHERE :domain LIKE domain;" + sql = "SELECT * FROM registration WHERE (:domain LIKE domain and allow = 1);" result = ub.session.query(ub.Registration).from_statement(text(sql)).params(domain=domain_text).all() - return len(result) + if not len(result): + return False + sql = "SELECT * FROM registration WHERE (:domain LIKE domain and allow = 0);" + result = ub.session.query(ub.Registration).from_statement(text(sql)).params(domain=domain_text).all() + return not len(result) # Orders all Authors in the list according to authors sort diff --git a/cps/static/js/table.js b/cps/static/js/table.js index 47daa6da..12c07102 100644 --- a/cps/static/js/table.js +++ b/cps/static/js/table.js @@ -19,21 +19,41 @@ $(function() { - $("#domain_submit").click(function(event) { + $("#domain_allow_submit").click(function(event) { event.preventDefault(); - $("#domain_add").ajaxForm(); + $("#domain_add_allow").ajaxForm(); $(this).closest("form").submit(); $.ajax ({ method:"get", - url: window.location.pathname + "/../../ajax/domainlist", + url: window.location.pathname + "/../../ajax/domainlist/1", async: true, timeout: 900, success:function(data) { - $("#domain-table").bootstrapTable("load", data); + $("#domain-allow-table").bootstrapTable("load", data); } }); }); - $("#domain-table").bootstrapTable({ + $("#domain-allow-table").bootstrapTable({ + formatNoMatches: function () { + return ""; + }, + striped: false + }); + $("#domain_deny_submit").click(function(event) { + event.preventDefault(); + $("#domain_add_deny").ajaxForm(); + $(this).closest("form").submit(); + $.ajax ({ + method:"get", + url: window.location.pathname + "/../../ajax/domainlist/0", + async: true, + timeout: 900, + success:function(data) { + $("#domain-deny-table").bootstrapTable("load", data); + } + }); + }); + $("#domain-deny-table").bootstrapTable({ formatNoMatches: function () { return ""; }, @@ -50,14 +70,22 @@ $(function() { $("#DeleteDomain").modal("hide"); $.ajax({ method:"get", - url: window.location.pathname + "/../../ajax/domainlist", + url: window.location.pathname + "/../../ajax/domainlist/1", async: true, timeout: 900, success:function(data) { - $("#domain-table").bootstrapTable("load", data); + $("#domain-allow-table").bootstrapTable("load", data); + } + }); + $.ajax({ + method:"get", + url: window.location.pathname + "/../../ajax/domainlist/0", + async: true, + timeout: 900, + success:function(data) { + $("#domain-deny-table").bootstrapTable("load", data); } }); - }); //triggered when modal is about to be shown $("#DeleteDomain").on("show.bs.modal", function(e) { diff --git a/cps/templates/email_edit.html b/cps/templates/email_edit.html index bb5c60a0..d1b6e893 100644 --- a/cps/templates/email_edit.html +++ b/cps/templates/email_edit.html @@ -41,22 +41,40 @@ {% if g.allow_registration %}

{{_('Allowed domains for registering')}}

- + +
+ + +
+ + +
+ + + + + + + +
+

{{_('Denied domains for registering')}}

+ - - + +
-
+
- - + +
- +
+ {% endif %} {% endblock %} diff --git a/cps/templates/user_edit.html b/cps/templates/user_edit.html index 31480e3c..cbd4f2e8 100644 --- a/cps/templates/user_edit.html +++ b/cps/templates/user_edit.html @@ -14,15 +14,14 @@ {% if ( g.user and g.user.role_passwd() or g.user.role_admin() ) and not content.role_anonymous() %} - {% if g.user and g.user.role_admin() and g.allow_registration and not new_user and not profile %} + {% if g.user and g.user.role_admin() and not new_user and not profile and ( mail_configured and content.email if content.email != None %} - {% else %} + {% endif %}
{% endif %} - {% endif %}
diff --git a/cps/ub.py b/cps/ub.py index b262e0eb..85ed1127 100644 --- a/cps/ub.py +++ b/cps/ub.py @@ -297,6 +297,7 @@ class Registration(Base): id = Column(Integer, primary_key=True) domain = Column(String) + allow = Column(Integer) def __repr__(self): return u"".format(self.domain) @@ -332,24 +333,32 @@ def migrate_Database(session): if not engine.dialect.has_table(engine.connect(), "registration"): ReadBook.__table__.create(bind=engine) conn = engine.connect() - conn.execute("insert into registration (domain) values('%.%')") + conn.execute("insert into registration (domain, allow) values('%.%',1)") + session.commit() + try: + session.query(exists().where(Registration.allow)).scalar() + session.commit() + except exc.OperationalError: # Database is not compatible, some columns are missing + conn = engine.connect() + conn.execute("ALTER TABLE registration ADD column 'allow' INTEGER") + conn.execute("update registration set 'allow' = 1") session.commit() # Handle table exists, but no content cnt = session.query(Registration).count() if not cnt: conn = engine.connect() - conn.execute("insert into registration (domain) values('%.%')") + conn.execute("insert into registration (domain, allow) values('%.%',1)") session.commit() try: session.query(exists().where(BookShelf.order)).scalar() - except exc.OperationalError: # Database is not compatible, some rows are missing + except exc.OperationalError: # Database is not compatible, some columns are missing conn = engine.connect() conn.execute("ALTER TABLE book_shelf_link ADD column 'order' INTEGER DEFAULT 1") session.commit() try: create = False session.query(exists().where(User.sidebar_view)).scalar() - except exc.OperationalError: # Database is not compatible, some rows are missing + except exc.OperationalError: # Database is not compatible, some columns are missing conn = engine.connect() conn.execute("ALTER TABLE user ADD column `sidebar_view` Integer DEFAULT 1") session.commit() diff --git a/test/Calibre-Web TestSummary.html b/test/Calibre-Web TestSummary.html index f8624193..51db76cb 100644 --- a/test/Calibre-Web TestSummary.html +++ b/test/Calibre-Web TestSummary.html @@ -30,15 +30,15 @@
-

Start Time: 2019-12-28 15:05:02.169394

+

Start Time: 2019-12-29 09:32:57.266265

-

Stop Time: 2019-12-28 15:36:05.637251

+

Stop Time: 2019-12-29 10:08:09.098085

-

Duration: 0:31:03.467857

+

Duration: 0:35:11.831820

@@ -230,11 +230,11 @@ PASS - + test_ebook_convert.test_ebook_convert 11 - 10 - 1 + 11 + 0 0 0 @@ -276,15 +276,15 @@
pt3.4: User: name@host.com, Password: 10234
-Receiving message from: ('127.0.0.1', 35724)
+Receiving message from: ('127.0.0.1', 44766)
 Message addressed from: name@host.com
 Message addressed to: a5@b.com
-Message length        : 1
+Message length        : 42
 User: name@host.com, Password: 10234
-Receiving message from: ('127.0.0.1', 35726)
+Receiving message from: ('127.0.0.1', 44768)
 Message addressed from: name@host.com
 Message addressed to: a1@b.com
-Message length        : 2
+Message length        : 16679
 User: name@host.com, Password: 1234
@@ -309,10 +309,10 @@ User: name@host.com, Password: 1234
pt3.5: User: name@host.com, Password: 10234
-Receiving message from: ('127.0.0.1', 35730)
+Receiving message from: ('127.0.0.1', 44772)
 Message addressed from: name@host.com
 Message addressed to: a5@b.com
-Message length        : 1
+Message length        : 42
 User: name@host.com, Password: 1234
@@ -355,45 +355,42 @@ User: name@host.com, Password: 1234
pt3.9: User: name@host.com, Password: 10234
-Receiving message from: ('127.0.0.1', 35734)
+Receiving message from: ('127.0.0.1', 44776)
 Message addressed from: name@host.com
 Message addressed to: a1@b.com
-Message length        : 2
+Message length : 22311
- +
test_email_only
- FAIL + PASS
-
pt6.1: User: name@host.com, Password: 10234
-Receiving message from: ('127.0.0.1', 41832)
+Receiving message from: ('127.0.0.1', 47328)
 Message addressed from: name@host.com
 Message addressed to: a1@b.com
-Message length        : 2
+Message length : 22013
@@ -1303,121 +1300,111 @@ Message length : 2 PASS - + test_email_ssl.test_SSL 4 - 0 - 4 + 2 0 0 + 2 Detail - +
test_SSL_None_setup_error
- FAIL + SKIP
-