コード例 #1
0
        public ActionResult Login(MemberModel.LoginModel login, string returnUrl, int time_offset)
        {
            if (ModelState.IsValid)
            {
                var account = data.Get_One(login.UserName, login.Password);
                if (account == null)
                {
                    LoginRecordModel.Login_Record(login.UserName, Request, false);
                    TempData["err"] = "使用者名稱或密碼不正確";
                    return View();
                }
                Session.RemoveAll();
                var competence = data.Get_Competence(account.Level);
                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                    account.Id == 0 ? s26web.Models.Method.CookieVersion_Admin : s26web.Models.Method.CookieVersion_Home,
                    login.UserName,
                    DateTime.UtcNow,
                    DateTime.UtcNow.AddMinutes(60),
                    login.RememberMe,
                    account.Name + "," + account.Password,
                    FormsAuthentication.FormsCookiePath);

                string encTicket = FormsAuthentication.Encrypt(ticket);

                Response.Cookies.Add(new HttpCookie(s26web.Models.Method.CookieName_Admin, encTicket));
                Response.Cookies[s26web.Models.Method.CookieName_Admin].Path = "/";
                Session.Add(s26web.Models.Method.SessionUserId_Admin, account.Id);
                Session.Add(s26web.Models.Method.SessionUserAccount_Admin, account.Account_Phone);
                Session.Add(s26web.Models.Method.SessionUserName_Admin, account.Name);
                Session.Add(s26web.Models.Method.SessionLevel_Admin, account.Level);
                Session.Add(s26web.Models.Method.SessionComptpence, competence);
                Session.Add(s26web.Models.Method.SessionLevelName_Admin, account.Level_Name);
                Session.Add(s26web.Models.Method.SessionUserAccount_Admin, account.Enable);
                LoginRecordModel.Login_Record(login.UserName, Request, true);
                return RedirectToLocal(returnUrl);
            }
            if (login.UserName != null)
            {
                LoginRecordModel.Login_Record(login.UserName, Request, false);
            }
            return View();
        }
コード例 #2
0
        private void LoginSession(HttpContextBase httpContext, MemberModel.MemberShow item)
        {
            MemberModel data = new MemberModel();

            var competence = data.Get_Competence(item.Level);
            httpContext.Session.RemoveAll();

            httpContext.Session.Add(Method.SessionUserId_Admin, item.Id);
            httpContext.Session.Add(Method.SessionUserAccount_Admin, item.Account_Phone);
            httpContext.Session.Add(Method.SessionUserName_Admin, item.Name);
            httpContext.Session.Add(Method.SessionLevel_Admin, item.Level);
            httpContext.Session.Add(Method.SessionLevelName_Admin, item.Level_Name);
            httpContext.Session.Add(Method.SessionUserAccount_Admin, item.Enable);
            httpContext.Session.Add(Method.SessionComptpence, competence);
        }
コード例 #3
0
        private void LoginCookie(HttpContextBase httpContext, MemberModel.MemberShow item, bool RememberMe)
        {
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                item.Id == 0 ? Method.CookieVersion_Admin : Method.CookieVersion_Home,
                item.Account_Phone,
                DateTime.UtcNow,
                DateTime.UtcNow.AddMinutes(60),
                RememberMe,
                item.Name + "," + item.Password,
                FormsAuthentication.FormsCookiePath);

            string encTicket = FormsAuthentication.Encrypt(ticket);

            httpContext.Response.Cookies.Add(new HttpCookie(Method.CookieName_Admin, encTicket));
            httpContext.Response.Cookies[Method.CookieName_Admin].Path = "/";
        }
コード例 #4
0
 public ActionResult CategoryEdit(MemberModel.UserLevelShow aItem, int p = 1)
 {
     if (ModelState.IsValid)
     {
         var item = data.Get_UserLevel_One(aItem.Id);
         if (item == null)
         {
             TempData["err"] = "Member_12";
             return RedirectToAction("Category");
         }
         int result = data.Update_UserLevel(aItem);
         if (result < 0)
         {
             TempData["err"] = "Member_13";
             return RedirectToAction("Category");
         }
     }
     return RedirectToAction("Category", new { p = p });
 }
コード例 #5
0
 public ActionResult CategoryCreate(MemberModel.UserLevelShow item)
 {
     try
     {
         if (ModelState.IsValid)
         {
             data.Insert_UserLevel(item);
         }
         else
         {
             TempData["err"] = "Member_10";
         }
     }
     catch { TempData["err"] = "Member_11"; }
     return RedirectToAction("Category");
 }
コード例 #6
0
        public ActionResult Edit(MemberModel.MemberShow aItem, int p = 1)
        {
            if (ModelState.IsValid)
            {
                var item = data.Get_One(aItem.Id);

                if (item == null)
                {
                    TempData["err"] = "Member_4";
                    return RedirectToAction("Index");
                }

                int result = data.Update(aItem);

                if (result <= 0)
                {
                    TempData["err"] = "Member_5";
                    return RedirectToAction("Index");
                }
            }

            return RedirectToAction("Index", new { p = p });
        }
コード例 #7
0
        public ActionResult Create(MemberModel.MemberShow item)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (item.Level == 0)
                    {
                        TempData["err"] = "Member_0,請選擇群組權限";
                    }
                    else if (Regex.IsMatch(item.Account_Phone, @"[\W_]+"))
                    {
                        TempData["err"] = "Member_1,帳號請勿使用特殊字元";
                    }
                    else
                    {
                        if (data.Insert(item) <= 0)
                        {
                            TempData["err"] = "Member_2,帳號新增失敗(請避免帳號重複)";
                        }
                    }
                }
                else
                {
                    TempData["err"] = "Member_3,帳號新增失敗(請輸入完整資訊)";
                }
            }
            catch { TempData["err"] = "Member_4,帳號新增失敗(請輸入完整資訊)"; }

            if (TempData["err"] != null)
            {
                return RedirectToAction("Create");
            }
            return RedirectToAction("Index");
        }