aboutsummaryrefslogtreecommitdiff
path: root/backend/api
diff options
context:
space:
mode:
authorIvan Ljubisavljevic <ivan996sk@gmail.com>2022-03-21 16:31:12 +0100
committerIvan Ljubisavljevic <ivan996sk@gmail.com>2022-03-21 16:31:12 +0100
commita77c7bff39574428953c162b17d4dee1113e68f7 (patch)
tree40cc8e579381a5ef2d3dc459a1136d7bfc79dd4b /backend/api
parent255d683fb4f2e3d341fe41537691b0924aa80f46 (diff)
api za myprofilepage
Diffstat (limited to 'backend/api')
-rw-r--r--backend/api/api/Controllers/UserController.cs31
1 files changed, 26 insertions, 5 deletions
diff --git a/backend/api/api/Controllers/UserController.cs b/backend/api/api/Controllers/UserController.cs
index 58121656..dcab53cc 100644
--- a/backend/api/api/Controllers/UserController.cs
+++ b/backend/api/api/Controllers/UserController.cs
@@ -2,7 +2,9 @@
using api.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.Net.Http.Headers;
using System.Diagnostics;
+using System.Net.Http.Headers;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
//dovrsi kontroler
@@ -13,10 +15,12 @@ namespace api.Controllers
public class UserController : ControllerBase
{
private readonly IUserService userService;
+ private JwtToken jwtToken;
- public UserController(IUserService userService)
+ public UserController(IUserService userService, IConfiguration configuration)
{
this.userService = userService;
+ jwtToken = new JwtToken(configuration);
}
// GET: api/<UserController>
@@ -38,12 +42,29 @@ namespace api.Controllers
return user;
}
- /*
+
+
+
+
// GET api/<UserController>/5
//potrebno za profile page
- [HttpGet("{id}")]
- public ActionResult<User> GetUserUsername(string username)
+ [HttpGet("myprofile")]
+ [Authorize(Roles = "User")]
+ public ActionResult<User> MyProfilePage()
{
+ string username;
+ var header = Request.Headers[HeaderNames.Authorization];
+ if (AuthenticationHeaderValue.TryParse(header, out var headerValue))
+ {
+ var scheme = headerValue.Scheme;
+ var parameter = headerValue.Parameter;
+ username = jwtToken.TokenToUsername(parameter);
+ if (username == null)
+ return null;
+ }
+ else
+ return BadRequest();
+
var user = userService.GetUserUsername(username);
if (user == null)
@@ -51,7 +72,7 @@ namespace api.Controllers
return user;
}
- */
+
// POST api/<UserController>
[HttpPost]
public ActionResult<User> Post([FromBody] User user)