def login(): # If the user is already logged in, move them to their game instead if current_user.is_authenticated: return redirect(url_for('main.game', group=current_user.group)) # Instance all the forms joinForm = JoinForm() joinFormPOC = JoinFormPOC() createForm = CreateForm() # If they have joined if joinForm.submit1.data and joinForm.validate(): user = User(group=joinForm.group.data, permission='1') db.session.add(user) db.session.commit() login_user(user) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('main.game', group=current_user.group) return redirect(next_page) # If they have joined as host if joinFormPOC.submit10.data and joinFormPOC.validate(): user = User(group=joinForm.group.data, permission='2') db.session.add(user) db.session.commit() login_user(user) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('main.game', group=current_user.group) return redirect(next_page) # If they have created a game if createForm.submit2.data and createForm.validate(): user = User(group=createForm.group.data, permission='2') db.session.add(user) db.session.commit() encounters = Encounter.query.all() game = Game(group=createForm.group.data, compEnc='1', mode='GAME', curEnc='0') game.generateFrequency() game.applyCallsign(CALLSIGN_LIST[randint(0, len(CALLSIGN_LIST) - 1)] + ' ' + str(randint(1, 9))) game.location = LOCATION_LIST[randint(0, len(LOCATION_LIST) - 1)] game.setGoalEnc(20) game.setQRandUpper(len(encounters) - 1) game.setMRandUpper(19) game.selectMarch() game.updateTime() db.session.add(game) db.session.commit() login_user(user) next_page = request.args.get('next') if not next_page or url_parse(next_page).netloc != '': next_page = url_for('main.game', group=current_user.group) return redirect(next_page) prompt = Prompt.query.all()[0] return render_template(['joinCreate.html', 'base.html'], prompt=prompt, joinForm=joinForm, createForm=createForm, joinFormPOC=joinFormPOC)