Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No exception handling on claims controller Index... #41

Open
mdelgadov opened this issue May 14, 2014 · 0 comments
Open

No exception handling on claims controller Index... #41

mdelgadov opened this issue May 14, 2014 · 0 comments
Labels

Comments

@mdelgadov
Copy link

In the ClaimsIdentityFactoryController, Index method, there is no exception handling for an invalid userid/password.
I tried to use the same implementation than in the accounts controller, but the Return View(model) doesn't work because is not the Index view, but the Login view.

I tried the following code but can't be sure is ok...
public class ClaimsIdentityFactoryController : Controller
{

    // POST: /Account/Login
    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    // GET: ClaimsIdentityFactory
    public async Task<ActionResult> Index(LoginViewModel model, string returnUrl)
    {
        if (ModelState.IsValid)
        {

            var context = new DbContext();
            var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context))
            {
                ClaimsIdentityFactory = new oEazyClaimsIdentityFactory<ApplicationUser>()
            };

            // Create a User to SignIn
            var user = await userManager.FindAsync(model.Email, model.Password);
            if (user != null)
            {
                //SignIn the User by generating a ClaimsIdentity            
                var claimsIdentity =
                    await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);

                // This claimsIdentity should have a claim called LastLoginTime
                var authManager = HttpContext.GetOwinContext().Authentication;
                authManager.SignIn(claimsIdentity);

                return RedirectToLocal(returnUrl);
            }

            ModelState.AddModelError("", "Invalid username or password.");
        }
        // If we got this far, something failed, redisplay form
        return View("_LoginPartial");
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants