コード例 #1
0
def student_attendance():
    student_id = request.args.get('sid')
    try:
        student_id = validation.sid(student_id)
    except ValueError:
        return Response("No valid student ID (sid)", 400).send()

    try:
        student_id = validation.sid(student_id)
    except ValueError:
        return Response("Invalid Student ID", 400).send()

    return Response(attending.get_student_attendance(student_id)).send()
コード例 #2
0
def register_student_attendance(student_id, event_uuid):
    try:
        student_id = validation.sid(student_id)
    except ValueError:
        return {'message': 'Invalid student ID'}, 400

    try:
        event_uuid = validation.event_id(event_uuid)
    except ValueError:
        return {'message': 'Invalid event ID'}, 400

    conn = sqlite3.connect(db_path)
    c = conn.cursor()

    arrival = datetime.datetime.now()
    arrival = arrival.strftime("%Y-%m-%d %H:%M:%S")
    try:
        c.execute("INSERT INTO Attendance VALUES(?, ?, ?);",
                  [student_id, arrival, event_uuid])
    except sqlite3.IntegrityError:
        return {'message': 'Already signed in'}, 200

    conn.commit()
    conn.close()
    return {'message': 'Successfully signed in'}, 200
コード例 #3
0
def get_student_by_id(sid):
    conn = sqlite3.connect(db_path)
    c = conn.cursor()
    sid = get_valid.sid(sid)  # Will throw ValueError if invalid sid
    c.execute("SELECT * FROM Student WHERE sid = ?;", (sid, ))
    result = c.fetchone()
    if not result:
        return None

    result_student = Student(sid, enc(result[1]), enc(result[2]))
    conn.close()
    return result_student
コード例 #4
0
ファイル: views.py プロジェクト: safwanvk/as
def create_student(request, *args, **kwargs):

    data = JSONParser().parse(request)
    
    std_id = data.get('sid')
    username = data.get('username')
    name = data.get('name')
    password = data.get('password')

    # If any of the values are not consistent with what is stored, then a response
    # is returned saying "parameters are missing" and an error code 400 is returned.
    if not (std_id and username and name and password):
        return Response({"message": "Parameters missing"}, status=400)

    try:
        std_id = validation.sid(std_id)
    except ValueError:
        return Response({"message": "Invalid student ID"}, status=400)

    try:
        username = validation.username(username)
    except ValueError:
        return Response({"message": "Invalid Username"}, status=400)

    try:
        name = validation.name(name)
    except ValueError:
        return Response({"message": "Invalid Name"}, status=400)


    try:
        std = Student.objects.filter(sid=std_id)

        if std.exists():
            return Response({"message": f"Student already exist with student id {std_id}."}, status=404)
            

        student = Student.objects.create(
            sid=std_id,
            username=username, 
            name=name,
            pass_hash=make_password(password)
        )

        return Response({"msg": "Success"} ,status=200)

    except Exception as e:
        print(e)
        return Response({"message": "Can't Create Studeny"} ,status=200)
コード例 #5
0
ファイル: views.py プロジェクト: safwanvk/as
def student_login(request, *args, **kwargs):

    data = JSONParser().parse(request)
    print(data)

    std_id = data.get('std_id')
    password = data.get('password')

    print(std_id, password)

    if not std_id or not password:
        return Response('ValueError: std_id or Password not found', 400)

    try:
        std_id = validation.sid(std_id)
    except ValueError:
        return Response({"message": "Invalid student ID"}, status=400)

    try:
        std = Student.objects.filter(std_id=std_id)

        if not std.exists():
            return Response({"message": f"No Student found with student id {std_id}."}, status=404)

        lec = std.first()
        serializer = StudentSerializer(lec)

        ck = check_password(password, serializer.data.get('pass_hash'))

        if ck != True:
            return Response({"message": "Password incorrect"}, status=401)

        session_key = uuid.uuid4().hex
        key_expires = datetime.now() + timedelta(days=1)
        key_expires_string = key_expires.strftime("%Y-%m-%d %H:%M:%S")

        reg = StudentLoginSessions.objects.create(
                    sid=Student.objects.get(sid=std_id), 
                    session_id=session_key,
                    expires=key_expires_string)

        return Response({"session_key": session_key} ,status=200)

    except Exception as e:
        print(e)
        return Response({"message": "A server error occurred"}, status=500)
コード例 #6
0
ファイル: views.py プロジェクト: safwanvk/as
def attend(request, *args, **kwargs):

    data = JSONParser().parse(request)
    print(data)

    std_id = data.get('user')
    event_uid = data.get('event')

    print(std_id, event_uid)

    if not std_id or not event_uid:
        return Response('ValueError: SID or Event_id not found', 400)

    try:
        try:
            std_id = validation.sid(std_id)
        except ValueError:
            return Response({"message": "Invalid student ID"}, status=400)

        try:
            event_uid = validation.event_id(event_uid)
        except ValueError:
            return Response({"message": "Invalid event ID"}, status=400)

        arrival = datetime.datetime.now()
        arrival = arrival.strftime("%Y-%m-%d %H:%M:%S")

        reg = Attendance.objects.create(
            sid=Student.objects.get(sid=std_id),
            arrival=arrival,
            event_id=Event.objects.get(event_id=event_uid),
        )

        return Response({"message": "Successfully signed in"}, status=200)

    except IntegrityError:
        return Response({"message": "Already signed in"}, status=200)
    except Exception as e:
        print(e)
        return Response({"message": "A server error occurred"}, status=500)
コード例 #7
0
ファイル: views.py プロジェクト: safwanvk/as
def student_attendance(request, *args, **kwargs):
    try:

        std_id = request.GET.get('sid')

        try:
            std_id = validation.sid(std_id)
        except ValueError:
            return Response({"message": "No valid student ID (sid)"},
                            status=400)

        std_ats = Attendance.objects.filter(sid=std_id)

        if not std_ats.exists():
            return Response({"message": "Student Attendance Not Found"},
                            status=404)

        serializer = AttendanceSerializer(std_ats, many=True)
        return Response(serializer.data, status=200)

    except Exception as e:
        print(e)
        return Response({"message": "A server error occurred"}, status=500)
コード例 #8
0
 def __init__(self, sid, name, username):
     self.sid = valid.sid(sid)
     self.name = valid.name(name)
     self.username = valid.username(username)