Ejemplo n.º 1
0
        public ActionResult Login(User user)
        {
            string passwordHash = Helper.GetSHA512Hash(user.Password);

            using (LoginDataModelContainer db = new LoginDataModelContainer())
            {
                var dbUser = db.Users.SingleOrDefault(x => x.Username == user.Username && x.Password == passwordHash);
                if (dbUser != null)
                {
                    FormsAuthentication.SetAuthCookie(user.Username, true);
                    

                    dbUser.Roles.Clear();
                    dbUser.Roles = (from role in db.Roles
                                    join userRole in user.SelectedRoles on role.Id equals userRole
                                    select role).ToList();
                    db.SaveChanges();
                    return RedirectToAction("Index");


                }
            }

            ModelState.AddModelError("LoginError", "Login failed");
            return View(user);
        }
Ejemplo n.º 2
0
 public ActionResult Login()
 {
     using (LoginDataModelContainer db = new LoginDataModelContainer())
     {
         User user = new User();
         ViewBag.Roles = db.Roles.ToList();
         return View(user);
     }
 }
Ejemplo n.º 3
0
 public ActionResult Create(User user)
 {
     return RedirectToAction("Index");
 }