def register_process():
"""Get information from registration form."""
username = request.form.get("username")
email = request.form.get("email")
password = request.form.get("password")
systems = request.form.getlist("systems")
account_created = datetime.now()
existing_username = User.query.filter_by(username=username).first()
existing_email = User.query.filter_by(email=email).first()
# check if the username is in use
if existing_username is None and existing_email is None:
#check if the email is in use
new_user = User(username=username, email=email, password=password,
account_created=account_created)
db.session.add(new_user)
db.session.commit()
get_user_rating(games)
for system in systems:
# add each system to the database for the specific user
system_id = db.session.query(System.system_id).filter(System.name==system).first()
new_user_system = UserSystem(user_id=new_user.user_id, system_id=system_id)
db.session.add(new_user_system)
db.session.commit()
flash("Successfully registered " + username + "!")
return redirect("/")
else:
flash("Username or email already in use")
# TODO probably handle this in AJAX on the form and be more specific
# as to whether it was the username or email that failed
return redirect("/")
评论列表
文章目录