def register(): if 'username' in session: flash("Cannot create new account while logged in.") return redirect(url_for('hello')) else: form = RegistrationForm() if form.validate_on_submit(): login = form.username.data user = dbsession.query(User).filter_by(name=login).first() if user is None: pw_hash = bcrypt.generate_password_hash(form.password.data) user = User(login, '', pw_hash) user.gender = form.gender.data user.species = form.species.data user.bio = form.bio.data user.email = form.email.data user.minorflag = not form.adult.data user.accepttos = True dbsession.add(user) dbsession.commit() flash("User Created") return redirect(url_for('login')) else: flash("User already exists.") return redirect(url_for('register')) return render_template('register.html', form=form)
# all users will have the password "changeme" # which looks like this: # $2a$12$/xOeN.4B6wQsen5TgvOAMOUVvETJ8vDC8WqhjHRF2OYGSslxMmB2O if __name__ == '__main__': password = '******' from db import User, Story, addDefault, refresh_db, session as dbsession import random import loremipsum for adduser in range(1,1000): username = "******" % (adduser) user = User(username,'',password) user.species = 'Automatic' user.bio = 'Automatic bio' user.email = '*****@*****.**' user.minorflag = True user.accepttos =True dbsession.add(user) dbsession.commit() for addstories in range(1,20000): newstory = Story(loremipsum.generate_sentence()[2]) newstory.text = loremipsum.generate_paragraph()[2] newstory.adult = True newstory.uid = random.randrange(1000)+1 dbsession.add(newstory) dbsession.commit()