aboutsummaryrefslogtreecommitdiff
path: root/Backend
diff options
context:
space:
mode:
authorTAMARA JERINIC <tamara.jerinic@gmail.com>2022-12-08 14:24:23 +0100
committerTAMARA JERINIC <tamara.jerinic@gmail.com>2022-12-08 14:24:23 +0100
commit6200ad1b4e30f8e6ed3487b79169862fe4ed0572 (patch)
tree8b764b524041d56875253c93182cead70a6a9d07 /Backend
parent97d62835b3e52395022d3f5920ddb1658b9c4c18 (diff)
Dodata funkcija za promenu lozinke na back-u. Povezana promena lozinke na front-u.
Diffstat (limited to 'Backend')
-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/UserService.cs24
3 files changed, 32 insertions, 0 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/UserService.cs b/Backend/Api/Api/Services/UserService.cs
index 2b3f0b8..74c0894 100644
--- a/Backend/Api/Api/Services/UserService.cs
+++ b/Backend/Api/Api/Services/UserService.cs
@@ -733,6 +733,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;
+ }
+
}