Skip to content

Commit 951c3fc

Browse files
committed
Latest changes and cleanup
1 parent 0e3fd9b commit 951c3fc

File tree

9 files changed

+102
-129
lines changed

9 files changed

+102
-129
lines changed
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,33 @@
1-
# Base image for running the .NET API
21
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
32
WORKDIR /app
43
EXPOSE 8080
54
EXPOSE 8081
65

7-
# Development stage (voor dotnet watch)
86
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS dev
97
WORKDIR /app
108
COPY ./ShowcaseAPI ./ShowcaseAPI
119
WORKDIR /app/ShowcaseAPI
1210
CMD ["dotnet", "watch", "run", "--no-launch-profile", "--urls", "http://+:80"]
1311

14-
# Build stage (voor productie)
1512
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
1613
WORKDIR /src
1714
COPY ["ShowcaseAPI/ShowcaseAPI.csproj", "ShowcaseAPI/"]
1815
RUN dotnet restore "ShowcaseAPI/ShowcaseAPI.csproj"
1916

20-
# Copy and build source
2117
COPY . .
2218
WORKDIR "/src/ShowcaseAPI"
2319
RUN dotnet build "ShowcaseAPI.csproj" -c Release -o /app/build
2420

25-
# Publish (voor productie)
2621
FROM build AS publish
2722
RUN dotnet publish "ShowcaseAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false
2823

29-
# Final production stage
3024
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS final
3125
WORKDIR /app
3226

33-
# Kopieer wait script
27+
# https://github.com/palfrey/wait-for-db
3428
COPY ShowcaseAPI/wait-for-sql.sh .
3529
RUN chmod +x wait-for-sql.sh
3630

37-
# Kopieer build output
3831
COPY --from=publish /app/publish .
3932

40-
# Start script dat wacht op SQL Server
4133
ENTRYPOINT ["./wait-for-sql.sh"]

ShowcaseProject/ShowcaseAPI/Program.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,9 @@
2323

2424
Env.Load();
2525

26-
// Add services to the container.
27-
builder.Services.AddAuthentication(options =>
26+
builder.Services.Configure<IdentityOptions>(options =>
2827
{
29-
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
30-
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
31-
}).AddJwtBearer(options =>
32-
{
33-
options.TokenValidationParameters = new TokenValidationParameters
34-
{
35-
ValidIssuer = Environment.GetEnvironmentVariable("JWT_ISSUER"),
36-
ValidAudience = Environment.GetEnvironmentVariable("JWT_AUDIENCE"),
37-
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Environment.GetEnvironmentVariable("JWT_KEY")!)),
38-
ValidateIssuer = true,
39-
ValidateAudience = true,
40-
ValidateLifetime = true,
41-
ValidateIssuerSigningKey = true,
42-
};
28+
options.Password.RequiredLength = 12;
4329
});
4430

4531
builder.Services.AddSignalR();

ShowcaseProject/ShowcaseFrontend/Controllers/ContactController.cs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,5 @@ public ActionResult Index()
2323
{
2424
return View();
2525
}
26-
27-
// POST: ContactController
28-
//[HttpPost]
29-
//[ValidateAntiForgeryToken]
30-
//public async Task<ActionResult> Index(Contactform form)
31-
//{
32-
// if(!ModelState.IsValid)
33-
// {
34-
// ViewBag.Message = "De ingevulde velden voldoen niet aan de gestelde voorwaarden";
35-
// return View();
36-
// }
37-
38-
// var settings = new JsonSerializerSettings
39-
// {
40-
// ContractResolver = new CamelCasePropertyNamesContractResolver()
41-
// };
42-
43-
// var json = JsonConvert.SerializeObject(form, settings);
44-
// var content = new StringContent(json, Encoding.UTF8, "application/json");
45-
46-
47-
48-
49-
//Gebruik _httpClient om een POST-request te doen naar ShowcaseAPI die de Mail uiteindelijk verstuurt met Mailtrap (of een alternatief).
50-
//Verstuur de gegevens van het ingevulde formulier mee aan de API, zodat dit per mail verstuurd kan worden naar de ontvanger.
51-
//Hint: je kunt dit met één regel code doen. Niet te moeilijk denken dus. :-)
52-
//Hint: vergeet niet om de mailfunctionaliteit werkend te maken in ShowcaseAPI > Controllers > MailController.cs,
53-
// nadat je een account hebt aangemaakt op Mailtrap (of een alternatief).
54-
55-
// HttpResponseMessage response = await _httpClient.PostAsync("api/Mail", content);
56-
57-
// if (!response.IsSuccessStatusCode)
58-
// {
59-
// ViewBag.Message = "Er is iets misgegaan";
60-
// return View();
61-
// } else
62-
// {
63-
// ViewBag.Message = "Het contactformulier is verstuurd";
64-
// }
65-
66-
// return View();
67-
//}
6826
}
6927
}

ShowcaseProject/ShowcaseFrontend/Dockerfile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1-
# Base image with only runtime (for production)
21
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
32
WORKDIR /app
43
EXPOSE 8080
54
EXPOSE 8081
65

7-
# Development stage with full .NET SDK for hot reload
86
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS dev
97
WORKDIR /app
108

11-
# Copy only the project files first to leverage Docker cache
129
COPY ShowcaseFrontend/ShowcaseFrontend.csproj ShowcaseFrontend/
1310
RUN dotnet restore ShowcaseFrontend/ShowcaseFrontend.csproj
1411

15-
# Copy the rest of the source code
1612
COPY ShowcaseFrontend/. ShowcaseFrontend/
1713

1814
WORKDIR /app/ShowcaseFrontend
1915
CMD ["dotnet", "watch", "run", "--project", "/app/ShowcaseFrontend/ShowcaseFrontend.csproj", "--no-launch-profile", "--urls=http://0.0.0.0:80"]
2016

21-
# Build stage for production
2217
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
2318
WORKDIR /src
2419
COPY ["ShowcaseFrontend/ShowcaseFrontend.csproj", "ShowcaseFrontend/"]
@@ -28,11 +23,9 @@ COPY . .
2823
WORKDIR "/src/ShowcaseFrontend"
2924
RUN dotnet build "./ShowcaseFrontend.csproj" -c Release -o /app/build
3025

31-
# Publish stage
3226
FROM build AS publish
3327
RUN dotnet publish "./ShowcaseFrontend.csproj" -c Release -o /app/publish /p:UseAppHost=false
3428

35-
# Final production stage
3629
FROM base AS final
3730
WORKDIR /app
3831
COPY --from=publish /app/publish .

ShowcaseProject/ShowcaseFrontend/Views/Shared/_Layout.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<link rel="stylesheet" href="~/css/gdpr.css" asp-append-version="true" />
1010
<link rel="stylesheet" href="~/css/profilepage.css" asp-append-version="true" />
1111
<link rel="stylesheet" href="~/css/contactpage.css" asp-append-version="true" />
12+
<script src="~/js/components/BoardCell.js"></script>
1213
</head>
1314
<body>
1415
<header>

ShowcaseProject/ShowcaseFrontend/cypress/e2e/game.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('Game Pagina (ingelogd) | Toont game pagina', () => {
1313
cy.visit('http://localhost:8080/login')
1414

1515
cy.get('#username').type('[email protected]')
16-
cy.get('input[type="password"]').type('P@ssw0rd');
16+
cy.get('input[type="password"]').type('P@ssw0rd!1234');
1717

1818
cy.get('button[type="submit"]').click();
1919

ShowcaseProject/ShowcaseFrontend/cypress/e2e/login.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('Correct Inloggen | Email + Uitloggen staat in navbar', () => {
1616
cy.visit('http://localhost:8080/login')
1717

1818
cy.get('#username').type('[email protected]')
19-
cy.get('input[type="password"]').type('P@ssw0rd');
19+
cy.get('input[type="password"]').type('P@ssw0rd!1234');
2020

2121
cy.get('button[type="submit"]').click();
2222

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
class BoardCell extends HTMLElement {
2+
3+
set connection(conn) {
4+
this._connection = conn;
5+
}
6+
7+
constructor() {
8+
super();
9+
this.attachShadow({ mode: "open" });
10+
this.value = " ";
11+
}
12+
13+
async connectedCallback() {
14+
this.renderHtml();
15+
await this.setListeners();
16+
this.shadowRoot.querySelector('.cell').addEventListener('click', this.addClick.bind(this));
17+
}
18+
19+
renderHtml() {
20+
this.shadowRoot.innerHTML = `
21+
<style>
22+
.cell {
23+
border:solid;#333333;1px;
24+
width:50px;
25+
height:50px;
26+
}
27+
</style>
28+
<div class="cell">${this.value}</div>
29+
`
30+
}
31+
32+
async addClick() {
33+
34+
if (this.value === " ") {
35+
const cellIndex = this.getAttribute('index');
36+
const groupName = this.getAttribute('group-name');
37+
const playerSymbol = this.getAttribute('player-symbol');
38+
39+
await this._connection.invoke("SendMove", groupName, playerSymbol, parseInt(cellIndex));
40+
this.renderHtml();
41+
}
42+
}
43+
44+
async setListeners() {
45+
this._connection.on("UpdateBoard", (playerSymbol, position) => {
46+
const targetCell = document.querySelector(`board-cell[index="${position}"]`);
47+
targetCell.setSymbol(playerSymbol);
48+
});
49+
50+
this._connection.on("GameWon", (playerSymbol) => {
51+
document.querySelectorAll("board-cell").forEach(cell => {
52+
cell.innerHTML = " ";
53+
});
54+
55+
const message = `<h1>${playerSymbol} heeft gewonnen!</h1>`;
56+
this.showGameEndPopUp(message);
57+
});
58+
59+
}
60+
61+
setSymbol(symbol) {
62+
this.value = symbol;
63+
this.renderHtml();
64+
}
65+
66+
showGameEndPopUp(message) {
67+
const popup = document.createElement("div");
68+
popup.id = "GameEndPopUp";
69+
popup.innerHTML = message;
70+
popup.style = "z-index: 10;width: 50%;position: absolute;top: 20%;left: 25%;background: #333333;opacity: 0.7;color: white;text-align: center;padding: 1rem;"
71+
72+
const button = document.createElement("button");
73+
button.onclick = () => {
74+
this._connection.stop();
75+
this.hideGameEndPopUp();
76+
location.href = location.href;
77+
};
78+
button.innerHTML = "Terug naar beginscherm.";
79+
popup.appendChild(button);
80+
document.querySelector("body").appendChild(popup);
81+
}
82+
83+
hideGameEndPopUp() {
84+
document.querySelector("#GameEndPopUp").remove();
85+
}
86+
}
87+
88+
customElements.define("board-cell", BoardCell);

ShowcaseProject/ShowcaseFrontend/wwwroot/js/game.js

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
await connection.on("GroupFull", (groupName) => {
4848
alert(groupName + " heeft al het maximum van twee spelers.")
49-
})
49+
});
5050

5151
await connection.on("GroupMade", (groupName, userIds) => {
5252
var groupNameElement = document.querySelector("#GroupName");
@@ -95,6 +95,7 @@
9595
console.error(err);
9696
}
9797
});
98+
9899
function generateGroupName() {
99100

100101
let randomString = (Math.random() + 1).toString(36).substring(7);
@@ -134,58 +135,14 @@
134135
const board = document.querySelector("#GameBoard");
135136
board.setAttribute("style", "display:grid;width: 150px;grid-template-columns: auto auto auto;gap: 5px 5px;");
136137
for (let i = 0; i < 9; i++) {
137-
let span = document.createElement("div");
138-
span.innerHTML = " ";
139-
span.style = "border:solid;#333333;1px;width:50px;height:50px;";
140-
span.id = "cell" + i;
141-
span.onclick = async () => {
142-
let cell = document.getElementById("cell" + i);
143-
if (cell.innerHTML == ' ') {
144-
await connection.invoke("SendMove", groupName, playerSymbol, i);
145-
}
146-
};
147-
148-
149-
board.appendChild(span);
150-
}
151-
}
138+
const boardCell = document.createElement("board-cell");
139+
boardCell.setAttribute("index", i);
140+
boardCell.setAttribute("group-name", groupName);
141+
boardCell.setAttribute("player-symbol", playerSymbol);
152142

153-
connection.on("UpdateBoard", (playerSymbol, position) => {
154-
155-
let cell = document.querySelector("#cell" + position);
156-
cell.innerHTML = playerSymbol;
157-
});
158-
159-
connection.on("GameWon", (playerSymbol) => {
160-
for (let i = 0; i < 9; i++) {
161-
let span = document.getElementById("cell" + i);
162-
span.onclick = null;
143+
boardCell.connection = connection;
144+
board.appendChild(boardCell);
163145
}
164-
165-
const message = "<h1>" + playerSymbol + " heeft gewonnen!" + "</h1>";
166-
167-
showGameEndPopUp(message);
168-
});
169-
170-
function showGameEndPopUp(message) {
171-
const popup = document.createElement("div");
172-
popup.id = "GameEndPopUp";
173-
popup.innerHTML = message;
174-
popup.style = "z-index: 10;width: 50%;position: absolute;top: 20%;left: 25%;background: #333333;opacity: 0.7;color: white;text-align: center;padding: 1rem;"
175-
176-
const button = document.createElement("button");
177-
button.onclick = () => {
178-
connection.stop();
179-
hideGameEndPopUp();
180-
location.href = location.href;
181-
};
182-
button.innerHTML = "Terug naar beginscherm.";
183-
popup.appendChild(button);
184-
document.querySelector("body").appendChild(popup);
185-
}
186-
187-
function hideGameEndPopUp() {
188-
document.querySelector("#GameEndPopUp").remove();
189146
}
190147

191148
async function setupConnection() {
@@ -212,5 +169,3 @@
212169
return connection;
213170
}
214171
});
215-
216-

0 commit comments

Comments
 (0)