def showRegistration(role): # For a post request, get the user information and store it into the # database, then redirect to the trainer/trainee's home page if request.method == 'POST': # Create a new user in the database newUser = User(name=request.form['name'], email=request.form['email'], password=request.form['password'], birthdate=request.form['birthdate'], image=request.form['image']) if newUser.image == "": newUser.image = "/static/images/profile.png" session.add(newUser) session.commit() # If the user is registering as a trainer if role == "trainer": # Create a new trainer in the database newTrainer = Trainer(years_experience=request.form['years'], gym=request.form['gym'], education=request.form['education'], specialization=request.form['specialization'], background=request.form['background'], user=newUser) session.add(newTrainer) session.commit() # Show a flash message to indicate registration was sucessful flash("Registration Successful") # Redirect the page to the trainer's homepage return redirect(url_for('showTrainerHomepage', trainer=newTrainer, user_id=newUser.id)) # If the user is registering as a trainee elif role == "trainee": # Create a new trainee in the database newTrainee = Trainee(goal=request.form['goal'], user=newUser) session.add(newTrainee) session.commit() flash("Registration Successful") # Redirect the page to the trainee's homepage return redirect(url_for('showTraineeHomepage', trainee=newTrainee, user_id=newUser.id)) else: # For get requests, show the registration page for the trainer if role == "trainer": return render_template('trainerregistration.html', role=role) # For get requests, show the registration page for the trainee else: return render_template('registration.html', role=role)