Skip to content

Commit

Permalink
update README and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
zeratax committed Dec 12, 2020
1 parent ac9c5f2 commit 7ba8f9c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 29 deletions.
1 change: 0 additions & 1 deletion .coveragerc
@@ -1,3 +1,2 @@
[run]
source = matrix_registration
omit = matrix_registration/__main__.py
11 changes: 4 additions & 7 deletions README.md
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion alembic/env.py
Expand Up @@ -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
Expand Down
26 changes: 14 additions & 12 deletions alembic/versions/140a25d5f185_create_tokens_table.py
Expand Up @@ -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',
Expand All @@ -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'")

Expand All @@ -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
2 changes: 1 addition & 1 deletion matrix_registration/__init__.py
Expand Up @@ -2,5 +2,5 @@
from . import tokens
from . import config

__version__ = '1.0.0.dev0'
__version__ = '1.0.0.dev1'
name = 'matrix_registration'
11 changes: 5 additions & 6 deletions matrix_registration/api.py
Expand Up @@ -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:
Expand All @@ -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/<token>', methods=['GET', 'PATCH'])
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = py36,py37,py38
envlist = py37,py38,p39
[testenv]
deps = coveralls
commands = coverage erase
Expand Down

0 comments on commit 7ba8f9c

Please sign in to comment.