Exemplo n.º 1
0
def adduser(args):
    # TODO: Lets trust admins this do not validate Emails :)
    commands_util.setup_app(args)

    args.username = six.text_type(commands_util.prompt_if_not_set(args.username, "Username:"******"Password:"******"Email:")

    db = mg_globals.database
    users_with_username = db.LocalUser.query.filter(LocalUser.username == args.username.lower()).count()

    if users_with_username:
        print(u"Sorry, a user with that name already exists.")
        sys.exit(1)

    else:
        # Create the user
        entry = db.LocalUser()
        entry.username = six.text_type(args.username.lower())
        entry.email = six.text_type(args.email)
        entry.pw_hash = auth.gen_password_hash(args.password)
        default_privileges = [
            db.Privilege.query.filter(db.Privilege.privilege_name == u"commenter").one(),
            db.Privilege.query.filter(db.Privilege.privilege_name == u"uploader").one(),
            db.Privilege.query.filter(db.Privilege.privilege_name == u"reporter").one(),
            db.Privilege.query.filter(db.Privilege.privilege_name == u"active").one(),
        ]
        entry.all_privileges = default_privileges
        entry.save()

        print(u"User created (and email marked as verified).")
Exemplo n.º 2
0
def adduser(args):
    #TODO: Lets trust admins this do not validate Emails :)
    commands_util.setup_app(args)

    args.username = commands_util.prompt_if_not_set(args.username, "Username:"******"Password:"******"Email:")

    db = mg_globals.database
    users_with_username = \
        db.User.find({
            'username': args.username.lower(),
        }).count()

    if users_with_username:
        print u'Sorry, a user with that name already exists.'

    else:
        # Create the user
        entry = db.User()
        entry.username = unicode(args.username.lower())
        entry.email = unicode(args.email)
        entry.pw_hash = auth_lib.bcrypt_gen_password_hash(args.password)
        entry.status = u'active'
        entry.email_verified = True
        entry.save(validate=True)

        print "User created (and email marked as verified)"
Exemplo n.º 3
0
def adduser(args):
    #TODO: Lets trust admins this do not validate Emails :)
    commands_util.setup_app(args)

    args.username = commands_util.prompt_if_not_set(args.username, "Username:"******"Password:"******"Email:")

    db = mg_globals.database
    users_with_username = \
        db.User.query.filter_by(
            username=args.username.lower()
        ).count()

    if users_with_username:
        print u'Sorry, a user with that name already exists.'

    else:
        # Create the user
        entry = db.User()
        entry.username = unicode(args.username.lower())
        entry.email = unicode(args.email)
        entry.pw_hash = auth.gen_password_hash(args.password)
        entry.status = u'active'
        entry.email_verified = True
        entry.save()

        print "User created (and email marked as verified)"
Exemplo n.º 4
0
def adduser(args):
    #TODO: Lets trust admins this do not validate Emails :)
    commands_util.setup_app(args)

    args.username = six.text_type(
        commands_util.prompt_if_not_set(args.username, "Username:"******"Password:"******"Email:")

    db = mg_globals.database
    users_with_username = \
        db.LocalUser.query.filter(
            LocalUser.username==args.username.lower()
        ).count()

    if users_with_username:
        print(u'Sorry, a user with that name already exists.')
        sys.exit(1)

    else:
        # Create the user
        entry = db.LocalUser()
        entry.username = six.text_type(args.username.lower())
        entry.email = six.text_type(args.email)
        entry.pw_hash = auth.gen_password_hash(args.password)
        default_privileges = [
            db.Privilege.query.filter(
                db.Privilege.privilege_name == u'commenter').one(),
            db.Privilege.query.filter(
                db.Privilege.privilege_name == u'uploader').one(),
            db.Privilege.query.filter(
                db.Privilege.privilege_name == u'reporter').one(),
            db.Privilege.query.filter(
                db.Privilege.privilege_name == u'active').one()
        ]
        entry.all_privileges = default_privileges
        entry.save()

        print(u"User created (and email marked as verified).")
Exemplo n.º 5
0
def adduser(args):
    #TODO: Lets trust admins this do not validate Emails :)
    commands_util.setup_app(args)

    args.username = commands_util.prompt_if_not_set(args.username, "Username:"******"Password:"******"Email:")

    db = mg_globals.database
    users_with_username = \
        db.User.query.filter_by(
            username=args.username.lower()
        ).count()

    if users_with_username:
        print u'Sorry, a user with that name already exists.'

    else:
        # Create the user
        entry = db.User()
        entry.username = unicode(args.username.lower())
        entry.email = unicode(args.email)
        entry.pw_hash = auth.gen_password_hash(args.password)
        default_privileges = [
            db.Privilege.query.filter(
                db.Privilege.privilege_name==u'commenter').one(),
            db.Privilege.query.filter(
                db.Privilege.privilege_name==u'uploader').one(),
            db.Privilege.query.filter(
                db.Privilege.privilege_name==u'reporter').one(),
            db.Privilege.query.filter(
                db.Privilege.privilege_name==u'active').one()
        ]
        entry.all_privileges = default_privileges
        entry.save()

        print "User created (and email marked as verified)"