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 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; + } + } |