aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/api/api/Controllers/DatasetController.cs10
-rw-r--r--backend/api/api/Models/JwtToken.cs28
-rw-r--r--backend/api/api/appsettings.json5
3 files changed, 13 insertions, 30 deletions
diff --git a/backend/api/api/Controllers/DatasetController.cs b/backend/api/api/Controllers/DatasetController.cs
index d022d6d2..fcebc4b0 100644
--- a/backend/api/api/Controllers/DatasetController.cs
+++ b/backend/api/api/Controllers/DatasetController.cs
@@ -32,12 +32,12 @@ namespace api.Controllers
var dataset = _datasetService.GetOneDataset(id, name);
if (dataset == null)
- return NotFound($"Dataset with name = {name} not found");
+ return NotFound($"Dataset with name = {name} or user with id = {id} not found");
return dataset;
}
- // POST api/<DatasetController>
+ // POST api/<DatasetController>/post
[HttpPost("post")]
public ActionResult<Dataset> Post([FromBody] Dataset dataset)
{
@@ -53,7 +53,7 @@ namespace api.Controllers
}
}
- // PUT api/<DatasetController>/5
+ // PUT api/<DatasetController>/{id}/{name}
[HttpPut("{id}/{name}")]
public ActionResult Put(string id, string name, [FromBody] Dataset dataset)
{
@@ -61,7 +61,7 @@ namespace api.Controllers
//ne mora da se proverava
if (existingDataset == null)
- return NotFound($"Dataset with name = {name} not found");
+ return NotFound($"Dataset with name = {name} or user with id = {id} not found");
_datasetService.Update(id, name, dataset);
return NoContent();
@@ -74,7 +74,7 @@ namespace api.Controllers
var dataset = _datasetService.GetOneDataset(id, name);
if (dataset == null)
- return NotFound($"Dataset with name = {name} not found");
+ return NotFound($"Dataset with name = {name} or user with id = {id} not found");
_datasetService.Delete(dataset.uploaderId,dataset.name);
diff --git a/backend/api/api/Models/JwtToken.cs b/backend/api/api/Models/JwtToken.cs
index 31ecca10..7cbd6f54 100644
--- a/backend/api/api/Models/JwtToken.cs
+++ b/backend/api/api/Models/JwtToken.cs
@@ -33,31 +33,13 @@ namespace api.Models
public string RenewToken(string existingToken)
{
- if (existingToken == null)
+ var userName = TokenToUsername(existingToken);
+ if (userName == null)
return null;
- var tokenHandler = new JwtSecurityTokenHandler();
- var key= Encoding.ASCII.GetBytes(_configuration.GetSection("AppSettings:JwtToken").Value);
- try
- {
- tokenHandler.ValidateToken(existingToken, new TokenValidationParameters
- {
- ValidateIssuerSigningKey = true,
- IssuerSigningKey = new SymmetricSecurityKey(key),
- ValidateIssuer = false,
- ValidateAudience = false,
- }, out SecurityToken validatedToken);
-
- var jwtToken = (JwtSecurityToken)validatedToken;
- var userName =jwtToken.Claims.First(x => x.Type == "name").Value;
- var authUser = new AuthRequest();
- authUser.UserName = userName;
+ var authUser = new AuthRequest();
+ authUser.UserName = userName;
- return GenToken(authUser);
- }
- catch
- {
- return null;
- }
+ return GenToken(authUser);
}
diff --git a/backend/api/api/appsettings.json b/backend/api/api/appsettings.json
index 3661f171..9b4f00a3 100644
--- a/backend/api/api/appsettings.json
+++ b/backend/api/api/appsettings.json
@@ -13,11 +13,12 @@
/* LocalHost
"ConnectionString": "mongodb://127.0.0.1:27017/",
"DatabaseName": "si_project",
- "CollectionName": "User"
+ "CollectionName": "User",
+ "DatasetCollectionName" : "Dataset"
*/
"ConnectionString": "mongodb+srv://si_user:si_user@sidatabase.twtfm.mongodb.net/myFirstDatabase?retryWrites=true&w=majority",
"DatabaseName": "si_db",
"CollectionName": "users",
- "DatasetCollectionName" : "Dataset"
+ "DatasetCollectionName": "Dataset"
}
}