예제 #1
0
파일: auth.py 프로젝트: Res260/flaggr
def register_administrator():
    """Register a new user"""
    body = flask_rebar.get_validated_body()
    email = body["email"]
    username = body["username"]
    password = body["password"]

    # Validate user uniqueness constraint.
    user = User.query.filter_by(email=email).first()
    if user is not None:
        administrator = user.get_administrator()

        if administrator is not None:
            raise errors.UnprocessableEntity("An administrator with that email already exists")

    user = User.query.filter_by(username=username).first()
    if user is not None:
        administrator = user.get_administrator()

        if administrator:
            raise errors.UnprocessableEntity("An administrator with that username already exists for this event")

    user = User(email=email, username=username)
    user.set_password(password)

    administrator = Administrator(is_platform_admin=False, user=user)

    DB.session.add(administrator)
    DB.session.commit()

    return administrator, 201
예제 #2
0
파일: auth.py 프로젝트: JDIS/flaggr
def register_participant(event: Event):
    """Register a new user"""
    body = flask_rebar.get_validated_body()
    email = body["email"]
    username = body["username"]
    password = body["password"]

    if not username:
        raise errors.UnprocessableEntity("Please choose a username")

    # Validate user uniqueness constraint.
    user = User.query.filter_by(email=email).first()
    if user is not None:
        participant = user.get_participant()

        if user is not None and participant and participant.event_id == event.id:
            raise errors.UnprocessableEntity("A participant with that email already exists for this event")

    user = User.query.filter_by(username=username).first()
    if user is not None:
        participant = user.get_participant()

        if user is not None and participant and participant.event_id == event.id:
            raise errors.UnprocessableEntity("A participant with that username already exists for this event")

    user = User(email=email, username=username)
    user.set_password(password)

    participant = Participant(event_id=event.id, user=user)

    DB.session.add(participant)

    if not event.teams:
        # means that its a solo event, need to create a team with the participant in it.
        team = Team(event_id=event.id, name=user.username,
                    members=[TeamMember(participant=participant, captain=True)])

        DB.session.add(team)

    DB.session.commit()

    login_user(participant.user, remember=True)

    return participant, 201
예제 #3
0

@fixture(autouse=True)
def current_participant_mock():
    with patch('JDISCTF.permission_wrappers.require_participant', lambda x: x):
        with local_patch('Participant') as mock:
            importlib.reload(sys.modules['JDISCTF.api.teams'])
            yield mock

    importlib.reload(sys.modules['JDISCTF.api.teams'])


A_EVENT = Event(id=0, name="Test Event", teams=True)

A_USER = User(id=0, username="******", email="*****@*****.**")
A_USER.set_password("test")

A_PARTICIPANT = Participant(id=0, user_id=A_USER.id, event_id=A_EVENT.id)

A_USER_WITHOUT_TEAM = User(id=1, username="******", email="*****@*****.**")
A_USER_WITHOUT_TEAM.set_password("test2")

A_PARTICIPANT_WITHOUT_TEAM = Participant(id=1,
                                         user_id=A_USER_WITHOUT_TEAM.id,
                                         event_id=A_EVENT.id)

A_USER_NOT_CAPTAIN = User(id=2, username="******", email="*****@*****.**")
A_USER_NOT_CAPTAIN.set_password("test3")

A_PARTICIPANT_NOT_CAPTAIN = Participant(id=2,
                                        user_id=A_USER_NOT_CAPTAIN.id,
예제 #4
0
파일: users.py 프로젝트: Res260/flaggr
def get_records_dev(events: [Event]):
    """Get the records to add to the database for development"""
    users = []
    for _ in events:
        user1 = User(email='*****@*****.**', username='******')
        user1.set_password('test')
        users.append(user1)
        user2 = User(email='*****@*****.**', username='******')
        user2.set_password('test')
        users.append(user2)
        user3 = User(email='*****@*****.**', username='******')
        user3.set_password('test')
        users.append(user3)
        user4 = User(email='*****@*****.**', username='******')
        user4.set_password('test')
        users.append(user4)

    user = User(email='*****@*****.**', username='******')
    user.set_password('admin')
    users.append(user)
    user = User(email='*****@*****.**', username='******')
    user.set_password('admin2')
    users.append(user)
    user = User(email='*****@*****.**', username='******')
    user.set_password('admin3')
    users.append(user)
    user = User(email='*****@*****.**', username='******')
    user.set_password('admin4')
    users.append(user)

    return users