Ejemplo 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
Ejemplo 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
Ejemplo n.º 3
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"
Ejemplo n.º 4
0
def add_admin(**values):
    values['password'] = prompt_pass("Password")
    request.form = AdminAddForm(MultiDict(values))
    if not validate_fields(request.form):
        print_field_errors(values['email'], request.form)
    a = Admin(values['email'], create_password(values['password']), values['active'])
    db.session.add(a)
    db.session.commit()
    print "Admin '%s' successfully added" % values['email'] 
Ejemplo n.º 5
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.'
Ejemplo n.º 6
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
Ejemplo n.º 7
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
Ejemplo n.º 8
0
    def run(username=None, email=None, active=False, password=''):
        from .models import User
        from base.ext import db

        password = password or prompt_pass("Set password")
        user = User(username=username,
                    email=email,
                    pw_hash=password,
                    active=active)

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

        print 'User created successfully.'
Ejemplo n.º 9
0
    def run(username=None, email=None, active=False, password=''):
        from .models import User
        from base.ext import db

        password = password or prompt_pass("Set password")
        user = User(username=username,
                    email=email,
                    pw_hash=password,
                    active=active)

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

        print 'User created successfully.'
Ejemplo n.º 10
0
def add_address(**values):
    domain = prompt_choices("Domain (%s@DOMAIN)" % values['username'], (d.name for d in Domain.query.order_by('-name')))
    passwd = prompt_pass("Password")