Esempio n. 1
0
def add_permission(name, description):
    permission = Permission(permission_name=name,
                            permission_description=description)
    info("Creating '" + name + "' permission.")
    db.session.add(permission)
    db.session.commit()
    return permission
Esempio n. 2
0
def add_user(id=None, active=False):
    user = User.query.get(id)
    if not user:
        user = User(uid=id, is_active=active)
        db.session.add(user)
        db.session.commit()
        info("Added user " + str(user.uid) + ".")
    return user
Esempio n. 3
0
def register(uid, **kwargs):
    token_user = AuthMethodToken.query.filter_by(uid=uid).first()
    if token_user:
        return {'status': 'error', 'message': 'User already has a token.'}
    else:
        user = User.query.get(int(uid))
        if not user:
            return {'status': 'error', 'message': 'User does not exist.'}

        token = generate_token()
        token_user = AuthMethodToken(uid=user.get_id(), token=token)
        db.session.add(token_user)
        db.session.commit()

        info("Token generated: " + str(user.get_id()) + "$" + token)

        return {'status': 'success', 'payload': user}
Esempio n. 4
0
def register(username, **kwargs):
    local_user = AuthMethodLocal.query.filter_by(username=username).first()
    if local_user:
        return {'status': 'error', 'message': 'Username already registered.'}
    else:
        try:
            if kwargs['password1'] == kwargs['password2']:
                password = hash_password(kwargs['password1'])
            else:
                return {'status': 'error', 'message': 'Passwords do not match'}
        except NameError:
            return {'status': 'error', 'message': 'No password supplied.'}

        user = None
        try:
            user = User.query.get(int(uid))
            try:
                if not verify_password(user.password, kwargs['password0']):
                    return {
                        'status': 'error',
                        'message': 'Current password incorrect.'
                    }
            except NameError:
                return {
                    'status': 'error',
                    'message': 'Current password not supplied.'
                }
        except NameError:
            user = User(is_active=True)
            db.session.add(user)
            db.session.commit()

        local_user = AuthMethodLocal(uid=user.get_id(),
                                     username=username,
                                     password=password)
        db.session.add(local_user)
        db.session.commit()
        info("Registered '" + username.rstrip() + "' with User ID: " +
             str(user.get_id()))
        return {'status': 'success', 'payload': user}
Esempio n. 5
0
def add_group(name, description):
    info("Adding group '" + name + "'.")
    group = Group(group_name=name, group_description=description)
    db.session.add(group)
    db.session.commit()
    return group
Esempio n. 6
0
def delete_user(user):
    info("Deleting user " + str(user.uid) + ".")
    db.session.delete(user)
    db.session.commit()
Esempio n. 7
0
def remove_auth_from_user(user, auth):
    info("Removing authentication method '" + auth.method_class +
         "' from user " + str(user.uid) + ".")
    user.auth_methods.remove(auth)
    db.session.commit()
Esempio n. 8
0
def add_auth_to_user(auth, user):
    info("Adding authentication method '" + auth.method_class + "' to user " +
         str(user.uid) + ".")
    user.auth_methods.append(auth)
    db.session.commit()
Esempio n. 9
0
def delete_auth(auth):
    info("Deleting authentication method '" + class_ + "'.")
    db.session.delete(auth)
    db.session.commit()
Esempio n. 10
0
def allow_user(user, permission):
    info("Allowing user " + str(user.uid) + " to use '" +
         permission.permission_name + "'.")
    permission.users.append(user)
    db.session.commit()
Esempio n. 11
0
def add_user_to_group(user, group):
    info("Adding user " + str(user.uid) + " to the '" + group.group_name +
         "' group.")
    group.users.append(user)
    db.session.commit()
Esempio n. 12
0
def deny_group(group, permission):
    info("Denying group '" + group.group_name + "' to use of '" +
         permission.permission_name + "'.")
    permission.groups.remove(group)
    db.session.commit()
Esempio n. 13
0
def allow_group(group, permission):
    info("Allowing group '" + group.group_name + "' to use '" +
         permission.permission_name + "'.")
    permission.groups.append(group)
    db.session.commit()
Esempio n. 14
0
def deny_user(user, permission):
    info("Denying user " + str(user.uid) + " to use of '" +
         permission.permission_name + "'.")
    permission.users.remove(user)
    db.session.commit()
Esempio n. 15
0
def add_auth(class_):
    info("Adding authentication method '" + class_ + "'.")
    auth = AuthMethod(method_class=class_)
    db.session.add(auth)
    db.session.commit()
    return auth
Esempio n. 16
0
def remove_user_from_group(user, group):
    info("Removing user " + str(user.uid) + " from the '" + group.group_name +
         "' group.")
    group.users.remove(user)
    db.session.commit()
Esempio n. 17
0
def delete_group(group):
    info("Deleting group '" + group.group_name + ".")
    db.session.delete(group)
    db.session.commit()
Esempio n. 18
0
def delete_permission(permission):
    info("Deleting '" + permission.permision_name + "' permission.")
    db.session.delete(permission)
    db.session.commit()