Fix closed registrations logic

This commit is contained in:
pluja 2020-09-04 17:07:44 +02:00
parent e6e6d0bd7e
commit e66729485e

View File

@ -32,7 +32,6 @@ config = json.load(open('yotter-config.json'))
########################## ##########################
NITTERINSTANCE = config['nitterInstance'] # Must be https://.../ NITTERINSTANCE = config['nitterInstance'] # Must be https://.../
YOUTUBERSS = "https://www.youtube.com/feeds/videos.xml?channel_id=" YOUTUBERSS = "https://www.youtube.com/feeds/videos.xml?channel_id="
REGISTRATIONS = config['registrations']
########################## ##########################
#### Global variables #### #### Global variables ####
@ -487,12 +486,12 @@ def allowed_file(filename):
@app.route('/register', methods=['GET', 'POST']) @app.route('/register', methods=['GET', 'POST'])
def register(): def register():
global REGISTRATIONS
count = db.session.query(User).count() count = db.session.query(User).count()
if current_user.is_authenticated: if current_user.is_authenticated:
return redirect(url_for('index')) return redirect(url_for('index'))
if count >= config['maxInstanceUsers']: REGISTRATIONS = True
if count >= config['maxInstanceUsers'] or config['maxInstanceUsers'] == 0:
REGISTRATIONS = False REGISTRATIONS = False
form = RegistrationForm() form = RegistrationForm()
@ -501,7 +500,6 @@ def register():
flash("This username is taken! Try with another.") flash("This username is taken! Try with another.")
return redirect(request.referrer) return redirect(request.referrer)
user = User(username=form.username.data) user = User(username=form.username.data)
user.set_password(form.password.data) user.set_password(form.password.data)
db.session.add(user) db.session.add(user)