0

I must admit, I'm newbie to MVC.. so everything is kind of like a black magic right now.

This is the code

        public ActionResult LogIn(Models.profile profile)
    {
        if (ModelState.IsValid)
        {
            if(IsValid(profile.profile_email, profile.profile_password))
            {
                var db = new DatabaseContext();
                var _id = db.profile.Where(u => u.profile_email == profile.profile_email).Select(n => n.profile_id).FirstOrDefault();
                var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Email, profile.profile_email),
                                                          new Claim(ClaimTypes.Name, _id.ToString())}, 
                                                          "ApplicationCookie");
                var ctx = Request.GetOwinContext();
                var authmngr = ctx.Authentication;

                authmngr.SignIn(identity);

                return RedirectToAction("LogIn", "Main");
            } else
            {
                ModelState.AddModelError("", "Something goes wrong");
            }
        }

        return View(profile);
    }

I've managed to login with the identity thing, which was quite hard @_ @ The thing was that those claimtype are not too flexible from what I've seen. I mean I have to choose something from the list and I kind just pick my own properties or something.

So, I decided to store current user ID in the ClaimTypes.Name. Not sure if it is any of the good idea. I'm not even sure if the whole login pattern is any viable ;o

But... to the point. How do I retrieve user infos with just this claim if there would be no user id in there? Or how could I retrieve users info from database at all with using claims identity?

If there is anything I should add, please let me know ;3

Harugawa
  • 539
  • 5
  • 19

0 Answers0