Exemplo n.º 1
0
def refresh_all_ad_logins(run_from="UI"):
    # Go to the AD server and refresh all student and staff AD login times
    ret = ""

    # Might be longer running - make sure to commit so we don't leave databases locked
    db.commit()

    # Update the last login value for all users (students and faculty)
    if AD._ldap_enabled is not True:
        ret = "[AD Disabled]"
        return ret
    if AD.ConnectAD() is not True:
        ret = "[AD Connection Error]" + AD.GetErrorString()
        return ret

    # Grab list of students
    rows = db(db.student_info).select(db.student_info.user_id)
    for row in rows:
        # ret += "UID: " + row.user_id
        ll = Student.GetLastADLoginTime(row.user_id)
        # if (ll == None):
        #    ret += "None"
        # else:
        #    ret += str(ll)
        db(db.student_info.user_id == row.user_id).update(ad_last_login=ll)
        db.commit()

    # Grab a list of faculty
    rows = db(db.faculty_info).select(db.faculty_info.user_id)
    for row in rows:
        # ret += "UID: " + row.user_id
        ll = Faculty.GetLastADLoginTime(row.user_id)
        # if (ll == None):
        #    ret += "None"
        # else:
        #    ret += str(ll)
        db(db.faculty_info.user_id == row.user_id).update(ad_last_login=ll)
        db.commit()

    rows = None
    ad_errors = AD.GetErrorString()
    ret = "Done."

    # Have to call commit in tasks if changes made to the db
    db.commit()
    return ret
Exemplo n.º 2
0
def UpdateLastADLogin():
    ret = ""
    # Update the last login value for all users (students and faculty)
    if (AD.ConnectAD() != True):
        ret = "[AD Disabled]" + AD.GetErrorString()
        return ret

    # Grab list of students
    rows = db(db.student_info).select(db.student_info.user_id)
    for row in rows:
        #ret += "UID: " + row.user_id
        ll = Student.GetLastADLoginTime(row.user_id)
        #if (ll == None):
        #    ret += "None"
        #else:
        #    ret += str(ll)
        db(db.student_info.user_id == row.user_id).update(ad_last_login=ll)
        pass
    db.commit()

    # Grab a list of faculty
    rows = db(db.faculty_info).select(db.faculty_info.user_id)
    for row in rows:
        #ret += "UID: " + row.user_id
        ll = Faculty.GetLastADLoginTime(row.user_id)
        #if (ll == None):
        #    ret += "None"
        #else:
        #    ret += str(ll)
        db(db.faculty_info.user_id == row.user_id).update(ad_last_login=ll)
        pass
    db.commit()

    rows = None
    ad_errors = AD.GetErrorString()
    ret = "Done."
    return locals()