protected void btn_register_Click(object sender, EventArgs e) { if (IsValid) { string path = "~/attach/" + fu_photo.FileName; fu_photo.SaveAs(Server.MapPath(path)); UsersLayer.InsertUser(txt_name.Text, int.Parse(txt_age.Text), txt_pass.Text, txt_email.Text, rbl_gender.Text, path); lbl_status.Text = "Product Added Successfuly!"; Response.Redirect("~/login.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["id"] != null) { DataTable dt = UsersLayer.GetUser(int.Parse(Session["id"].ToString())); lbl_name.Text = dt.Rows[0]["Name"].ToString(); lbl_age.Text = dt.Rows[0]["Age"].ToString(); lbl_email.Text = dt.Rows[0]["Email"].ToString(); lbl_gender.Text = dt.Rows[0]["Gender"].ToString(); img_profile.ImageUrl = dt.Rows[0]["Image"].ToString(); } else { Response.Redirect("~/login.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { try { DataTable dt = UsersLayer.GetUser(int.Parse(Request.Cookies["user"].Values["id"])); txt_name.Text = dt.Rows[0]["Name"].ToString(); txt_age.Text = dt.Rows[0]["Age"].ToString(); txt_gender.Text = dt.Rows[0]["Gender"].ToString(); txt_email.Text = dt.Rows[0]["Email"].ToString(); } catch { DataTable dt = UsersLayer.GetUser(int.Parse(Session["id"].ToString())); txt_name.Text = dt.Rows[0]["Name"].ToString(); txt_age.Text = dt.Rows[0]["Age"].ToString(); txt_gender.Text = dt.Rows[0]["Gender"].ToString(); txt_email.Text = dt.Rows[0]["Email"].ToString(); } }
protected void btn_save_Click(object sender, EventArgs e) { try { if (IsValid) { string newPass = txt_new.Text; UsersLayer.changePassword(int.Parse(Request.Cookies["user"].Values["id"].ToString()), newPass); lbl_save.Text = "New Password Saved Correctly!"; } } catch { if (IsValid) { string newPass = txt_new.Text; UsersLayer.changePassword(int.Parse(Session["id"].ToString()), newPass); lbl_save.Text = "New Password Saved Correctly!"; } } }
protected void btn_login_Click1(object sender, EventArgs e) { DataTable dt = UsersLayer.GetUserId(txt_name.Text, txt_password.Text); if (dt.Rows.Count > 0 && txt_name.Text == "admin" && txt_password.Text == "admin") { Session["id"] = dt.Rows[0]["Id"]; Session["admin"] = dt.Rows[0]["Id"]; if (chb_remeberme.Checked) { HttpCookie co = new HttpCookie("user"); co.Values.Add("id", dt.Rows[0]["Id"].ToString()); co.Values.Add("admin", dt.Rows[0]["Id"].ToString()); co.Expires = DateTime.Now.AddDays(15); Response.Cookies.Add(co); } Response.Redirect("~/Profile.aspx"); } else if (dt.Rows.Count > 0 && txt_name.Text != "admin" && txt_password.Text != "admin") { Session["id"] = dt.Rows[0]["Id"]; if (chb_remeberme.Checked) { HttpCookie co = new HttpCookie("user"); co.Values.Add("id", dt.Rows[0]["Id"].ToString()); co.Expires = DateTime.Now.AddDays(15); Response.Cookies.Add(co); } Response.Redirect("~/Profile.aspx"); } else { lbl_status.Text = "invalid username or password"; } }