Пример #1
0
    def login_student(fenix_auth_code):
        if fenix_auth_code is not None:
            user = TecnicoClientHandler.get_user(fenix_client, fenix_auth_code)
            person = TecnicoClientHandler.get_person(fenix_client, user)

            banned_ids = StudentsFinder.get_banned_students_ist_id()
            if (person['username'] in banned_ids):
                return None, None

            student = StudentsFinder.get_from_ist_id(person['username'])
            if student is None:
                course = None
                for role in person['roles']:
                    if role['type'] == "STUDENT":
                        for registration in role['registrations']:
                            if registration['acronym']:
                                course = registration['acronym']
                                entry_year = get_year(
                                    registration['academicTerms'])
                                break
                    if role['type'] == 'ALUMNI':
                        for registration in role['concludedRegistrations']:
                            if registration['acronym']:
                                course = registration['acronym']
                                entry_year = get_year(
                                    registration['academicTerms'])
                                break

                if not course:
                    return None, None

                if person['email']:
                    email = person['email']
                elif person['institutionalEmail']:
                    email = person['institutionalEmail']
                else:
                    return None, None

                student = StudentsHandler.create_student(
                    person['name'], person['username'], email, course,
                    entry_year, person['photo']['data'],
                    person['photo']['type'])
                if student is None:
                    return None, None

            _jwt = jwt.encode({"user_id": person['username']},
                              Config.JWT_SECRET,
                              algorithm="HS256")
            encrypted_jwt = EncryptTokenService(_jwt).call()

            return student, encrypted_jwt

        else:
            return None, None
Пример #2
0
def kick_member(student):
    if (not student.is_captain()):
        return APIErrorValue('Student is not captain').json(401)

    try:
        member_ist_id = request.get_json()["ist_id"]
    except KeyError:
        return APIErrorValue('Invalid IST id').json(500)

    member = StudentsFinder.get_from_ist_id(member_ist_id)
    if (member is None):
        return APIErrorValue('Member not found').json(404)

    StudentsHandler.leave_squad(member)

    return SquadsValue(student.squad).json(200)
Пример #3
0
    def invite_squad_members(cls, student, members_ist_id):
        invitations_sent = SquadsFinder.get_invitations_from_parameters(
            {"sender_id": student.id})
        if (student.squad is None
                or (len(members_ist_id) + len(student.squad.members.all()) +
                    len(invitations_sent) > 4)):
            return None

        for member_ist_id in members_ist_id:
            member = StudentsFinder.get_from_ist_id(member_ist_id)
            if (member is None or member in student.squad.members):
                continue

            if (SquadsHandler.create_squad_invitation(
                    sender_id=student.id, receiver_id=member.id) is None):
                return False

        return True