コード例 #1
0
ファイル: UsersController.cs プロジェクト: DroneDB/Registry
        public async Task <IActionResult> ChangePasswordPost([FromForm] string oldPassword,
                                                             [FromForm] string newPassword)
        {
            try
            {
                _logger.LogDebug("Users controller ChangePasswordPost('XXX','XXX')");

                var res = await _usersManager.ChangePassword(oldPassword, newPassword);

                var auth = await _usersManager.Authenticate(res.UserName, res.Password);

                return(Ok(auth));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Exception in Users controller ChangePasswordPost('XXX','XXX')");

                return(ExceptionResult(ex));
            }
        }
コード例 #2
0
        public async Task <IActionResult> ChangePassword([FromForm] ChangeUserPasswordRequest model)
        {
            try
            {
                _logger.LogDebug("Users controller ChangePassword('{UserName}')", model?.UserName);

                if (model == null)
                {
                    return(BadRequest(new ErrorResponse("No user data provided")));
                }

                await _usersManager.ChangePassword(model.UserName, model.CurrentPassword, model.NewPassword);

                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Exception in Users controller ChangePassword('{UserName}')", model?.UserName);

                return(ExceptionResult(ex));
            }
        }