protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int userID = Convert.ToInt32(RouteData.Values["UserID"]); if (userID > 0) { //update statement App_Code.User user = new App_Code.User(userID); txtUserID.Text = user.UserID.ToString(); txtUserEmail.Text = user.UserEmail.ToString(); txtUserIsAdmin.Text = user.UserIsAdmin.ToString(); txtUserIsBanned.Text = user.UserIsBanned.ToString(); txtUserRank.Text = user.UserRank.ToString(); lbInsert.Visible = false; } else if (userID <= 0) { //insert statement btnDelete.Visible = false; lblUserID.Visible = false; txtUserID.Visible = false; txtUserID.Enabled = false; txtUserEmail.Text = ""; txtUserIsAdmin.Text = ""; txtUserIsBanned.Text = ""; txtUserRank.Text = ""; lbUpdate.Visible = false; } } }
protected void lbInsert_Click(object sender, EventArgs e) { App_Code.User u_info = new App_Code.User(); u_info.UserEmail = txtUserEmail.Text; u_info.UserIsAdmin = Convert.ToBoolean(txtUserIsAdmin.Text); u_info.UserIsBanned = Convert.ToBoolean(txtUserIsBanned.Text); u_info.UserRank = Convert.ToInt32(txtUserRank.Text); u_info.UserHashedPw = App_Code.User.CreatePasswordHash(u_info.UserSalt, txtUserPassword.Text); App_Code.User.InsertUser(u_info); Response.Redirect("~/Admin/Users"); }
protected void btnLogin_Click(object sender, EventArgs e) { App_Code.User you = new App_Code.User(txtEmail.Text); string hsh = App_Code.User.CreatePasswordHash(you.UserSalt, txtPassword.Text); //check password if (hsh == you.UserHashedPw) { you.validLogin = true; } //check username is valid by checking if exception is thrown try { int emailLength = you.UserEmail.Length; } catch (NullReferenceException) { you.validLogin = false; } //use validLogin to create auth ticket if (you.validLogin) { FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, you.UserID.ToString(), DateTime.Now, DateTime.Now.AddMinutes(480), false, "Admin"); //encrypt cookies string encryptedTicket = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); //add cookies Response.Cookies.Add(cookie); //create session variable Session["FullName"] = you.UserEmail; //final redirect, well redirect to admin pages Response.Redirect("~/Home"); } }
protected void btnRegister_Click(object sender, EventArgs e) { DataTable usrTbl = App_Code.User.GetUser(txtEmail.Text); if (usrTbl.Rows.Count >= 1) { //do nothing, should refresh fields indicating email is taken } else { App_Code.User usr = new App_Code.User(); string hsh = App_Code.User.CreatePasswordHash(usr.UserSalt, txtPassword.Text); usr.UserEmail = txtEmail.Text; usr.UserHashedPw = hsh; usr.UserIsAdmin = false; usr.UserIsBanned = false; usr.UserRank = 0; App_Code.User.InsertUser(usr); Response.Redirect("~/Home/Sign-In"); } }
protected void lbUpdate_Click(object sender, EventArgs e) { //here we will update the selected player-info //to-do: incorporate api fetch here //create new obj to forward to player-info class App_Code.User u_info = new App_Code.User(); u_info.UserID = Convert.ToInt32(txtUserID.Text); u_info.UserEmail = txtUserEmail.Text; u_info.UserIsAdmin = Convert.ToBoolean(txtUserIsAdmin.Text); u_info.UserIsBanned = Convert.ToBoolean(txtUserIsBanned.Text); u_info.UserRank = Convert.ToInt32(txtUserRank.Text); App_Code.User.UpdateUserInfo(u_info); Response.Redirect("~/Admin/Users"); }