DotNet4Neo4j / Neo4j.AspNet.Identity

Custom ASP.NET Identity provider for the Neo4j Graph Database
MIT License
23 stars 17 forks source link

Store does not implement IUserLockoutStore<TUser>. #1

Closed gallarotti closed 9 years ago

gallarotti commented 10 years ago

I am getting the above error when trying to login on a standard MVC 5 project built following your instructions. This is the line of code where the exception happens:

var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);

which belongs to the following method in the AccountController:

    //
    // POST: /Account/Login
    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
    {
        if (!ModelState.IsValid)
        {
            return View(model);
        }

        // This doesn't count login failures towards account lockout
        // To enable password failures to trigger account lockout, change to shouldLockout: true
        var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
        switch (result)
        {
            case SignInStatus.Success:
                return RedirectToLocal(returnUrl);
            case SignInStatus.LockedOut:
                return View("Lockout");
            case SignInStatus.RequiresVerification:
                return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return View(model);
        }
    }
gallarotti commented 10 years ago

I changed the Login to be the following and now it seems to work:

    //
    // POST: /Account/Login
    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
    {
        if (!ModelState.IsValid)
        {
            return View(model);
        }

        ApplicationUser user = await UserManager.FindAsync(model.Email, model.Password);
        if (user != null)
        {
            await SignInAsync(user, model.RememberMe);
            return RedirectToLocal(returnUrl);
        }
        else
        {
            ModelState.AddModelError("", "Invalid username or password.");
            return View(model);
        }
    }
assimoes commented 10 years ago

That's because I actually haven't implemented the IUserLockoutStore in the IdentityUser class. This is only a small sample project on how you can go about persisting your users in a Neo4j database. Shouldn't be too hard to implement that interface...however, I'm currently "afk" in this project for the next week or so (vacations :))

If you'd like to contribute with that code sooner than I, be my guest sir :)

cskardon commented 9 years ago

Current Neo4jUserStore implementation does now implement the IUserLockoutStore<TUser, object> interface.

Please use the code, it's not in nuget yet.