Exemple #1
0
        // 詳細資訊
        public ActionResult Detail(long RecordID)
        {
            RepositoryUser repo = new RepositoryUser();
            UserViewModel  data = repo.GetUserViewModel(RecordID);

            return(data == null?PartialView("_Error") : PartialView("_Detail", data));
        }
        // 帳號設定首頁
        public ActionResult Index()
        {
            RepositoryUser repo = new RepositoryUser();
            AuthModel      auth = RepositoryAuthModel.GetAuthModel(HttpContext.User.Identity as FormsIdentity);
            UserViewModel  data = repo.GetUserViewModel(auth.ID);

            return(data == null?View("Error") : View(data));
        }
Exemple #3
0
        public ActionResult Login(LoginMD Data)
        {
            RepositoryUser repo = new RepositoryUser();
            UserViewModel  user = repo.GetUserViewModel(new User {
                Phone = Data.Phone
            });

            // 驗證帳號
            if (user == null)
            {
                TempData["ErrMsg"] = "登入失敗 : 帳號錯誤";
                return(RedirectToAction("Login", "Home"));
            }

            // 驗證密碼
            if (!Data.UserPwd.Equals(user.UserPwd))
            {
                TempData["ErrMsg"] = "登入失敗 : 密碼錯誤";
                return(RedirectToAction("Login", "Home"));
            }

            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                1,
                user.Name,
                DateTime.Now,
                DateTime.Now.AddMinutes(30),
                true,
                JsonConvert.SerializeObject(new AuthModel {
                ID = user.RecordID, Name = user.Name, Phone = user.Phone, AuthLevel = user.AuthLevel
            }),
                FormsAuthentication.FormsCookiePath
                );

            string     encTicket = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);

            cookie.HttpOnly = true;
            Response.Cookies.Add(cookie);

            return(RedirectToAction("Index", "Home"));
        }