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'
Exemple #2
0
 def run(self, **kwargs):
     db.create_all()
     # check if admin exists
     a = Role.query.filter_by(name='admin').first()
     if a is None:
         db.session.add(Role(name='admin'))
         db.session.commit()
         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'
Exemple #3
0
from flask.ext.script import Manager
from flask.ext.script.commands import Server, Shell, ShowUrls, Clean
from flask.ext.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()
Exemple #4
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