mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-09 17:13:45 +01:00
parent
2abcd8ee47
commit
ef0a32524e
@ -31,12 +31,13 @@ migrate = Migrate(app, db)
|
||||
|
||||
|
||||
class UserRank(enum.Enum):
|
||||
NOT_JOINED = 0
|
||||
NEW_MEMBER = 1
|
||||
MEMBER = 2
|
||||
EDITOR = 3
|
||||
MODERATOR = 4
|
||||
ADMIN = 5
|
||||
BANNED = 0
|
||||
NOT_JOINED = 1
|
||||
NEW_MEMBER = 2
|
||||
MEMBER = 3
|
||||
EDITOR = 4
|
||||
MODERATOR = 5
|
||||
ADMIN = 6
|
||||
|
||||
def atLeast(self, min):
|
||||
return self.value >= min.value
|
||||
|
@ -62,6 +62,10 @@ def _do_login_user(user, remember_me=False):
|
||||
if not user:
|
||||
return False
|
||||
|
||||
if user.rank == UserRank.BANNED:
|
||||
flash("You have been banned.", "error")
|
||||
return False
|
||||
|
||||
user.active = True
|
||||
if not user.rank.atLeast(UserRank.NEW_MEMBER):
|
||||
user.rank = UserRank.NEW_MEMBER
|
||||
|
@ -51,3 +51,10 @@ def flatpage(path):
|
||||
page = pages.get_or_404(path)
|
||||
template = page.meta.get('template', 'flatpage.html')
|
||||
return render_template(template, page=page)
|
||||
|
||||
@app.before_request
|
||||
def do_something_whenever_a_request_comes_in():
|
||||
if current_user.is_authenticated and current_user.rank == UserRank.BANNED:
|
||||
flash("You have been banned.", "error")
|
||||
logout_user()
|
||||
return redirect(url_for('user.login'))
|
||||
|
29
migrations/versions/ea5a023711e0_.py
Normal file
29
migrations/versions/ea5a023711e0_.py
Normal file
@ -0,0 +1,29 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: ea5a023711e0
|
||||
Revises: fa12fadbdb40
|
||||
Create Date: 2018-05-26 01:55:09.745881
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'ea5a023711e0'
|
||||
down_revision = 'fa12fadbdb40'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
conn = op.get_bind()
|
||||
conn.execute("ALTER TYPE userrank ADD VALUE 'BANNED'")
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in New Issue
Block a user