protected void SchoolSelectSubmit_Click(object sender, EventArgs e) { FormsAuthenticationTicket tkt; string cookiestr; HttpCookie ck; tkt = new FormsAuthenticationTicket(1, Session["UserName"].ToString(), DateTime.Now, DateTime.Now.AddMinutes(60), false, ""); cookiestr = FormsAuthentication.Encrypt(tkt); ck = new HttpCookie("SmacCookie", cookiestr); StringBuilder sb = new StringBuilder(); var genders = GenderEntity.GetGenders(); genders.ForEach(t => sb.Append(t.GenderType.ToString() + ":")); sb.Remove(sb.Length - 1, 1); ck.Values.Add("UserId", Session["UserId"].ToString()); ck.Values.Add("FirstName", Session["FirstName"].ToString()); ck.Values.Add("MiddleName", Session["MiddleName"].ToString()); ck.Values.Add("LastName", Session["LastName"].ToString()); ck.Values.Add("PhoneNumber", Session["PhoneNumber"].ToString()); ck.Values.Add("Email", Session["Email"].ToString()); ck.Values.Add("UserName", Session["UserName"].ToString()); ck.Values.Add("Gender", Session["Gender"].ToString()); ck.Values.Add("SchoolName", ddList_SchoolSelect.SelectedItem.Text); ck.Values.Add("SchoolId", ddList_SchoolSelect.SelectedItem.Value); ck.Values.Add("Genders", sb.ToString()); Response.Cookies.Add(ck); Session["UpdateCookie"] = "no"; Response.Redirect("/Home.aspx"); }
protected void Submit_Click(object sender, EventArgs e) { try { var usr = UserCredentialEntity.Authenticate(Request.Form["username"].Trim(), Request.Form["password"]); FormsAuthenticationTicket tkt; string cookiestr; HttpCookie ck; tkt = new FormsAuthenticationTicket(1, Request.Form["username"].Trim(), DateTime.Now, DateTime.Now.AddMinutes(60), false, ""); cookiestr = FormsAuthentication.Encrypt(tkt); ck = new HttpCookie("SmacCookie", cookiestr); StringBuilder sb = new StringBuilder(); var genders = GenderEntity.GetGenders(); genders.ForEach(t => sb.Append(t.GenderType.ToString() + ":")); sb.Remove(sb.Length - 1, 1); ck.Values.Add("UserId", usr.UserId); ck.Values.Add("FirstName", usr.FirstName); ck.Values.Add("LastName", usr.LastName); ck.Values.Add("PhoneNumber", usr.PhoneNumber); ck.Values.Add("Email", usr.EmailAddress); ck.Values.Add("MiddleName", usr.MiddleName); ck.Values.Add("UserName", usr.UserCredential.UserName); ck.Values.Add("Gender", usr.GenderType); ck.Values.Add("Genders", sb.ToString()); var school = SchoolEntity.GetUsersSchools(usr.UserId); if (school.Count == 1) { ck.Values.Add("SchoolName", school[0].SchoolName); ck.Values.Add("SchoolId", school[0].SchoolId.ToString()); } Response.Cookies.Add(ck); FormsAuthentication.RedirectFromLoginPage(Request.Form["username"].Trim(), false); } catch (Exception ex) { loginStatus.Text = ex.Message; loginStatus.ForeColor = System.Drawing.Color.Red; } }
protected void Page_Load(object sender, EventArgs e) { if (!HttpContext.Current.User.Identity.IsAuthenticated) { FormsAuthentication.RedirectToLoginPage(); } var userId = Request.Cookies["SmacCookie"]["UserId"]; this.userRole.Value = Database.Helpers.GetUserRole(userId).ToString(); this.newMessages.Value = PrivateMessageEntity.CheckForNewMessages(userId).ToString(); if (Session["UpdateCookie"] != null && Session["UpdateCookie"].ToString() == "yes") { FormsAuthenticationTicket tkt; string cookiestr; HttpCookie ck; tkt = new FormsAuthenticationTicket(1, Session["UserName"].ToString(), DateTime.Now, DateTime.Now.AddMinutes(60), false, ""); cookiestr = FormsAuthentication.Encrypt(tkt); ck = new HttpCookie("SmacCookie", cookiestr); StringBuilder sb = new StringBuilder(); var genders = GenderEntity.GetGenders(); genders.ForEach(t => sb.Append(t.GenderType.ToString() + ":")); sb.Remove(sb.Length - 1, 1); ck.Values.Add("UserId", Session["UserId"].ToString()); ck.Values.Add("FirstName", Session["FirstName"].ToString()); ck.Values.Add("MiddleName", Session["MiddleName"].ToString()); ck.Values.Add("LastName", Session["LastName"].ToString()); ck.Values.Add("PhoneNumber", Session["PhoneNumber"].ToString()); ck.Values.Add("Email", Session["Email"].ToString()); ck.Values.Add("UserName", Session["UserName"].ToString()); ck.Values.Add("Gender", Session["Gender"].ToString()); ck.Values.Add("SchoolName", Session["SchoolName"].ToString()); ck.Values.Add("SchoolId", Session["SchoolId"].ToString()); ck.Values.Add("Genders", sb.ToString()); Response.Cookies.Add(ck); Session["UpdateCookie"] = "no"; } else { Session["UserId"] = Request.Cookies["SmacCookie"]["UserId"]; Session["FirstName"] = Request.Cookies["SmacCookie"]["FirstName"]; Session["MiddleName"] = Request.Cookies["SmacCookie"]["MiddleName"]; Session["LastName"] = Request.Cookies["SmacCookie"]["LastName"]; Session["PhoneNumber"] = Request.Cookies["SmacCookie"]["PhoneNumber"]; Session["Email"] = Request.Cookies["SmacCookie"]["Email"]; Session["UserName"] = Request.Cookies["SmacCookie"]["UserName"]; Session["Gender"] = Request.Cookies["SmacCookie"]["Gender"]; Session["SchoolName"] = Request.Cookies["SmacCookie"]["SchoolName"]; Session["SchoolId"] = Request.Cookies["SmacCookie"]["SchoolId"]; Session["Genders"] = Request.Cookies["SmacCookie"]["Genders"]; if (Session["SchoolName"] != null) { schoolBanner.Visible = true; schoolBanner.InnerHtml = Request.Cookies["SmacCookie"]["SchoolName"]; } } }