protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { String username = unameInput.Text; String password = pwordInput.Text; if (validate()) { if (UsersDatabaseAccessor.login(username, password)) { Response.Cookies["username"].Value = username; Response.Cookies["username"].Expires = DateTime.Now.AddDays(30); Response.Cookies["password"].Value = password; // todo: hash password with salt Response.Cookies["password"].Expires = DateTime.Now.AddDays(30); Response.Redirect("ctrlpanel.aspx"); } else { failureTooltip.Style.Add("height", "100%"); } } else { return; } } }
public void addEntry(Object sender, EventArgs e) { if (Request.Cookies["username"] != null && Request.Cookies["password"] != null) { string username = Request.Cookies["username"].Value; string password = Request.Cookies["password"].Value; if (Validation.isValidPhoneNumber(username) && Validation.isValidPassword(password)) { UsersDatabaseAccessor db = new UsersDatabaseAccessor(username, password); if (db.isLoggedIn()) { if (db.CanAdd()) { string entryUsername = addEntryPhone.Value; string entryPassword = addEntryPass.Value; if (Validation.isValidPhoneNumber(entryUsername) && Validation.isValidPassword(entryPassword)) { db.addUser(entryUsername, entryPassword); Response.Redirect(Request.RawUrl); } } } } } }
protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["username"] != null && Request.Cookies["password"] != null) { string username = Request.Cookies["username"].Value; string password = Request.Cookies["password"].Value; if (Validation.isValidPhoneNumber(username) && Validation.isValidPassword(password)) { UsersDatabaseAccessor db = new UsersDatabaseAccessor(username, password); if (db.isLoggedIn()) { createTable(db); } else { Response.Cookies["username"].Expires = DateTime.Now; Response.Cookies["password"].Expires = DateTime.Now; Response.Redirect("login.aspx"); } } else { Response.Cookies["username"].Expires = DateTime.Now; Response.Cookies["password"].Expires = DateTime.Now; Response.Redirect("login.aspx"); } } else { Response.Redirect("login.aspx"); } }
private void createTable(UsersDatabaseAccessor db) { Table table = new Table(); ctrlPanel.Controls.Add(table); createTitle(table, db); createBody(table, db); }
private void deleteEntry(object sender, EventArgs e) { if (Request.Cookies["username"] != null && Request.Cookies["password"] != null) { string username = Request.Cookies["username"].Value; string password = Request.Cookies["password"].Value; if (Validation.isValidPhoneNumber(username) && Validation.isValidPassword(password)) { UsersDatabaseAccessor db = new UsersDatabaseAccessor(username, password); if (db.isLoggedIn()) { if (db.CanDelete()) { db.deleteUser(((Button)sender).ID.Split('_')[1]); Response.Redirect(Request.RawUrl); } } } } }
private void permitModify(Object sender, EventArgs e) { if (Request.Cookies["username"] != null && Request.Cookies["password"] != null) { string username = Request.Cookies["username"].Value; string password = Request.Cookies["password"].Value; if (Validation.isValidPhoneNumber(username) && Validation.isValidPassword(password)) { UsersDatabaseAccessor db = new UsersDatabaseAccessor(username, password); if (db.isLoggedIn()) { if (db.CanModify()) { db.switchModify(((CheckBox)sender).ID.Split('_')[1]); Response.Redirect(Request.RawUrl); } } } } }
private void createTitle(Table table, UsersDatabaseAccessor db) { if (db.CanAdd()) { int colspan = 1; if (db.CanDelete()) { colspan++; } if (db.CanModify()) { colspan += 3; } TableRow additionTitleRow = new TableRow(); table.Controls.Add(additionTitleRow); additionTitleRow.Style.Add("background-color", "#7A9124"); additionTitleRow.Style.Add("color", "white"); TableCell additionTitleCell = new TableCell { ColumnSpan = colspan }; additionTitleRow.Controls.Add(additionTitleCell); Button additionTitleButton = new Button(); additionTitleCell.Controls.Add(additionTitleButton); additionTitleButton.Text = "Adding"; additionTitleButton.OnClientClick = "addEntry(); return false"; } TableRow permissioTitlenRow = new TableRow(); table.Controls.Add(permissioTitlenRow); permissioTitlenRow.Style.Add("background-color", "#7A9124"); permissioTitlenRow.Style.Add("color", "white"); permissioTitlenRow.Controls.Add(new TableCell()); if (db.CanModify()) { permissioTitlenRow.Controls.Add(new TableCell { ColumnSpan = 3, Text = "Permissions" }); } if (db.CanDelete()) { permissioTitlenRow.Controls.Add(new TableCell()); } TableRow titleRow = new TableRow(); table.Controls.Add(titleRow); titleRow.Style.Add("background-color", "#7A9124"); titleRow.Style.Add("color", "white"); titleRow.Controls.Add(new TableCell { Text = "Phone number" }); if (db.CanModify()) { titleRow.Controls.Add(new TableCell { Text = "Adding" }); titleRow.Controls.Add(new TableCell { Text = "Deleting" }); titleRow.Controls.Add(new TableCell { Text = "Managing" }); } if (db.CanDelete()) { titleRow.Controls.Add(new TableCell { Text = "Deletion" }); } }
private void createBody(Table table, UsersDatabaseAccessor db) { foreach (var entry in db.getAll()) { TableRow bodyRow = new TableRow(); table.Controls.Add(bodyRow); bodyRow.Controls.Add(new TableCell { Text = entry.phone }); if (db.CanModify()) { TableCell canAddInputCell = new TableCell(); TableCell canDeleteInputCell = new TableCell(); TableCell canModifyInputCell = new TableCell(); bodyRow.Controls.Add(canAddInputCell); bodyRow.Controls.Add(canDeleteInputCell); bodyRow.Controls.Add(canModifyInputCell); CheckBox canAddInput = new CheckBox { ID = "canadd_" + entry.phone, AutoPostBack = true }; CheckBox canDeleteInput = new CheckBox { ID = "candel_" + entry.phone, AutoPostBack = true }; CheckBox canModifyInput = new CheckBox { ID = "canmod_" + entry.phone, AutoPostBack = true }; canAddInputCell.Controls.Add(canAddInput); canDeleteInputCell.Controls.Add(canDeleteInput); canModifyInputCell.Controls.Add(canModifyInput); if (entry.canAdd) { canAddInput.Checked = true; } if (entry.canDel) { canDeleteInput.Checked = true; } if (entry.canMod) { canModifyInput.Checked = true; } canAddInput.CheckedChanged += permitAdd; canDeleteInput.CheckedChanged += permitDelete; canModifyInput.CheckedChanged += permitModify; } if (db.CanDelete()) { TableCell deleteInputCell = new TableCell(); bodyRow.Controls.Add(deleteInputCell); Button deleteInput = new Button { Text = "Delete", ID = "delete_" + entry.phone }; deleteInputCell.Controls.Add(deleteInput); deleteInput.Click += deleteEntry; } } }
protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["username"] != null && Request.Cookies["password"] != null) { string username = Request.Cookies["username"].Value; string password = Request.Cookies["password"].Value; if (Validation.isValidPhoneNumber(username) && Validation.isValidPassword(password)) { UsersDatabaseAccessor db = new UsersDatabaseAccessor(username, password); if (db.isLoggedIn()) { RidesDatabaseAccessor rdb = new RidesDatabaseAccessor(); if (IsPostBack) { string dest = ""; string depart = ""; string date = ""; string time = ""; if (destInput.Text != "" && Validation.isValidPlacesID(destInput.Text)) { dest = destInput.Text; } if (departInput.Text != "" && Validation.isValidPlacesID(departInput.Text)) { depart = departInput.Text; } if (dateInput.Text != "" && Validation.isValidDateString(dateInput.Text)) { date = dateInput.Text; } if (timeInput.Text != "" && Validation.isValidTimeString(timeInput.Text)) { time = timeInput.Text; } RidesDatabaseAccessor.Filters filters = new RidesDatabaseAccessor.Filters { destinationID = dest, departureID = depart }; if (date != "" || time != "") { DateTime dateObj; if (date != "") { dateObj = DateTime.Parse(date); } else { dateObj = DateTime.Today; } if (time != "") { filters.time = dateObj.Add(DateTime.Parse(time).TimeOfDay); } else { filters.time = dateObj; } } rdb.setFilters(filters); } createTable(rdb); } else { Response.Cookies["username"].Expires = DateTime.Now; Response.Cookies["password"].Expires = DateTime.Now; Response.Redirect("login.aspx"); } } else { Response.Cookies["username"].Expires = DateTime.Now; Response.Cookies["password"].Expires = DateTime.Now; Response.Redirect("login.aspx"); } } else { Response.Redirect("login.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["username"] != null && Request.Cookies["password"] != null) { string username = Request.Cookies["username"].Value; string password = Request.Cookies["password"].Value; if (Validation.isValidPhoneNumber(username) && Validation.isValidPassword(password)) { UsersDatabaseAccessor db = new UsersDatabaseAccessor(username, password); if (db.isLoggedIn()) { if (IsPostBack) { string dest = ""; string depart = ""; string date = ""; string time = ""; string through = ""; string comment = ""; if (destInput.Text != "" && Validation.isValidPlacesID(destInput.Text)) { dest = destInput.Text; } if (departInput.Text != "" && Validation.isValidPlacesID(departInput.Text)) { depart = departInput.Text; } if (dateInput.Text != "" && Validation.isValidDateString(dateInput.Text)) { date = dateInput.Text; } if (timeInput.Text != "" && Validation.isValidTimeString(timeInput.Text)) { time = timeInput.Text; } if (throughInput.Text != "" && Validation.isValidComment(throughInput.Text)) { through = throughInput.Text; } if (commentInput.Text != "" && Validation.isValidComment(commentInput.Text)) { comment = commentInput.Text; } if (dest == "" || depart == "") { return; } DateTime dt = default(DateTime); if (date != "") { dt = DateTime.Parse(date); } else { dt = DateTime.Today; } if (time != "") { dt = dt.Add(DateTime.Parse(time).TimeOfDay); } else { if (date == "") { dt = DateTime.Now; } } RidesDatabaseAccessor rdb = new RidesDatabaseAccessor(); rdb.updateEntry(new RidesDatabaseAccessor.Entry { phone = username, destinationID = dest, departureID = depart, time = dt, through = through, comment = comment }); } } else { Response.Cookies["username"].Expires = DateTime.Now; Response.Cookies["password"].Expires = DateTime.Now; Response.Redirect("login.aspx"); } } else { Response.Cookies["username"].Expires = DateTime.Now; Response.Cookies["password"].Expires = DateTime.Now; Response.Redirect("login.aspx"); } } else { Response.Redirect("login.aspx"); } }