From 3e39569edb66ea5d5de3774f22f078d90297bc0f Mon Sep 17 00:00:00 2001 From: Meghan Date: Tue, 21 May 2024 16:11:35 -0700 Subject: [PATCH] Make authenticated get endpoint --- .../Wordle.Api/Controllers/WordController.cs | 13 ++++++- wordle-web/pages/index.vue | 34 +++++++++++++------ wordle-web/scripts/tokenService.ts | 4 +++ 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/Wordle.Api/Wordle.Api/Controllers/WordController.cs b/Wordle.Api/Wordle.Api/Controllers/WordController.cs index e580c9fd..8bcac50b 100644 --- a/Wordle.Api/Wordle.Api/Controllers/WordController.cs +++ b/Wordle.Api/Wordle.Api/Controllers/WordController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; using Wordle.Api.Services; namespace Wordle.Api.Controllers; @@ -24,4 +25,14 @@ public async Task GetWordOfDay(double offsetInHours = -7.0) DateOnly today = DateOnly.FromDateTime(DateTime.UtcNow.AddHours(offsetInHours)); return await wordOfTheDayService.GetWordOfTheDay(today); } + + [Authorize] + [HttpGet("WordOfTheDayHint")] + public async Task GetWordOfDayHint(double offsetInHours = -7.0) + { + DateOnly today = DateOnly.FromDateTime(DateTime.UtcNow.AddHours(offsetInHours)); + var wordOfTheDay = await wordOfTheDayService.GetWordOfTheDay(today); + + return wordOfTheDay.Substring(0, 1) + "___" + wordOfTheDay.Substring(4,1); + } } diff --git a/wordle-web/pages/index.vue b/wordle-web/pages/index.vue index a7da6196..5abb8cfa 100644 --- a/wordle-web/pages/index.vue +++ b/wordle-web/pages/index.vue @@ -25,9 +25,7 @@ {{ game.stats.winPercentage }} %
- - Success Rate - + Success Rate - {{ game.stats.averageGuessesPercent(game.maxAttempts).toFixed(0) }} % + {{ + game.stats.averageGuessesPercent(game.maxAttempts).toFixed(0) + }} + %
- - Average Guesses - + Average Guesses
@@ -59,14 +58,20 @@ - - Guess! - +
+ + Guess! + +
+ Hint! 👀 +
diff --git a/wordle-web/scripts/tokenService.ts b/wordle-web/scripts/tokenService.ts index 20516cdd..cb140c30 100644 --- a/wordle-web/scripts/tokenService.ts +++ b/wordle-web/scripts/tokenService.ts @@ -22,4 +22,8 @@ export default class TokenService { console.log(JSON.parse(atob(token.split(".")[1]))); return JSON.parse(atob(token.split(".")[1])).userName; } + + public generateTokenHeader(){ + return { 'Authorization': `Bearer ${this.getToken()}`} + } }