def register_with_oauth_authorized(): ''' This endpoint should be called after authorizing with oauth, by the user. ''' email = request.form.get('email') username = request.form.get('username') provider = request.form.get('provider') remote_user = request.form.get('remote_user') good = True if check_username_for_registration(username): good = False if check_email_for_registration(email): good = False if good: password = binascii.b2a_hex(os.urandom(99)) user = User(username, email, password) user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8") db.add(user) db.flush() # to get an ID. auth = UserAuth(user.id, remote_user, provider) db.add(auth) db.commit() # Commit before trying to email send_confirmation(user) return redirect("/account-pending") return render_register_with_oauth(provider, remote_user, username, email)
def register(): if request.method == 'POST': # Validate kwargs = dict() followMod = request.form.get('follow-mod') email = request.form.get('email') username = request.form.get('username') password = request.form.get('password') confirmPassword = request.form.get('repeatPassword') if not email: kwargs['emailError'] = 'Email is required.' else: if not re.match(r"^[^@]+@[^@]+\.[^@]+$", email): kwargs['emailError'] = 'Please specify a valid email address.' elif db.query(User).filter(User.email == email).first(): kwargs['emailError'] = 'A user with this email already exists.' if not username: kwargs['usernameError'] = 'Username is required.' else: if not re.match(r"^[A-Za-z0-9_]+$", username): kwargs[ 'usernameError'] = 'Please only use letters, numbers, and underscores.' if len(username) < 3 or len(username) > 24: kwargs[ 'usernameError'] = 'Usernames must be between 3 and 24 characters.' if db.query(User).filter(User.username.ilike(username)).first(): kwargs['usernameError'] = 'A user by this name already exists.' if not password: kwargs['passwordError'] = 'Password is required.' else: if password != confirmPassword: kwargs['repeatPasswordError'] = 'Passwords do not match.' if len(password) < 5: kwargs[ 'passwordError'] = 'Your password must be greater than 5 characters.' if len(password) > 256: kwargs[ 'passwordError'] = 'We admire your dedication to security, but please use a shorter password.' if not kwargs == dict(): if email is not None: kwargs['email'] = email if username is not None: kwargs['username'] = username return render_template("register.html", **kwargs) # All valid, let's make them an account user = User(username, email, password) user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8") db.add(user) db.commit( ) # We do this manually so that we're sure everything's hunky dory before the email leaves if followMod: send_confirmation(user, followMod) else: send_confirmation(user) return redirect("/account-pending") else: return render_template("register.html")
def register(): if not _cfgb('registration'): return redirect("/") if request.method == 'POST': # Validate kwargs = dict() followMod = request.form.get('follow-mod') email = request.form.get('email') username = request.form.get('username') password = request.form.get('password') confirmPassword = request.form.get('repeatPassword') error = check_email_for_registration(email) if error: kwargs['emailError'] = error error = check_username_for_registration(username) if error: kwargs['usernameError'] = error if not password: kwargs['passwordError'] = 'Password is required.' else: if password != confirmPassword: kwargs['repeatPasswordError'] = 'Passwords do not match.' if len(password) < 5: kwargs['passwordError'] = 'Your password must be greater than 5 characters.' if len(password) > 256: kwargs['passwordError'] = 'We admire your dedication to security, but please use a shorter password.' if not kwargs == dict(): # Fill in config values kwargs['site_name'] = _cfg('site-name') kwargs['support_mail'] = _cfg('support-mail') if email is not None: kwargs['email'] = email if username is not None: kwargs['username'] = username kwargs['registration'] = registration = _cfgb('registration') print("test") return render_template("register.html", **kwargs) # All valid, let's make them an account user = User(username, email, password) user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8") db.add(user) db.commit() # We do this manually so that we're sure everything's hunky dory before the email leaves if followMod: send_confirmation(user, followMod) else: send_confirmation(user) return redirect("/account-pending") else: return render_template("register.html", **{ "site_name": _cfg('site-name'), "support_mail": _cfg('support-mail'), "registration": _cfgb('registration') })
def register(): if request.method == 'POST': # Validate kwargs = dict() followMod = request.form.get('follow-mod') email = request.form.get('email') username = request.form.get('username') password = request.form.get('password') confirmPassword = request.form.get('repeatPassword') if not email: kwargs['emailError'] = 'Email is required.' else: if not re.match(r"^[^@]+@[^@]+\.[^@]+$", email): kwargs['emailError'] = 'Please specify a valid email address.' elif db.query(User).filter(User.email == email).first(): kwargs['emailError'] = 'A user with this email already exists.' elif _mailbans.isMailBanned(email): kwargs['emailError'] = 'This email host is banned, please use an alternative, this is to prevent botting, sorry.' if not username: kwargs['usernameError'] = 'Username is required.' else: if not re.match(r"^[A-Za-z0-9_]+$", username): kwargs['usernameError'] = 'Please only use letters, numbers, and underscores.' if len(username) < 3 or len(username) > 24: kwargs['usernameError'] = 'Usernames must be between 3 and 24 characters.' if db.query(User).filter(User.username.ilike(username)).first(): kwargs['usernameError'] = 'A user by this name already exists.' if not password: kwargs['passwordError'] = 'Password is required.' else: if password != confirmPassword: kwargs['repeatPasswordError'] = 'Passwords do not match.' if len(password) < 5: kwargs['passwordError'] = 'Your password must be greater than 5 characters.' if len(password) > 256: kwargs['passwordError'] = 'We admire your dedication to security, but please use a shorter password.' if not kwargs == dict(): if email is not None: kwargs['email'] = email if username is not None: kwargs['username'] = username return render_template("register.html", **kwargs) # All valid, let's make them an account user = User(username, email, password) user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8") db.add(user) db.commit() # We do this manually so that we're sure everything's hunky dory before the email leaves if followMod: send_confirmation(user, followMod) else: send_confirmation(user) return redirect("/account-pending") else: return render_template("register.html")
def register(): if not _cfgb('registration'): return redirect("/") if request.method == 'POST': # Validate kwargs = dict() followMod = request.form.get('follow-mod') email = request.form.get('email') username = request.form.get('username') password = request.form.get('password') confirmPassword = request.form.get('repeatPassword') error = check_email_for_registration(email) if error: kwargs['emailError'] = error error = check_username_for_registration(username) if error: kwargs['usernameError'] = error if not password: kwargs['passwordError'] = 'Password is required.' else: if password != confirmPassword: kwargs['repeatPasswordError'] = 'Passwords do not match.' if len(password) < 5: kwargs[ 'passwordError'] = 'Your password must be greater than 5 characters.' if len(password) > 256: kwargs[ 'passwordError'] = 'We admire your dedication to security, but please use a shorter password.' if not kwargs == dict(): if email is not None: kwargs['email'] = email if username is not None: kwargs['username'] = username kwargs['registration'] = registration = _cfgb('registration') print("test") return render_template("register.html", **kwargs) # All valid, let's make them an account user = User(username, email, password) user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8") db.add(user) db.commit( ) # We do this manually so that we're sure everything's hunky dory before the email leaves if followMod: send_confirmation(user, followMod) else: send_confirmation(user) return redirect("/account-pending") else: return render_template("register.html", registration=_cfgb('registration'))
def register(): if request.method == 'POST': # Validate kwargs = dict() email = request.form.get('email') username = request.form.get('username') password = request.form.get('password') confirmPassword = request.form.get('repeatPassword') if not email: kwargs['emailError'] = 'Email is required.' else: if not re.match(r"[^@]+@[^@]+\.[^@]+", email): kwargs['emailError'] = 'Please specify a valid email address.' elif db.query(User).filter(User.email == email).first(): kwargs['emailError'] = 'A user with this email already exists.' if not username: kwargs['usernameError'] = 'Username is required.' else: if not re.match(r"[A-Za-z0-9_]+", username): kwargs['usernameError'] = 'Please only use letters, numbers, and underscores.' if len(username) < 3 or len(username) > 12: kwargs['usernameError'] = 'Usernames must be between 3 and 12 characters.' if db.query(User).filter(User.username == username).first(): kwargs['usernameError'] = 'A user by this name already exists.' if not password: kwargs['passwordError'] = 'Password is required.' else: if password != confirmPassword: kwargs['repeatPasswordError'] = 'Passwords do not match.' if len(password) < 5: kwargs['passwordError'] = 'Your password must be greater than 5 characters.' if len(password) > 256: kwargs['passwordError'] = 'We admire your dedication to security, but please use a shorter password.' if not kwargs == dict(): if email is not None: kwargs['email'] = email if username is not None: kwargs['username'] = username return render_template("register.html", **kwargs) # All valid, let's make them an account user = User(username, email, password) user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8") db.add(user) db.commit() send_confirmation(user) return redirect("/account-pending") else: return render_template("register.html")