diff --git a/.coveragerc b/.coveragerc index b0ac4540..cb141192 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,3 +1,2 @@ [run] source = matrix_registration -omit = matrix_registration/__main__.py diff --git a/README.md b/README.md index a8d35e89..a7ed46c5 100644 --- a/README.md +++ b/README.md @@ -75,15 +75,12 @@ if you want to write your own registration page, you can take a look at the samp the html page looks for the query paramater `token` and sets the token input field to it's value. this would allow you to directly share links with the token included, e.g.: `https://homeserver.tld/register.html?token=DoubleWizardSki` -### troubleshooting +### bot -#### SQLAlchemy complains that a value isn't in a DateTime value +if you're looking for a bot to interface with matrix-registration and manage your tokens, take a look at: + +[maubot-invite](https://github.com/williamkray/maubot-invite) -Before #17 introduced SQLAlchemy support the sqlite database incorrectly stored the expire dates, to fix this you have to manually run: -```sql -update tokens set ex_date=null where ex_date='None'; -``` -on your database once, or just delete your current database. ### similar projects diff --git a/alembic/env.py b/alembic/env.py index a489f6f7..859a08ed 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -23,7 +23,8 @@ fileConfig(config.config_file_name) # load matrix-registration config and set db path for alembic -mr_config.config = mr_config.Config("config.yaml") +config_path = context.get_x_argument(as_dictionary=True).get("dbname") or "config.yaml" +mr_config.config = mr_config.Config(config_path) config.set_main_option("sqlalchemy.url", mr_config.config.db.replace("{cwd}", f"{getcwd()}/")) # add your model's MetaData object here diff --git a/alembic/versions/140a25d5f185_create_tokens_table.py b/alembic/versions/140a25d5f185_create_tokens_table.py index acf50758..8c57b3ac 100644 --- a/alembic/versions/140a25d5f185_create_tokens_table.py +++ b/alembic/versions/140a25d5f185_create_tokens_table.py @@ -22,16 +22,17 @@ def upgrade(): - op.create_table( - 'ips', - sa.Column('id', sa.Integer, primary_key=True), - sa.Column('address', sa.String(255), nullable=True) - ) - conn = op.get_bind() inspector = Inspector.from_engine(conn) tables = inspector.get_table_names() + if 'ips' not in tables: + op.create_table( + 'ips', + sa.Column('id', sa.Integer, primary_key=True), + sa.Column('address', sa.String(255), nullable=True) + ) + if 'tokens' not in tables: op.create_table( 'tokens', @@ -51,11 +52,13 @@ def upgrade(): Column('disabled', Boolean, default=False) ) - op.create_table( - 'association', db.Model.metadata, - Column('ips', String, ForeignKey('ips.address'), primary_key=True), - Column('tokens', Integer, ForeignKey('tokens.name'), primary_key=True) - ) + + if 'association' not in tables: + op.create_table( + 'association', db.Model.metadata, + Column('ips', String, ForeignKey('ips.address'), primary_key=True), + Column('tokens', Integer, ForeignKey('tokens.name'), primary_key=True) + ) op.execute("update tokens set expiration_date=null where expiration_date='None'") @@ -64,4 +67,3 @@ def upgrade(): def downgrade(): op.alter_column('tokens', 'expiration_date', new_column_name='ex_date') op.alter_column('tokens', 'max_usage', new_column_name='one_time') - pass diff --git a/matrix_registration/__init__.py b/matrix_registration/__init__.py index 359b4087..3ad4dc48 100644 --- a/matrix_registration/__init__.py +++ b/matrix_registration/__init__.py @@ -2,5 +2,5 @@ from . import tokens from . import config -__version__ = '1.0.0.dev0' +__version__ = '1.0.0.dev1' name = 'matrix_registration' diff --git a/matrix_registration/api.py b/matrix_registration/api.py index 6c92e19e..f07dbacd 100644 --- a/matrix_registration/api.py +++ b/matrix_registration/api.py @@ -243,11 +243,6 @@ def token(): return jsonify(tokens.tokens.toList()) elif request.method == 'POST': data = request.get_json() - if data: - if 'expiration' in data: - expiration_date = data['expiration'] - if 'max_usage' in data: - max_usage = data['max_usage'] try: if data: if 'expiration_date' in data and data['expiration_date'] is not None: @@ -263,7 +258,11 @@ def token(): } return make_response(jsonify(resp), 400) return jsonify(token.toDict()) - abort(400) + resp = { + 'errcode': 'MR_BAD_USER_REQUEST', + 'error': 'malformed request' + } + return make_response(jsonify(resp), 400) @api.route('/api/token/', methods=['GET', 'PATCH']) diff --git a/tox.ini b/tox.ini index 7546c05f..625741af 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py36,py37,py38 +envlist = py37,py38,p39 [testenv] deps = coveralls commands = coverage erase