Пример #1
0
        public ActionResult Login(string Account, string PD, bool remember)
        {
            客戶資料 client = repo.FindAccount(Account, PD);

            if (client != null)
            {
                string userData = client.Role;
                if (string.IsNullOrEmpty(userData))
                {
                    userData = "normal";
                }
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket
                                                       (1, Account, DateTime.Now, DateTime.Now.AddMinutes(60), false, userData);
                string encTicket = FormsAuthentication.Encrypt(ticket);
                Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));

                if (remember)
                {
                    HttpCookie cookie = new HttpCookie("mvc_coures_remember");
                    cookie.Value   = LoginViewModel.Encrypt(Account);
                    cookie.Expires = DateTime.Now.AddDays(7);
                    Response.Cookies.Add(cookie);
                }

                return(RedirectToAction("Index", "Home"));
            }
            return(View("Index"));
        }
Пример #2
0
 public ActionResult Index()
 {
     try
     {
         string name   = ((FormsIdentity)User.Identity).Ticket.Name;
         客戶資料   client = repo.FindAccount(name);
         if (client != null)
         {
             return(View(client));
         }
     }
     catch
     {
     }
     return(RedirectToAction("Index", "Home"));
 }
Пример #3
0
 public ActionResult EditProfile()
 {
     return(View(CompanyRepo.FindAccount(User.Identity.Name)));
 }