Refactor lexicon.join handler
This commit is contained in:
parent
e311202700
commit
c09851333e
|
@ -32,20 +32,24 @@ def join(name):
|
||||||
|
|
||||||
form = LexiconJoinForm()
|
form = LexiconJoinForm()
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if not form.validate_on_submit():
|
||||||
# Gate on password if one is required
|
# GET or POST with invalid form data
|
||||||
|
return render_template('lexicon.join.jinja', form=form)
|
||||||
|
|
||||||
|
# POST with valid data
|
||||||
|
# If the game is passworded, check password
|
||||||
if (g.lexicon.cfg.join.password
|
if (g.lexicon.cfg.join.password
|
||||||
and form.password.data != g.lexicon.cfg.join.password):
|
and form.password.data != g.lexicon.cfg.join.password):
|
||||||
return redirect(url_for("lexicon.join", name=name))
|
# Bad creds, try again
|
||||||
# Gate on join validity
|
flash('Incorrect password')
|
||||||
|
return redirect(url_for('lexicon.join', name=name))
|
||||||
|
# If the password was correct, check if the user can join
|
||||||
if player_can_join_lexicon(current_user, g.lexicon, form.password.data):
|
if player_can_join_lexicon(current_user, g.lexicon, form.password.data):
|
||||||
add_player_to_lexicon(current_user, g.lexicon)
|
add_player_to_lexicon(current_user, g.lexicon)
|
||||||
return redirect(url_for('session.session', name=name))
|
return redirect(url_for('session.session', name=name))
|
||||||
else:
|
else:
|
||||||
flash("Could not join game")
|
flash('Could not join game')
|
||||||
return redirect(url_for("home.home", name=name))
|
return redirect(url_for('home.home', name=name))
|
||||||
|
|
||||||
return render_template('lexicon.join.jinja', form=form)
|
|
||||||
|
|
||||||
|
|
||||||
@bp_lexicon.route('/contents/', methods=['GET'])
|
@bp_lexicon.route('/contents/', methods=['GET'])
|
||||||
|
|
Loading…
Reference in New Issue