diff options
author | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-12-08 14:33:39 +0100 |
---|---|---|
committer | Ognjen Cirkovic <ciraboxkg@gmail.com> | 2022-12-08 14:33:39 +0100 |
commit | f9d930da33a4a31aac2578b9943271d6340623d2 (patch) | |
tree | e9a77ac5218292c4a93458db5e028c9ee6a897f5 /Backend | |
parent | a3dbcdcfbe171ea84fe6870d2d49bf95fe9de148 (diff) | |
parent | 12677dfc9558c7eecad158b5620b4640a67e06b3 (diff) |
Merge branch 'develop' of http://gitlab.pmf.kg.ac.rs/BrzoDoLokacije2022/odyssey/brzodolokacije into develop
# Conflicts:
# Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivityChangePassword.kt
# Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Activities/ActivitySinglePost.kt
# Client/BrzoDoLokacije/app/src/main/java/com/example/brzodolokacije/Fragments/FragmentMyProfileInfo.kt
Diffstat (limited to 'Backend')
-rw-r--r-- | Backend/Api/Api/Controllers/UserController.cs | 6 | ||||
-rw-r--r-- | Backend/Api/Api/Interfaces/IUserService.cs | 2 | ||||
-rw-r--r-- | Backend/Api/Api/Services/PostService.cs | 6 | ||||
-rw-r--r-- | Backend/Api/Api/Services/UserService.cs | 24 |
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; + } + } |