Esempio n. 1
0
 public ActionResult UserLogin()
 {
     //檢查是否有登入過會員
     if (string.IsNullOrEmpty(Method.getSessionAccount_Val))
     {
         bool   isError  = false;
         string userName = Request.Form["userName"].ToString().Trim();
         string password = Request.Form["password"].ToString().Trim();
         //判斷欄位是否空值
         Method.ValueIsEmpty(userName);
         Method.ValueIsEmpty(password);
         //獲取結果
         isError = Method.ValueIsEmpty_Val;
         if (isError)
         {
             return(Redirect(Method.RedirectUrl));
         }
         user_Tb objItem = Server_User_P.GetUserInfo_Md(userName);
         TempData[InternalVal._RESULTMSG] = "登入會員失敗!";
         //確認是否有該用戶
         if (objItem == null)
         {
             return(RedirectToAction("ResultMessage", "Home"));
         }
         else if (!objItem.password.Equals(Method.GetMD5_Md(password)))
         {
             //檢查密碼
             TempData[InternalVal._RESULTMSG] = "帳號或密碼錯誤!";
         }
         if (objItem.account == userName && objItem.password.Equals(Method.GetMD5_Md(password)))
         {
             HttpCookie cookie = new HttpCookie(InternalVal._COOKIEUSERINFO);
             cookie.Values.Add(InternalVal._COOKIEACCOUNT, userName);
             cookie.Values.Add(InternalVal._COOKIEANAME, objItem.username);
             cookie.Values.Add("userVerify", Method.GetMD5HashPassword_Md(objItem.password));
             //cookie保存2天
             cookie.Expires = DateTime.Now.AddDays(2);
             Response.Cookies.Add(cookie);
             HttpCookie UserSession = new HttpCookie("UserSession");
             UserSession.Values.Add("TestSessionID", Session.SessionID);
             Session[InternalVal._SESSIONACCOUNT] = objItem.account;
             Session[InternalVal._SESSIONNAME]    = objItem.username;
             cookie.Expires = DateTime.Now.AddDays(2);
             Response.Cookies.Add(UserSession);
             //給予SessionID
             //Session["sessionID"] = Session.SessionID + userName;
             //Session["sessionIdCompare"] = Session.SessionID + userName;
             TempData[InternalVal._RESULTMSG] = Session[InternalVal._SESSIONACCOUNT] + " 已成功登入會員!";
         }
     }
     //Method.RedirectUrl = "~/Home/Index";
     //return View();
     return(RedirectToAction("ResultMessage", "Home"));
 }
Esempio n. 2
0
        /// <summary>
        /// 討論版文章列表
        /// </summary>
        /// <param name="board"></param>
        /// <param name="theme"></param>
        /// <returns></returns>
        public ActionResult BoardArticle(int?board, int?theme)
        {
            HomeViewModel   viewModel  = new HomeViewModel();
            List <board_Tb> themeItems = new List <board_Tb>();

            viewModel.boardItem = new board_Tb();
            //如果board參數無值以及負數導向首頁
            Method.ValueIsEmpty(board);
            if (Method.ValueIsEmpty_Val || board < 0)
            {
                return(RedirectToAction("Index", "Home"));
            }
            ViewBag.boardId = board;
            //如果theme參數無值以及負數導向該版全部主題
            Method.ValueIsEmpty(theme);
            if (Method.ValueIsEmpty_Val || theme < 0)
            {
                theme = 0;
            }
            //目前討論版資訊
            viewModel.boardItem.id         = (int)board;
            viewModel.boardItem.board_name = Service_Board_P.GetBoardName_Md((int)board);
            //獲取討論版分類項目
            themeItems          = Service_Board_P.ListTheme_Md((int)board);
            viewModel.boardList = themeItems;
            //獲取全部主題或該項目文章列表
            List <article_Tb> articleItems = new List <article_Tb>();

            articleItems          = (theme != 0) ? Service_Article_P.ListArticle_Md(board, theme).OrderByDescending(m => m.arti_date).ToList() : Service_Article_P.ListArticle_Md(board, null).OrderByDescending(m => m.arti_date).ToList();
            viewModel.articleList = articleItems;
            List <user_Tb> userItems = new List <user_Tb>();

            viewModel.replyCountList = new List <int>();
            //各文章回覆數量
            for (int i = 0; i < articleItems.Count(); i++)
            {
                articleItems[i].title    = Method.StrSubstring(articleItems[i].title, 0, 50);
                articleItems[i].arti_txt = Method.StrSubstring(articleItems[i].arti_txt, 0, 100);
                int sum = Service_Article_P.GetArticleReplyCount_Md(articleItems[i].arti_id);
                viewModel.replyCountList.Add(sum);
                userItems.Add(Service_User_P.GetUserInfo_Md(articleItems[i].user_id));
            }
            viewModel.userInfoList = userItems;
            return(View(viewModel));
        }