Beispiel #1
0
 public ActionResult Login(Users users, string ReturnUrl)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     using (DbContextSln sln = new DbContextSln())
     {
         Users authUser = sln.dbUsers.FirstOrDefault(x => x.username == users.username);
         if (authUser == null)
         {
             ViewData["warning1"] = "Wrong Username, Please try again";
             return(View(users));//provide this so taht user dont have to type again and agian.
         }
         if (authUser.password.ToLower() != CalculateMD5Hash(users.password).ToLower())
         {
             ViewData["warning2"] = "Wrong Password, Please try again";
             return(View(users));
         }
         FormsAuthentication.SetAuthCookie(authUser.username, false);//persistent cookie for 2nd value...remember me check box
         FormsAuthentication.SetAuthCookie(Convert.ToString(authUser.user_id), false);
         var    authTicket      = new FormsAuthenticationTicket(1, authUser.username, DateTime.Now, DateTime.Now.AddMinutes(20), false, authUser.Roles);
         string encryptedTicket = FormsAuthentication.Encrypt(authTicket);
         var    authCookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
         HttpContext.Response.Cookies.Add(authCookie);
         return(RedirectToAction("OrderItem", "Department"));
     }
 }
 public ActionResult OrderItem()
 {
     using (DbContextSln dbsol = new DbContextSln())
     {
         List <Items> list = dbsol.orderItems.ToList();
         //var groups = dbsol.orderItems.GroupBy(x => x.Category, i => i,
         //    (key,v)=> new Items { Category = key, Name = v}).ToList();
         ViewData["uname"] = User.Identity.Name;
         return(View(list));
     }
 }
 public ActionResult Delegate()
 {
     using (DbContextSln users = new DbContextSln())
     {
         List <Users> user = users.dbUsers.ToList();
         ViewData["uname"] = User.Identity.Name;
         Debug.WriteLine(User.Identity.ToString());
         Debug.WriteLine(User.Identity.Name);
         Debug.WriteLine(User.Identity.IsAuthenticated);
         ViewData["users"] = user;
     }
     return(View());
 }