예제 #1
0
        public ActionResult Login(User input)
        {
            if (ModelState.IsValid)
            {
                using (BlogDBContext db = new BlogDBContext())
                {
                    var authUser = db.Members.Any(u => u.Username == input.Username && u.Password == input.Password);
                    if(authUser)
                    {
                        var identity = new ClaimsIdentity(new[]
                            {
                            new Claim(ClaimTypes.Name, input.Username),
                            },
                        DefaultAuthenticationTypes.ApplicationCookie,
                        ClaimTypes.Name, ClaimTypes.Role);

                        identity.AddClaim(new Claim(ClaimTypes.Role, "guest"));

                        Authentication.SignIn(identity);
                        return RedirectToAction("index", "blogs");
                    }
                }
            }

            return View("Login", input);
        }
예제 #2
0
 public ActionResult Index()
 {
     using (var db = new BlogDBContext())
     {
         return View(db.Blogs.OrderByDescending(b => b.CreatedDate).ToList());
     }
 }