Exemplo n.º 1
0
def createuser(username=None, password=None, email=None, role=None):
    """
    Create a new user
    """
    
    if username is None:
        while True:
            username = prompt("Username")
            user = User.query.filter(User.username==username).first()
            if user is not None:
                print "Username %s is already taken" % username
            else:
                break

    if email is None:
        while True:
            email = prompt("Email address")
            user = User.query.filter(User.email==email).first()
            if user is not None:
                print "Email %s is already taken" % email
            else:
                break

    if password is None:
        password = prompt_pass("Password")

        while True:
            password_again = prompt_pass("Password again")
            if password != password_again:
                print "Passwords do not match"
            else:
                break
    
    roles = (
        (User.MEMBER, "member"),
        (User.MODERATOR, "moderator"),
        (User.ADMIN, "admin"),
    )

    if role is None:
        role = prompt_choices("Role", roles, resolve=int, default=User.MEMBER)

    user = User(username=username,
                email=email,
                password=password,
                role=role)

    db.session.add(user)
    db.session.commit()

    print "User created with ID", user.id
Exemplo n.º 2
0
def createuser(username=None, password=None, email=None, role=None):
    """
    Create a new user
    """

    if username is None:
        while True:
            username = prompt("Username")
            user = User.query.filter(User.username==username).first()
            if user is not None:
                print "Username %s is already taken" % username
            else:
                break

    if email is None:
        while True:
            email = prompt("Email address")
            user = User.query.filter(User.email==email).first()
            if user is not None:
                print "Email %s is already taken" % email
            else:
                break

    if password is None:
        password = prompt_pass("Password")

        while True:
            password_again = prompt_pass("Password again")
            if password != password_again:
                print "Passwords do not match"
            else:
                break

    roles = (
        (User.MEMBER, "member"),
        (User.MODERATOR, "moderator"),
        (User.ADMIN, "admin"),
    )

    if role is None:
        role = prompt_choices("Role", roles, resolve=int, default=User.MEMBER)

    user = User(username=username,
                email=email,
                password=password,
                role=role)

    db.session.add(user)
    db.session.commit()

    print "User created with ID", user.id
Exemplo n.º 3
0
def mailall():
    "Sends an email to all users"

    subject = prompt("Subject")
    message = prompt("Message")
    from_address = prompt("From", default="*****@*****.**")
    if prompt_bool("Are you sure ? Email will be sent to everyone!"):
        with mail.connect() as conn:
            for user in User.query:
                message = Message(subject=subject,
                                  body=message,
                                  sender=from_address,
                                  recipients=[user.email])

                conn.send(message)
Exemplo n.º 4
0
def mailall():
    "Sends an email to all users"
    
    subject = prompt("Subject")
    message = prompt("Message")
    from_address = prompt("From", default="*****@*****.**")
    if prompt_bool("Are you sure ? Email will be sent to everyone!"):
        with mail.connect() as conn:
            for user in User.query:
                message = Message(subject=subject,
                                  body=message,
                                  sender=from_address,
                                  recipients=[user.email])

                conn.send(message)
Exemplo n.º 5
0
def _read_date():
    """ read date from input; default to today """
    # show date
    while 1:
        dts = prompt("Date", default=str(datetime.date.today()))
        try:
            datetime.datetime.strptime(dts, "%Y-%m-%d")
            break
        except ValueError:
            continue
    return dts
Exemplo n.º 6
0
def deladmin():
    """ Management function to delete admins. """
    if password_valid(): 
        username = None
        while username is None:
            username = prompt("Please enter admin username").strip()
        user = admin_models.Admin.query.filter_by(username=username).first()
        if user:
            if prompt_bool("Are you sure you want to delete user %s"%user.name):
                models.db.session.delete(user)
                models.db.session.commit()
        else:
            print "User does not exist"
Exemplo n.º 7
0
def createuser(username=None, password=None, email=None):
    "Create a new user"
    if username is None:
        while True:
            username = prompt("Username")
            user = User.query.filter(User.username==username).first()
            if user is not None:
                print "Username %s is already taken" % username
            else:
                break

    if email is None:
        while True:
            email = prompt("Email address")
            user = User.query.filter(User.email==email).first()
            if user is not None:
                print "Email %s is already taken" % email
            else:
                break

    if password is None:
        password = prompt_pass("Password")

        while True:
            password_again = prompt_pass("Password again")
            if password != password_again:
                print "Passwords do not match"
            else:
                break

    user = User(username=username,
                email=email,
                password=password)

    db.session.add(user)
    db.session.commit()

    print "User created with ID", user.id
Exemplo n.º 8
0
def createuser(username=None, password=None, email=None):
    """
    Create new user
    """

    if username is None:
        while True:
            username = prompt("Username")
            user = User.query.filter(User.username == username).first()
            if user is not None:
                print "Username %s is already taken" % username
            else:
                break

    if email is None:
        while True:
            email = prompt("Email")
            user = User.query.filter(User.email == email).first()
            if user is not None:
                print "Email %s is already taken" % email
            else:
                break

    if password is None:
        password = prompt_pass("Password")

        while True:
            password_again = prompt_pass("Password again")
            if password != password_again:
                print "Password do not match"
            else:
                break

    user = User(username, None, email)
    user.set_password(password)
    user.store_to_db()

    print "User created with ID", user.id
Exemplo n.º 9
0
def admin():
    """ Management function to add admins. """
    if password_valid(): 
        username = None
        while username is None:
            username = prompt("Please enter new admin username")
        passwd = None
        while passwd is None:
            passwd = prompt_pass("Please enter password for user '%s'"%username)
            passwd_confirm = prompt_pass("Please confirm password")
            if passwd != passwd_confirm:
                print "Passwords do not match."
                passwd = None
        models.db.session.add(admin_models.Admin(username,passwd,True))
        models.db.session.commit()
    else:
        print "Admin creation aborted"
Exemplo n.º 10
0
def create_user(email=None, is_superuser=False):
    """Creates a user for this webapp. A valid email address is required."""

    super = 'super' if is_superuser else ''
    if email is None:
        email = prompt("Please enter the %suser's email address" % super)

    pw1 = prompt_pass("Please enter the %suser's password" % super)
    pw2 = prompt_pass("Please repeat the %suser's password" % super)
    if pw1 == pw2:
        user = models.User(email=email)
        user.set_password(pw1)
        if is_superuser:
            user.superuser = True
        db.session.add(user)
        db.session.commit()
    else:
        print 'Abort. Passwords do not match.'
Exemplo n.º 11
0
def create(what="app", name="MyAwesomeApp", layout="factory"):
    """(ext|app) <name>"""
    """
    flasktool create ext 'Flask-MongoEngine'

    flasktool create app MyAwesomeApp
    flasktool create app MyAwesomeApp --layout=factory
        - Create new folder.
        - Make app.yaml and  add to new folder.
        - Look at layout for template to use.
        - cd to new app directory
        - Create tasks, settings, etc.

    flasktool create view account
    flasktool create view api.account
        - Check we're in an app and load app yaml.
        - Default view imports in app.yaml
        - Create tests.views.test_account.py

    flasktool create view api.account
        - Check we're in an app and load app yaml.

    flasktool create model Account
        - Check we're in an app and load app yaml.
        - Create models.account.py.
        - Create tests.models.account.py
    """
    what = what[0]
    name = name[0]
    if what == "app":
        _app = FlaskApplication(name, layout=layout)
        _app.bootstrap()

        print "###################"
        print "Your new Flask app is ready!"
        print "###################"
        print "What to do now:"
        print "- cd %s" % name
        print "- Run ./manage.py runserver"
        print "- Write your app and tests"
        print "- Check in your code"
        print "- setup an EC2 instance"
        print "- Add credentials and hosts to fabfile.py"
        print "- Run fab deploy"
        print "- ???????"
        print "- Profit!"

    elif what == "ext":
        if not url:
            url = prompt("URL")

        if not author_name:
            author_name = prompt("Author Name")

        if not author_email:
            author_email = prompt("Author Email")

        license = prompt_choices("License", ("BSD", "MIT", "WTFPL"), default="BSD", resolve=string.upper)

        if not short_description:
            short_description = prompt("Short Description")

        if not requires:
            requires = prompt("Dependencies (comma separated, exclude Flask)")

        extension = FlaskExtension(name, url, author_name, author_email, short_description, requires, license)

        print "###################"
        print "Makin' the donuts..."
        print "###################"
        extension.boostrap()
        print "###################"
        print "Flask-%s created in %s" % (extension.name, extension.dir)
        print "###################"
Exemplo n.º 12
0
def create(what='app', name='MyAwesomeApp', layout='factory'):
    """(ext|app) <name>  # create an app or extension"""
    """
    flasktool create ext 'Flask-MongoEngine'

    flasktool create app MyAwesomeApp
    flasktool create app MyAwesomeApp --layout=factory
        - Create new folder.
        - Make app.yaml and  add to new folder.
        - Look at layout for template to use.
        - cd to new app directory
        - Create tasks, settings, etc.

    flasktool create view account
    flasktool create view api.account
        - Check we're in an app and load app yaml.
        - Default view imports in app.yaml
        - Create tests.views.test_account.py

    flasktool create view api.account
        - Check we're in an app and load app yaml.

    flasktool create model Account
        - Check we're in an app and load app yaml.
        - Create models.account.py.
        - Create tests.models.account.py
    """
    what = what[0]
    name = name[0]
    if what == 'app':
        _app = FlaskApplication(name, layout=layout)
        _app.bootstrap()

        print whatnext % {'name':name}
    
    elif what == 'ext':
        if not url:
            url = prompt('URL')
        
        if not author_name:
            author_name = prompt('Author Name')
        
        if not author_email:
            author_email = prompt('Author Email')
        
        license = prompt_choices('License', ('BSD','MIT','WTFPL'), 
            default='BSD', resolve=string.upper)
            
        if not short_description:
            short_description = prompt('Short Description')
        
        if not requires:
            requires = prompt('Dependencies (comma separated, exclude Flask)')
            
        extension = FlaskExtension(name, url, author_name, author_email, 
            short_description, requires, license)

        print "###################"
        print "Makin' the donuts..."
        print "###################"
        extension.boostrap()
        print "###################"
        print "Flask-%s created in %s" % (extension.name, extension.dir)
        print "###################"