Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented mock routes #7

Merged
merged 8 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ Atlas is an open-source platform for hosting CTF competitions, utilizing dynamic
3. Build and run the docker containers

```bash
docker-compose up --build
docker compose up --build
```

4. For admin panel
```bash
docker exec -it atlas_backend python manage.py createsuperuser
```
The corresponding email and the password would be used for logging in to admin panel and use its functionality.

## Coding Guidelines

### Comments
Expand Down
7 changes: 4 additions & 3 deletions backend/atlas_backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Team(models.Model):
updated_at = models.DateTimeField(auto_now=True)
password = models.CharField(max_length=128, default=make_password('default_password'))
team_email = models.EmailField(unique=True, default='[email protected]')
max_attempts_per_challenge = models.IntegerField(default=10)

def __str__(self):
return self.name
Expand Down Expand Up @@ -82,7 +83,7 @@ class Challenge(models.Model):
docker_image = models.CharField(max_length=200)
flag = models.CharField(max_length=200)
max_points = models.IntegerField(validators=[MinValueValidator(0)])
max_team_size = models.IntegerField(default=4)
max_team_size = models.IntegerField(default=3)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
is_hidden = models.BooleanField(default=False)
Expand Down Expand Up @@ -124,8 +125,8 @@ class Submission(models.Model):
timestamp = models.DateTimeField(auto_now_add=True)

class Meta:
unique_together = ("team", "challenge", "attempt_number")
ordering = ["-timestamp"]
unique_together = [['team', 'challenge', 'attempt_number']]

def __str__(self):
return f"{self.team.name} - {self.challenge.title}"
return f"{self.team.name} - {self.challenge.title}"
22 changes: 15 additions & 7 deletions backend/atlas_backend/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from .models import User, Challenge, Team, Submission, Container

class UserSerializer(serializers.ModelSerializer):
team_name = serializers.CharField(source='team.name',read_only=True)
class Meta:
model = User
vg239 marked this conversation as resolved.
Show resolved Hide resolved
fields = ['id', 'username', 'email', 'team']
fields = ['id', 'username', 'email', 'team', 'team_name']

class SignupSerializer(serializers.ModelSerializer):
class Meta:
Expand All @@ -20,8 +21,18 @@ class ChallengeSerializer(serializers.ModelSerializer):

class Meta:
model = Challenge
fields = ['id', 'name', 'description', 'points', 'category',
'difficulty', 'is_solved']
fields = [
'id',
'title',
'description',
'max_points',
'category',
'docker_image',
'is_hidden',
'hints',
'file_links',
'is_solved'
]

def get_is_solved(self, obj):
user_team = self.context.get('user_team')
Expand All @@ -45,10 +56,7 @@ class Meta:
'total_score', 'member_count', 'solved_count', 'challenges']

class SubmissionSerializer(serializers.ModelSerializer):
challenge_name = serializers.CharField(source='challenge.title')
submitted_by = serializers.CharField(source='user.username')

class Meta:
model = Submission
fields = ['id', 'challenge_name', 'submitted_by', 'flag_submitted',
'is_correct', 'points_awarded', 'attempt_number', 'timestamp']
'is_correct', 'points_awarded', 'attempt_number', 'timestamp']
19 changes: 10 additions & 9 deletions backend/atlas_backend/urls.py
imApoorva36 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@

urlpatterns = [
# Auth routes
path('auth/register', views.signup, name='signup'),
path('auth/signup', views.signup, name='signup'),
path('auth/login', views.signin, name='signin'),
path('auth/refresh', views.token_refresh, name='token_refresh'),

# Challenge routes
path('challenges', views.get_challenges, name='get_challenges'),
path('challenges/<int:challenge_id>/submit', views.submit_flag, name='submit_flag'),
path('challenges/<int:challenge_id>/submissions', views.get_challenge_submissions, name='get_challenge_submissions'),
path('challenges/<int:challenge_id>/start', views.start_challenge, name='start_challenge'),

# Team routes
path('teams', views.get_teams, name='get_teams'),
path('teams/profile', views.team_profile, name='team_profile'),

# Scoreboard route
path('scoreboard', views.get_scoreboard, name='get_scoreboard'),
path('auth/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
# path('auth/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),

# Admin routes
path('auth/admin/login', views.admin_login, name='admin_login'),
path('challenges/admin', views.admin_get_challenges, name='admin_get_challenges'),
path('challenges/create', views.create_challenge, name='create_challenge'),
path('challenges/<int:challenge_id>/update', views.update_challenge, name='update_challenge'),
path('challenges/<int:challenge_id>/delete', views.delete_challenge, name='delete_challenge'),
path('challenges/<int:challenge_id>', views.get_challenge_detail, name='get_challenge_by_id'),
path('api/admin/challenges', views.admin_get_challenges, name='admin_get_challenges'),
path('api/admin/challenges/create', views.create_challenge, name='create_challenge'),
path('api/admin/challenges/<int:challenge_id>/update', views.update_challenge, name='update_challenge'),
path('api/admin/challenges/<int:challenge_id>/delete', views.delete_challenge, name='delete_challenge'),
path('api/admin/challenges/<int:challenge_id>', views.get_challenge_detail, name='get_challenge_by_id'),


]
]
Loading