diff options
Diffstat (limited to 'Backend/Api/Api/Services/UserService.cs')
-rw-r--r-- | Backend/Api/Api/Services/UserService.cs | 24 |
1 files changed, 24 insertions, 0 deletions
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; + } + } |