//遊戲(User端)login public ActionResult GameUserLoginView(string LoginAccount, string numberid) { SDuser user = userdb.SDuser.Where(x => x.numberid == numberid).FirstOrDefault(); if (user != null) { Wedding_UserInfo wedding_user = userdb.Wedding_UserInfo.Where(x => x.username == LoginAccount).FirstOrDefault(); if (wedding_user == null) { //存入db Wedding_UserInfo userinfo = new Wedding_UserInfo() { username = LoginAccount, weddingname = user.adaccount, }; userdb.Wedding_UserInfo.Add(userinfo); userdb.SaveChanges(); //存入Cookies UserDataHandler.LoginWeddingSaveToCookies(userinfo); return(RedirectToAction("GameUserView", "Wedding")); } else { ViewBag.error = "已經有人使用,請重新輸入!!"; } } return(View()); }
//登入 public static void LoginSaveToCookies(SDuser user) { FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( version: 1, name: user.adaccount, issueDate: DateTime.Now, expiration: DateTime.Now.AddHours(10), isPersistent: false, userData: user.name,//UserData用來儲存使用者編號 cookiePath: FormsAuthentication.FormsCookiePath ); string encryptTicket = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptTicket); cookie.HttpOnly = true; cookie.Expires = ticket.Expiration; HttpContext.Current.Response.Cookies.Add(cookie); }
public ActionResult Login(string LoginAccount, string Password) { SDuser user = userdb.SDuser.Where(x => x.adaccount == LoginAccount && (x.state == 512 || x.state == 444)).FirstOrDefault(); if (user != null) { string pwd = UserDataHandler.Md5Hash(Password); if (user.Password == pwd) { UserDataHandler.LoginSaveToCookies(user); return(RedirectToAction("NewPhotoWall", "Wedding")); } else { ViewBag.error = "帳號或密碼錯誤,請重新輸入。"; } } else { ViewBag.error = "帳號或密碼錯誤,請重新輸入。"; } return(View()); }