from mailu import manager, db
from mailu.admin import models
from passlib import hash


@manager.command
def flushdb():
    """ Flush the database
    """
    db.drop_all()


@manager.command
def initdb():
    """ Initialize the database
    """
    db.create_all()


@manager.command
def admin(localpart, domain_name, password):
    """ Create an admin user
    """
    domain = models.Domain.query.get(domain_name)
    if not domain:
        domain = models.Domain(name=domain_name)
        db.session.add(domain)
    user = models.User(
        localpart=localpart,
        domain=domain,
        global_admin=True,
        password=hash.sha512_crypt.encrypt(password)
    )
    db.session.add(user)
    db.session.commit()


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

@@ -721,16 +721,469 @@
 mmit()%0A%0A
+@manager.command%0Adef user(localpart, domain_name, password):%0A    %22%22%22 Create an user%0A    %22%22%22%0A    domain = models.Domain.query.get(domain_name)%0A    if not domain:%0A        domain = models.Domain(name=domain_name)%0A        db.session.add(domain)%0A    user = models.User(%0A        localpart=localpart,%0A        domain=domain,%0A        global_admin=False,%0A        password=hash.sha512_crypt.encrypt(password)%0A    )%0A    db.session.add(user)%0A    db.session.commit()%0A
 %0Aif __na

Add method to create a normal user