alextochetto / 2017.02

Projeto utilizando ASPNET CORE 2 e MongoDB para autenticação de usuários
4 stars 0 forks source link

Where are the commits with changes to a basic project? #2

Open Mech0z opened 6 years ago

Mech0z commented 6 years ago

I cant seem to find the commits that should help me set this up The only change thing I can see you have done is

  1. Create aspnet core 2.0 web page with user account authentication
  2. Add https://www.nuget.org/packages/Contrib.Microsoft.AspNetCore.Identity.MongoDB/
  3. Change this line in startup services.AddIdentityWithMongoStores("myconnectionstring" .AddDefaultTokenProviders();

But when I run this I get

InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[WebApplication1.Models.ApplicationUser]' has been registered.

alextochetto commented 6 years ago

@Mech0z your sequence it's nice, but you need to use this project: https://github.com/alextochetto/aspnetcore-identity-mongodb

Mech0z commented 6 years ago

I cloned your sample project and got it compiling and running but I cant do as said in the readme

`    public class HomeController : Controller
    {
        private readonly IServiceProvider _provider;

        public HomeController(IServiceProvider provider)
        {
            _provider = provider;
        }
        public async Task<IActionResult> Index()
        {
            var userManager = _provider.GetService<UserManager<IdentityUser>>();
            var result = await userManager.Users.ToListAsync();
            return View();
        }`

If I do, then userManager is null and I get an exception when I call userManager.Users

https://github.com/Mech0z/Foosball/blob/master/FoosballService/Controllers/HomeController.cs

alextochetto commented 6 years ago

@Mech0z did you create an account at mLab or any other mongodb server? Did you change the connection string in appsettings.json file configuration?

Mech0z commented 6 years ago

Yes I just use a test databse https://github.com/Mech0z/Foosball/tree/master/FoosballService and I can create a user and login just fine, I just cant do these commands which are in the Readme.md

var userManager = provider.GetService<UserManager<IdentityUser>>();
var roleManager = provider.GetService<RoleManager<IdentityRole>>();