Giter Site home page Giter Site logo

Comments (3)

browrp avatar browrp commented on June 20, 2024 1

@x19chen OpenIddict uses ASP.Net Core Identity for user management. You wouldn't necessarily use OpenIddict-ui to allow a user to change their own password; openiddict-ui is for an admin role not a user role.

You can most likely use some of the existing ASP.Net Core Identity functionality to do this. You would just need to write an api endpoint that allows a user to change their password similar to how the existing ASP.Net Core Identity functionality does it.

If you've generated all the Identity code for your project you should have a ChangePassword page somewhere in your solution. For example there is a Change Password page which is most likely located under Areas/Identity/Pages/Account/Manage/ChangePassword. You can see how this is done via the existing ASP.Net Core web application using the following code:

    public async Task<IActionResult> OnPostAsync()
    {
        if (!ModelState.IsValid)
        {
            return Page();
        }

        var user = await _userManager.GetUserAsync(User);
        if (user == null)
        {
            return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
        }

        var changePasswordResult = await _userManager.ChangePasswordAsync(user, Input.OldPassword, Input.NewPassword);
        if (!changePasswordResult.Succeeded)
        {
            foreach (var error in changePasswordResult.Errors)
            {
                ModelState.AddModelError(string.Empty, error.Description);
            }
            return Page();
        }

        await _signInManager.RefreshSignInAsync(user);
        _logger.LogInformation("User changed their password successfully.");
        StatusMessage = "Your password has been changed.";

        return RedirectToPage();
    }
}

All you will need to do is create an api endpoint that requires authentication and allows the authenticated user to pass in the data to change their password.

Let me know if this helps.

-Robert

from openiddict-ui.

thomasduft avatar thomasduft commented on June 20, 2024

@browrp Thanks for answering the question of @x19chen. I couldn't have done it better 👍.

@x19chen For some inspiration you could have a look here or as @browrp mentioned have a look at ASP.NET Core Identity samples.

Have a nice weekend both.

Thomas

from openiddict-ui.

 avatar commented on June 20, 2024

@browrp @thomasduft
Thanks for your answer, that was indeed helpful.
It actually confirms my suspicion that I have to create another API for that and the example is clear.

Enjoy your weekend.

Xiaoyang

from openiddict-ui.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.