def signup(): recaptcha = RecaptchaField() if request.method == "POST": username = request.form["username"] password = generate_password_hash(request.form["password"]) confirm_password = request.form["confirm-password"] about = request.form["about"] email = request.form["email"] letters = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890" letters = list(letters) if username == "": return render_template("signup.html", error="*You did not enter any username.", confirm=confirm_password, username=username, password=password, about=about) elif len(username.split(" ")) > 1: return render_template( "signup.html", error="*Your username cannot contain any spaces.", confirm=confirm_password, username=username, password=password, about=about, recaptcha=recaptcha) elif compare_digest(confirm_password, password): return render_template("signup.html", error="*Your passwords do not match.", confirm=confirm_password, username=username, password=password, about=about, recaptcha=recaptcha) elif compare_digest(password, ""): return render_template("signup.html", error="*You did not enter a password", confirm=confirm_password, username=username, password=password, about=about, recaptcha=recaptcha) elif bool(User.query.filter_by(username=username).first()): return render_template("signup.html", error="*The username is already taken.", confirm=confirm_password, username=username, password=password, about=about, recaptcha=recaptcha) elif username.lower in rude_words: return render_template("signup.html", error="*Rude words are not allowed.", confirm=confirm_password, username=username, password=password, about=about, recaptcha=recaptcha) else: for char in username: if char not in letters: return render_template( "signup.html", error= "*Your username can only contain letters and numbers. ", confirm=confirm_password, username=username, password=password, about=about, recaptcha=recaptcha) i = 0 for char in username: if char in "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM": i = i + 1 if i < 4: return render_template( "signup.html", error="*Your username must contain at least 4 letters.", confirm=confirm_password, username=username, password=password, about=about, recaptcha=recaptcha) for user in User.query.all(): if user.username.lower() == username.lower(): return render_template( "signup.html", error="*The username is already taken.", confirm=confirm_password, username=username, password=password, about=about, recaptcha=recaptcha) user = User() user.username = username user.top_progress = "" user.password = generate_password_hash(password) user.admin = 0 user.email = email db.session.add(user) db.session.commit() login_user(User.query.filter_by(password=password, username=username).first(), remember=True) user_id = current_user.id profile = User() profile.user_id = user_id profile.about = about db.session.add(profile) db.session.commit() return redirect(url_for('home')) else: return render_template("signup.html", error="", username="", password="", confirm="", about="", recaptcha=recaptcha)