def fake_admin(): admin = User( username='******', email='*****@*****.**', image='http://www.gravatar.com/avatar/%s?d=identicon&s=120' % hashlib.md5( random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*()').encode( 'utf-8')).hexdigest()) admin.password = '******' db.session.add(admin) db.session.commit()
def fake_user(count=20): for i in range(count): users = User( username=fake.name(), email=fake.email(), image='http://www.gravatar.com/avatar/%s?d=identicon&s=120' % hashlib.md5( random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*()').encode( 'utf-8')).hexdigest()) users.password = '******' db.session.add(users) db.session.commit()
def initadmin(username, password): """Initialized blog account.""" click.echo('Initializing the database...') db.create_all() admin_empty = False admin_role = Role.query.filter_by(name='ADMIN').first() print(admin_role.users.first()) if admin_role.users.first() is None: admin_empty = True print("admin_empty:", admin_empty) if admin_empty: email = os.getenv('ADMIN_EMAIL', '*****@*****.**') click.echo('Creating account...') admin = User(username=username, email=email) admin.password = password admin_role.users.append(admin) click.echo('Giving email:< %s > a administrator permission...' % admin.email) else: admin = admin_role.users.first() click.echo( 'The Email < %s > is updating username and password...' % admin.email) admin.username = username admin.password = password db.session.add(admin) category = Category.query.first() if category is None: click.echo('Creating the default category...') category = Category(name='Default') db.session.add(category) db.session.commit() click.echo('Done.')
def register(): if current_user.is_authenticated: return redirect(url_for('index.index')) form = RegisterForm() if form.validate_on_submit(): email = form.email.data.lower() username = form.username.data password = form.password.data user = User(email=email, username=username) user.password=password token = generate_token(user=user, operation=Operations.CONFIRM) db.session.add(user) db.session.commit() send_confirm_email(user=user, token=token) flash('Register sucessfully. Please check your email and click the link to confirm your account.', 'info') return redirect(url_for('index.index')) return render_template('auth/register.html', form=form)