Skip to content

Commit

Permalink
last update
Browse files Browse the repository at this point in the history
  • Loading branch information
Winz18 committed Jun 3, 2024
1 parent f4ee8fe commit a5c437b
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 77 deletions.
3 changes: 3 additions & 0 deletions CTF_App/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class Question(models.Model):
id = models.AutoField(primary_key=True)
content = models.TextField()

def __str__(self):
return self.content


class QuestionInTest(models.Model):
id = models.AutoField(primary_key=True)
Expand Down
22 changes: 7 additions & 15 deletions CTF_App/templates/CTF_App/add_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
{% block content %}
<div class="container mt-5">
<div class="row">
{% if messages %}
<ul class="messages">
{% for message in messages %}
<div class="text-center">{{ message }}</div>
{% endfor %}
</ul>
{% endif %}
<div class="col-md-8 offset-md-2">
<div class="card bg-dark text-light">
<div class="card-header">
Expand All @@ -23,19 +30,4 @@ <h2>Add Test to {{ article.name }}</h2>
</div>
</div>
</div>

<script>
document.getElementById('add-answer').addEventListener('click', function() {
const answerIndex = document.querySelectorAll('#answers .form-group').length + 1;
const newAnswerDiv = document.createElement('div');
newAnswerDiv.classList.add('form-group');
newAnswerDiv.innerHTML = `
<label for="answer_${answerIndex}_content">Answer ${answerIndex}</label>
<input type="text" class="form-control" id="answer_${answerIndex}_content" name="form-${answerIndex}-content" required>
<label for="answer_${answerIndex}_result">Is Correct</label>
<input type="checkbox" id="answer_${answerIndex}_result" name="form-${answerIndex}-result">
`;
document.getElementById('answers').appendChild(newAnswerDiv);
});
</script>
{% endblock %}
45 changes: 35 additions & 10 deletions CTF_App/templates/CTF_App/article_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@

<div class="container mt-5">
<div class="row">
<div style="align-self: center; justify-content: center; align-items: center;">
{% if messages %}
<ul class="messages" style="align-self: center; justify-content: center; align-items: center; width: 60%; margin-left: 225px">
{% for message in messages %}
<div class="alert alert-warning text-center" role="alert"
style="align-self: center; justify-content: center; align-items: center; font-size: large">
{{message}}
</div>
{% endfor %}
</ul>
{% endif %}
</div>
<div class="col-md-8 offset-md-2">
<div class="card bg-dark text-light">
<div class="card-header article-header">
Expand All @@ -56,39 +68,50 @@ <h2>{{ article.name }}</h2>
{% if section.part_type == 'text' %}
<pre>{{ section.text|safe }}</pre>
{% elif section.part_type == 'image' %}
<img alt="Article Image" class="img-fluid mx-auto d-block" src="{{ section.image.url }}">
<img alt="Article Image" class="img-fluid mx-auto d-block" width="100%" height="70%" src="{{ section.image.url }}">
{% elif section.part_type == 'video' %}
<iframe allowfullscreen frameborder="0" height="400" src="{{ section.video_url }}"
width="100%"></iframe>
<iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen frameborder="0"
height="315"
referrerpolicy="strict-origin-when-cross-origin"
src="{{ section.video_url }}"
title="YouTube video player"
width="100%">
</iframe>
{% endif %}
<br>
{% if user.is_authenticated and user == article.author %}
<a class="btn btn-warning" href="{% url 'CTF_App:edit_section' section.id %}">Edit</a>
<span style="margin-right: 30px;"></span>
<a class="btn btn-danger" href="{% url 'CTF_App:delete_section' section.id %}">Delete</a>
<span style="margin-right: 30px;"></span>
<a class="btn btn-primary" href="{% url 'CTF_App:add_section' article.id section.position %}">Add
above</a>
<a class="btn btn-primary" href="{% url 'CTF_App:add_section' article.id section.position %}">Add above</a>
<hr>
{% endif %}
{% endfor %}
</div>
<div class="btn-group">
{% if user.is_authenticated and user == article.author %}
<a class="btn btn-primary" href="{% url 'CTF_App:add_section' article.id %}">Add Section</a>
<a class="btn btn-primary" href="{% url 'CTF_App:edit_test' article.id %}">Edit Test</a>
{% if article.test %}
<a class="btn btn-warning" href="{% url 'CTF_App:edit_test' article.id %}">Edit Test</a>
{% else %}
<a class="btn btn-primary" href="{% url 'CTF_App:add_test' article.id %}">Add Test</a>
<a class="btn btn-danger" href="{% url 'CTF_App:delete_article' article.id %}">Delete
Article</a>
{% endif %}
<a class="btn btn-danger" href="{% url 'CTF_App:delete_article' article.id %}">Delete Article</a>
{% else %}
{% if article.test and user.is_authenticated %}
<a class="btn btn-primary" href="{% url 'CTF_App:take_test' article.id %}">Start Quiz</a>
{% endif %}
{% endif %}
</div>
<hr>
<div class="comments">
<h3>Comments</h3>
{% for comment in comments %}
<div class="comment">
<p> <p class="text-info">{{ comment.user.username }} ({{ comment.created_at }}) :</p>{{ comment.text }}</p>
<p class="text-info">{{ comment.user.username }} ({{ comment.created_at }}) :</p>
{{comment.text }}</p>
</div>
{% endfor %}
</div>
Expand All @@ -98,9 +121,11 @@ <h3>Leave a comment</h3>
<form method="post">
{% csrf_token %}
{{ comment_form.as_p }}
{% if user.is_authenticated %}
<button class="btn btn-primary" type="submit">
Submit
</button>
{% endif %}
</form>
</div>
</div>
Expand All @@ -112,7 +137,7 @@ <h3>Leave a comment</h3>

{% block extra_js %}
<script>
// reload the pagg and move to the previous position
// reload the page and move to the previous position
window.onload = function () {
window.scrollTo(0, localStorage.getItem('scrollPosition'));
}
Expand Down
7 changes: 7 additions & 0 deletions CTF_App/templates/CTF_App/article_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ <h6>Valid categories: 'Web Security' | 'Cryptography' | 'Reverse Engineering' |
<button class="btn btn-primary" type="submit">Submit</button>
</form>
</div>
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li {% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }} </li>
{% endfor %}
</ul>
{% endif %}
{% endblock %}
86 changes: 70 additions & 16 deletions CTF_App/templates/CTF_App/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,60 @@
<link href="{% static 'static/css/style.css' %}" rel="stylesheet">
<style>
body {
background-color: #121212; /* Màu đen */
color: #fff; /* Màu chữ trắng */
background-color: #121212;
color: #fff;

.navbar {
background-color: #1f1f1f;
}

.navbar-brand, .nav-link, .dropdown-item {
color: #fff !important;
}

.navbar-brand:hover, .nav-link:hover, .dropdown-item:hover {
color: #bbb !important;
}

.navbar-toggler {
border: none;
}

.btn {
margin-right: 10px;
}

.container {
padding-top: 20px;
}

.dropdown-menu {
background-color: #1f1f1f;
}

.dropdown-item {
transition: background-color 0.2s, color 0.2s;
}

.dropdown-item:hover {
background-color: #343a40;
color: #fff;
}

.nav-item {
margin-left: 10px;
}

.categories-section {
margin-top: 20px;
padding: 20px;
background-color: #1f1f1f;
border-radius: 5px;
}

.categories-section h5 {
margin-bottom: 15px;
}
}
</style>
{% block extra_css %}{% endblock %}
Expand All @@ -38,14 +90,15 @@
<div class="collapse navbar-collapse" id="navbarTogglerDemo02">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a aria-current="page" class="nav-link active" href="{% url 'CTF_App:index' %}"
style="color: white">Home</a>
<a aria-current="page" class="nav-link active" href="{% url 'CTF_App:index' %}">Home</a>
</li>
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="{% url 'CTF_App:article_create' %}" style="color: white">Contribute_article</a>
<a class="nav-link" href="{% url 'CTF_App:article_create' %}">Contribute Article</a>
</li>
{% endif %}
<li class="nav-item">
<a class="nav-link" href="{% url 'CTF_App:scoreboard' %}" style="color: white">Scoreboard</a>
<a class="nav-link" href="{% url 'CTF_App:scoreboard' %}">Scoreboard</a>
</li>
<li class="nav-item dropdown">
<a aria-expanded="false" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#"
Expand All @@ -67,16 +120,17 @@
</ul>
</li>
</ul>
{% if user.is_authenticated %}
<a class="btn btn-danger" href="{% url 'CTF_App:logout' %}">Logout</a>
<span style="margin-right: 30px;"></span>
<a class="btn btn-primary" href="{% url 'CTF_App:profile' %}">Profile</a>
{% endif %}
{% if not user.is_authenticated %}
<a class="btn btn-success" href="{% url 'CTF_App:login' %}">Login</a>
<span style="margin-right: 30px;"></span>
<a class="btn btn-primary" href="{% url 'CTF_App:signup' %}">Signup</a>
{% endif %}
<div class="d-flex">
{% if user.is_authenticated %}
<a class="btn btn-danger" href="{% url 'CTF_App:logout' %}">Logout</a>
<span style="margin-right: 30px;"></span>
<a class="btn btn-primary" href="{% url 'CTF_App:profile' %}">Profile</a>
{% else %}
<a class="btn btn-success" href="{% url 'CTF_App:login' %}">Login</a>
<span style="margin-right: 30px;"></span>
<a class="btn btn-primary" href="{% url 'CTF_App:signup' %}">Signup</a>
{% endif %}
</div>
</div>
</div>
</nav>
Expand Down
12 changes: 11 additions & 1 deletion CTF_App/templates/CTF_App/edit_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
{% block content %}
<div class="container mt-5">
<h2>Edit Test for {{ article.name }}</h2>
<div class="row">
{% if messages %}
<ul class="messages">
{% for message in messages %}
<div class="text-center">{{ message }}</div>
{% endfor %}
</ul>
{% endif %}
</div>
<form method="post">
{% csrf_token %}
{{ formset.management_form }}
Expand All @@ -36,8 +45,9 @@ <h5>Answers:</h5>
<div class="form-group">
{{ af.as_p }}
</div>
<hr>
<br>
{% endfor %}
<hr>
{% else %}
<p>Please save the question before adding answers.</p>
{% endif %}
Expand Down
3 changes: 2 additions & 1 deletion CTF_App/templates/CTF_App/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ <h2 class="text-center">Sign Up</h2>
<button class="btn btn-primary btn-block btn-signup" type="submit">Sign Up</button>
</form>
{% if messages %}
<br>
<div class="alert alert-danger">
<ul>
{% for message in messages %}
<li>{{ message }}</li>
<div>{{ message }}</div>
{% endfor %}
</ul>
</div>
Expand Down
Loading

0 comments on commit a5c437b

Please sign in to comment.