public
Authored by avatar null pointer

jam.py server-side snippet for multiple local login sources

Edited
system.py 1.61 KiB
def on_login(task, login, password):
    results = None

    if not results and login == "admin" and password == "admin":
        results = {
            'user_id': '1',
            'user_name': 'administrative failsafe',
            'role_id': 1,
            'role_name': 'Administrator',
            'admin': 1
        }
        print("DEV: hardcoded login")

    if not results:
        user = task.catalogs.external.copy()
        user.open(where = {
            "f_login": login,
            "f_password": password })
        if user.record_count() == 1:
            # match role_id and role_name with existing system roles
            results = {
                'user_id': user.field_by_name('id').value,
                'user_name': user.field_by_name('username').value,
                'role_id': 2,
                'role_name': 'Lesser Group',
                'admin': 0,
                'custom_field': user.field_by_name('custom_field').value
            }
            print("DEV: login via userspace")

    if not results:
        user = task.app.admin.sys_catalogs.sys_users.copy()
        user.open(where = {
            "f_login": login,
            "f_password": password })
        if user.record_count() == 1:
            results = {
                'user_id': user.field_by_name('id').value,
                'user_name': user.field_by_name('f_name').value,
                'role_id': user.field_by_name('f_role').value,
                'role_name': user.field_by_name('f_role').display_text,
                'admin': user.field_by_name('f_admin').value
            }
            print("DEV: login via system")

    return results
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment