Esempio n. 1
0
def add_role(email, role):
    """Adds a role to the specified user.
        """
    from enferno.user.models import Role
    u = User.query.filter(User.email == email).first()
    if u == None:
        print('Sorry, this user does not exist!')
        return
    r = Role.query.filter(Role.name == role).first()
    if r == None:
        print('Sorry, this role does not exist!')
        u = click.prompt('Would you like to create one? Y/N', default='N')
        if u.lower() == 'y':
            r = Role(name=role)
            try:
                db.session.add(r)
                db.session.commit()
                print(
                    'Role created successfully, you may add it now to the user'
                )
            except:
                db.session.rollback()

    else:
        AddRoleCommand().run(user_identifier=email, role_name=role)
Esempio n. 2
0
 def run(self, **kwargs):
     #check if admin exists
     a = Role.objects.filter(name='admin').first()
     if a == None:
         Role(name='admin').save()
         u = prompt('Admin Email?', default='*****@*****.**')
         p = prompt('Admin Password (min 6 characters)?', default='enferno')
         CreateUserCommand().run(email=u, password=p, active=1)
         AddRoleCommand().run(user_identifier=u, role_name='admin')
     else:
         print 'Seems like an Admin is already installed'
Esempio n. 3
0
def install():
    """Install a default admin user and add an admin role to it.
    """
    #check if admin exists
    from enferno.user.models import Role
    a = Role.objects.filter(name ='admin').first()

    if a == None:
        r = Role(name='admin').save()
        u = click.prompt('Admin Email?',default='*****@*****.**')
        p = click.prompt('Admin Password (min 6 characters)?',default='enferno')
        CreateUserCommand().run(email=u,password=p,active=1)
        AddRoleCommand().run(user_identifier=u,role_name='admin')
    else:
        print ('Seems like an Admin is already installed')
Esempio n. 4
0
def add_role(email, role):
    """Adds a role to the specified user.
    """
    from enferno.user.models import Role
    u = User.objects(email = email).first()
    if u == None:
        print ('Sorry, this user does not exist!')
        return
    r = Role.objects(name = role).first()
    if r == None:
        print ('Sorry, this role does not exist!')
        u = click.prompt('Would you like to create one? Y/N', default='N')
        if u.lower() == 'y':
            Role(name=role).save()
            print ('Role created successfully, you may add it now to the user')
    else:
        AddRoleCommand().run(user_identifier=email, role_name=role)
Esempio n. 5
0
#!/usr/bin/env python
from flask_script import Manager
from flask_script.commands import Server, Shell, ShowUrls, Clean
from flask_security.script import CreateUserCommand, AddRoleCommand,\
    RemoveRoleCommand, ActivateUserCommand, DeactivateUserCommand

from flask_application import app
from flask_application.script import ResetDB, PopulateDB
from flask_application.tests.script import RunTests

manager = Manager(app)
manager.add_command("shell", Shell(use_ipython=True))
manager.add_command("runserver", Server(use_reloader=True))
manager.add_command("show_urls", ShowUrls())
manager.add_command("clean", Clean())

manager.add_command("reset_db", ResetDB())
manager.add_command("populate_db", PopulateDB())

manager.add_command('create_user', CreateUserCommand())
manager.add_command('add_role', AddRoleCommand())
manager.add_command('remove_role', RemoveRoleCommand())
manager.add_command('deactivate_user', DeactivateUserCommand())
manager.add_command('activate_user', ActivateUserCommand())

manager.add_command('run_tests', RunTests())

if __name__ == "__main__":
    manager.run()
Esempio n. 6
0
@user_manager.command
def reset_password(user_id):
    from flask.ext.security.utils import encrypt_password
    user = models.RegisteredUser.query.get(user_id)
    if user.is_ldap:
        print "Can't change password for EIONET users"
        return
    plaintext_password = raw_input("new password: "******"password for %s has been changed" % user_id


role_manager = Manager()
role_manager.add_command('create', CreateRoleCommand())
role_manager.add_command('add', AddRoleCommand())
role_manager.add_command('remove', RemoveRoleCommand())


@role_manager.command
def ls():
    for role in models.Role.query:
        print "{r.name}: {r.description}".format(r=role)


@role_manager.command
def members(role):
    role_ob = models.Role.query.filter_by(name=role).first()
    if role_ob is None:
        print 'No such role %r' % role
        return