aboutsummaryrefslogtreecommitdiff
path: root/Backend/Api
diff options
context:
space:
mode:
Diffstat (limited to 'Backend/Api')
-rw-r--r--Backend/Api/Api/Controllers/UserController.cs6
-rw-r--r--Backend/Api/Api/Interfaces/IUserService.cs2
-rw-r--r--Backend/Api/Api/Services/PostService.cs6
-rw-r--r--Backend/Api/Api/Services/UserService.cs24
4 files changed, 37 insertions, 1 deletions
diff --git a/Backend/Api/Api/Controllers/UserController.cs b/Backend/Api/Api/Controllers/UserController.cs
index 73d32ea..30beac4 100644
--- a/Backend/Api/Api/Controllers/UserController.cs
+++ b/Backend/Api/Api/Controllers/UserController.cs
@@ -162,6 +162,12 @@ namespace Api.Controllers
return Ok(await _userService.ChangeMyProfileName(newName));
}
+ [HttpPost("changePass")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<int>> ChangePass(string currentPass, string newPass)
+ {
+ return Ok(await _userService.ChangePass(currentPass,newPass));
+ }
}
diff --git a/Backend/Api/Api/Interfaces/IUserService.cs b/Backend/Api/Api/Interfaces/IUserService.cs
index f4954e0..855272f 100644
--- a/Backend/Api/Api/Interfaces/IUserService.cs
+++ b/Backend/Api/Api/Interfaces/IUserService.cs
@@ -40,6 +40,8 @@ namespace Api.Interfaces
Task<int> ChangeMyProfileUsername(String newUsername);
Task<bool> ChangeMyProfileName(String newUsername);
+ Task<int> ChangePass(string currentPass, string newPass);
+
}
}
diff --git a/Backend/Api/Api/Services/PostService.cs b/Backend/Api/Api/Services/PostService.cs
index cb59330..0799f10 100644
--- a/Backend/Api/Api/Services/PostService.cs
+++ b/Backend/Api/Api/Services/PostService.cs
@@ -162,7 +162,11 @@ namespace Api.Services
tosend.ratingscount = ps.ratingscount;
if (p.ownerId == userid)
- return null;
+ {
+ tosend.myrating = -1;
+ return tosend;
+ }
+
if(rating.rating == 0)// ako nema rating staviti 0
{
var r = p.ratings.Find(x => x.userId == userid);
diff --git a/Backend/Api/Api/Services/UserService.cs b/Backend/Api/Api/Services/UserService.cs
index 98938c0..d8ec4a2 100644
--- a/Backend/Api/Api/Services/UserService.cs
+++ b/Backend/Api/Api/Services/UserService.cs
@@ -741,6 +741,30 @@ namespace Api.Services
return false;
}
+ public async Task<int> ChangePass(string currentPass,string newPass)
+ {
+
+ string myId = null;
+ if (_httpContext.HttpContext.User.FindFirstValue("id") != null)
+ {
+ myId = _httpContext.HttpContext.User.FindFirstValue("id").ToString();
+ }
+
+ User u = await _users.Find(user => user._id == myId).FirstOrDefaultAsync();
+
+ if (u != null)
+ {
+ if (checkPassword(currentPass, u.password))
+ {
+ u.password = hashPassword(newPass);
+ await _users.ReplaceOneAsync(x => x._id == u._id, u);
+ return 1;
+ }
+ return -1;
+ }
+ return -2;
+ }
+
}