import os

from app import create_app

from flask.ext.script import Manager

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)

if __name__ == '__main__':
  manager.run()

import os

from app import create_app, db
from app.models import User

from flask.ext.script import Manager

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)

@manager.command
def adduser(email, username, admin=False):
  """ Register a new user"""
  from getpass import getpass
  password = getpass()
  password2 = getpass(prompt = 'Confirm: ')

  if password != password2:
    import sys
    sys.exit("Error: Passwords do not match!")
  
  db.create_all()

  user = User(email=email, username=username, password=password, is_admin=admin)
  db.session.add(user)
  db.session.commit()

  print('User {0} was registered successfully!'.format(username))

if __name__ == '__main__':
  manager.run()

Add a custom script command to add a user to the database
Add a custom script command to add a user to the database

  import os
  
- from app import create_app
+ from app import create_app, db
+ from app.models import User
  
  from flask.ext.script import Manager
  
  app = create_app(os.getenv('FLASK_CONFIG') or 'default')
  manager = Manager(app)
  
+ @manager.command
+ def adduser(email, username, admin=False):
+   """ Register a new user"""
+   from getpass import getpass
+   password = getpass()
+   password2 = getpass(prompt = 'Confirm: ')
+ 
+   if password != password2:
+     import sys
+     sys.exit("Error: Passwords do not match!")
+   
+   db.create_all()
+ 
+   user = User(email=email, username=username, password=password, is_admin=admin)
+   db.session.add(user)
+   db.session.commit()
+ 
+   print('User {0} was registered successfully!'.format(username))
+ 
  if __name__ == '__main__':
    manager.run()
  
Add a custom script command to add a user to the database
## Code Before:
import os

from app import create_app

from flask.ext.script import Manager

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)

if __name__ == '__main__':
  manager.run()

## Instruction:
Add a custom script command to add a user to the database
## Code After:
import os

from app import create_app, db
from app.models import User

from flask.ext.script import Manager

app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)

@manager.command
def adduser(email, username, admin=False):
  """ Register a new user"""
  from getpass import getpass
  password = getpass()
  password2 = getpass(prompt = 'Confirm: ')

  if password != password2:
    import sys
    sys.exit("Error: Passwords do not match!")
  
  db.create_all()

  user = User(email=email, username=username, password=password, is_admin=admin)
  db.session.add(user)
  db.session.commit()

  print('User {0} was registered successfully!'.format(username))

if __name__ == '__main__':
  manager.run()
