protected void reset_data() { using (WindchimeEntities wce = new WindchimeEntities()) { var user1 = (from User u in wce.CreatorSet.OfType<User>() where u.Username.Equals( WindchimeSession.Current.User.Username ) select u); if (user1.Count() != 1) { Response.Redirect("~/Login.aspx?ReturnUrl=/UserPref.aspx", false); return; } User usr = user1.First<User>(); boxUsername.Text = usr.Username; boxEmail.Text = usr.Email; boxFirstName.Text = usr.FirstName; boxLastName.Text = usr.LastName; boxAddr1.Text = usr.Address1; boxAddr2.Text = usr.Address2; boxCity.Text = usr.City; listState.SelectedValue = usr.State; boxZip.Text = usr.PostalCode; boxPassword1.Text = ""; boxPassword2.Text = ""; WindchimeSession.Current.User = usr; } }
protected void btnSearch_Click(object sender, EventArgs e) { string args = searchbox.Text.Trim().ToLower(); if (args.CompareTo("") == 0) { resultlabel.Text = "Enter Search Params"; return; } else { using (WindchimeEntities wce = new WindchimeEntities()) { var results = (from TextVersion t in wce.VersionSet.OfType <TextVersion>() where t.Text.Contains(args) || t.Assets.Headline.Contains(args) && t.Assets.Approved select t); if (results.Count() != 0) { resultlabel.Text = ""; foreach (var r in results) { resultlabel.Text += r.VersionID; } } else { resultlabel.Text = "No Results Returned"; } } } }
protected void Page_Load(object sender, EventArgs e) { if (this.IsPostBack) { // this.ViewState return; } if (!string.IsNullOrEmpty(Request.QueryString["ID"])) { id = int.Parse(Request.QueryString["ID"]); using (WindchimeEntities wce = new WindchimeEntities()) { Asset asst = (from Asset a in wce.PermissionableEntities.OfType<Asset>() where a.EntityID == id select a).FirstOrDefault(); if (asst == null) throw new ArgumentException("Invalid ID specified as parameter."); Name_box.Text = asst.Headline; TextVersion version = (from TextVersion tv in asst.Versions orderby tv.CreatedDate descending select tv).FirstOrDefault(); if (version != null) { Content_box.Text = version.Text; } } } }
protected void Page_Load(object sender, EventArgs e) { if (this.IsPostBack) { // this.ViewState return; } if (!string.IsNullOrEmpty(Request.QueryString["ID"])) { id = int.Parse(Request.QueryString["ID"]); using (WindchimeEntities wce = new WindchimeEntities()) { Asset asst = (from Asset a in wce.PermissionableEntities.OfType <Asset>() where a.EntityID == id select a).FirstOrDefault(); if (asst == null) { throw new ArgumentException("Invalid ID specified as parameter."); } Name_box.Text = asst.Headline; TextVersion version = (from TextVersion tv in asst.Versions orderby tv.CreatedDate descending select tv).FirstOrDefault(); if (version != null) { Content_box.Text = version.Text; } } } }
void Save_Click(object sender, EventArgs e) { Asset asst = null; using (WindchimeEntities wce = new WindchimeEntities()) { if (id != null) { asst = (from Asset a in wce.PermissionableEntities.OfType<Asset>() where a.EntityID == id select a).FirstOrDefault(); } if (asst == null) { asst = new Asset(); wce.AddToPermissionableEntities(asst); } asst.Headline = Name_box.Text; TextVersion tv = new TextVersion(); tv.Text = Content_box.Text; tv.CreatedDate = DateTime.Now; asst.Versions.Add(tv); wce.AddToVersionSet(tv); wce.SaveChanges(); wce.Refresh(System.Data.Objects.RefreshMode.StoreWins, asst); id = asst.EntityID; } }
protected void btnSearch_Click(object sender, EventArgs e) { string args = searchbox.Text.Trim().ToLower(); if (args.CompareTo("") == 0) { resultlabel.Text = "Enter Search Params"; return; } else { using (WindchimeEntities wce = new WindchimeEntities()) { var results = (from TextVersion t in wce.VersionSet.OfType<TextVersion>() where t.Text.Contains(args) || t.Assets.Headline.Contains(args) && t.Assets.Approved select t); if (results.Count() != 0) { resultlabel.Text = ""; foreach (var r in results) { resultlabel.Text += r.VersionID; } } else { resultlabel.Text = "No Results Returned"; } } } }
void Save_Click(object sender, EventArgs e) { Assignment assgn = null; using (WindchimeEntities wce = new WindchimeEntities()) { if (id != null) { assgn = (from Assignment a in wce.PermissionableEntities.OfType<Assignment>() where a.EntityID == id select a).FirstOrDefault(); } if (assgn == null) { assgn = new Assignment(); wce.AddToPermissionableEntities(assgn); } assgn.Summary = Summary_box.Text; assgn.Name = Name_box.Text; assgn.DueDate = DateTime.Parse(DueDate_box.Text); assgn.Location = Location_box.Text; if (Completed_chk.Checked && assgn.CompletedDate == null) assgn.CompletedDate = DateTime.Now; else if (!Completed_chk.Checked) assgn.CompletedDate = null; wce.SaveChanges(); wce.Refresh(System.Data.Objects.RefreshMode.StoreWins, assgn); id = assgn.EntityID; } }
protected void reset_data() { using (WindchimeEntities wce = new WindchimeEntities()) { var user1 = (from User u in wce.CreatorSet.OfType <User>() where u.Username.Equals(WindchimeSession.Current.User.Username) select u); if (user1.Count() != 1) { Response.Redirect("~/Login.aspx?ReturnUrl=/UserPref.aspx", false); return; } User usr = user1.First <User>(); boxUsername.Text = usr.Username; boxEmail.Text = usr.Email; boxFirstName.Text = usr.FirstName; boxLastName.Text = usr.LastName; boxAddr1.Text = usr.Address1; boxAddr2.Text = usr.Address2; boxCity.Text = usr.City; listState.SelectedValue = usr.State; boxZip.Text = usr.PostalCode; boxPassword1.Text = ""; boxPassword2.Text = ""; WindchimeSession.Current.User = usr; } }
public static PolicyEntry CreatePolicy(Group g, Policy pol, bool overRide) { if (!overRide && !DoesUserHavePolicy(WindchimeSession.Current.User, Policy.CreatePolicy)) { throw new NoPolicyException(Policy.CreatePolicy); } if (g == null) { return(null); } PolicyEntry pent = new PolicyEntry(); pent.GroupID = g.GroupID; pent.Policy = pol; using (WindchimeEntities wce = new WindchimeEntities()) { wce.AddToPolicyEntries(pent); wce.SaveChanges(); wce.Detach(pent); } return(pent); }
public override bool ValidateUser(string strName, string strPassword) { using (WindchimeEntities wce = new WindchimeEntities()) { string pw = SecurityManager.HashPasswordForStoringInDatabase(strPassword); var users = (from User u in wce.CreatorSet.OfType <User>() where u.Username == strName && u.Password == pw select u); int num = users.Count <User>(); if (num > 1) { //throw new MultipleUsersException(); //doesn't exist right now throw new Exception("Multiple users in system with same credentials!"); } else if (num == 0) { return(false); } else { WindchimeSession.Current.User = users.First <User>(); return(true); } } }
/// <summary> /// Creates a new permission and adds it to the database. /// </summary> /// <param name="g">The group to give permission to.</param> /// <param name="ent">The entity on which the permissio act.</param> /// <param name="perm">The permission to give to the group.</param> /// <param name="deny">Whether or not to explicitly deny this permission.</param> /// <param name="applytarget">Whether or not the permission applies to this entity (versus its contents).</param> /// <param name="applycolls">Whether or not the permission applies to collections within this entity.</param> /// <param name="applyassets">Whether or not the permission applies to assets within this entity.</param> /// <returns>The new permission entry or null.</returns> /// <exception cref="NoPolicyException">If the current user does not have the ability to create a new permission.</exception> public static PermissionEntry CreatePermissionEntry(Group g, PermissionableEntity ent, Permission perm, bool deny, bool applytarget, bool applycolls, bool applyassets) { if (!DoesUserHavePerm(WindchimeSession.Current.User, ent, Permission.EditPermissions)) { throw new NoPermissionException(Permission.EditPermissions); } if (g == null || ent == null) { return(null); } PermissionEntry pent = new PermissionEntry(); pent.GroupID = g.GroupID; pent.EntityID = ent.EntityID; pent.Permission = (int)perm; pent.IsDeny = deny; pent.DoesApplyToTarget = applytarget; pent.DoesApplyToCollections = applycolls; pent.DoesApplyToAssets = applyassets; using (WindchimeEntities wce = new WindchimeEntities()) { wce.AddToPermissionEntrySet(pent); wce.SaveChanges(); wce.Detach(pent); } return(pent); }
void Save_Click(object sender, EventArgs e) { Asset asst = null; using (WindchimeEntities wce = new WindchimeEntities()) { if (id != null) { asst = (from Asset a in wce.PermissionableEntities.OfType <Asset>() where a.EntityID == id select a).FirstOrDefault(); } if (asst == null) { asst = new Asset(); wce.AddToPermissionableEntities(asst); } asst.Headline = Name_box.Text; TextVersion tv = new TextVersion(); tv.Text = Content_box.Text; tv.CreatedDate = DateTime.Now; asst.Versions.Add(tv); wce.AddToVersionSet(tv); wce.SaveChanges(); wce.Refresh(System.Data.Objects.RefreshMode.StoreWins, asst); id = asst.EntityID; } }
public static Group CreateGroup(string name, bool isSpecial, bool overRide) { if (!overRide && !DoesUserHavePolicy(WindchimeSession.Current.User, Policy.CreateGroup)) { throw new NoPolicyException(Policy.CreateGroup); } if (name.Length < 1) { return(null); } Group g = new Group(); g.Name = name; g.IsSpecial = isSpecial; using (WindchimeEntities wce = new WindchimeEntities()) { wce.AddToGroups(g); wce.SaveChanges(); wce.Detach(g); } return(g); }
public static User CreateUser(Creator c, string username, string password, bool isStaff, bool overRide) { if (!overRide && !DoesUserHavePolicy(WindchimeSession.Current.User, Policy.CreateUser)) { throw new NoPolicyException(Policy.CreateUser); } WCMembershipProvider wcm = new WCMembershipProvider(); Regex re = new Regex(wcm.PasswordStrengthRegularExpression); User u; Group g = new Group(); if (c == null || username.Length < 1 || !re.IsMatch(password)) { return(null); } u = User.CreateUser(c.CreatorID, c.FirstName, c.LastName, username, SecurityManager.HashPasswordForStoringInDatabase(password), isStaff); g.Name = username; g.IsSpecial = true; using (WindchimeEntities wce = new WindchimeEntities()) { wce.AddToCreatorSet(u); wce.AddToGroups(g); g.Users.Add(u); wce.SaveChanges(); wce.Detach(g); wce.Detach(u); } return(u); }
static void Main(String[] args) { Console.WriteLine("Windchime Importer"); if (args.Length != 1) { usage(); } if (!Directory.Exists(args[0])) { Console.WriteLine("Error: Invalid directory."); usage(); } DirectoryInfo di = new DirectoryInfo(args[0]); FileInfo[] files = di.GetFiles(args[0] + "\\*"); WindchimeEntities wce = new WindchimeEntities(); foreach (FileInfo f in files) { BinaryVersion b = new BinaryVersion(); b.Path = f.FullName; Asset a = new Asset(); a.Versions.Add(b); wce.AddToPermissionableEntities(a); Console.WriteLine("Added binary asset from file " + f.FullName); } wce.SaveChanges(); }
protected void Collections_PopulateNodes(object sender, FlyTreeNodeEventArgs e) { int collectionID = int.Parse(e.Node.Value); using (WindchimeEntities wce = new WindchimeEntities()) { var children = (from Collection c in wce.Collections where c.EntityID == collectionID select c.Children).First(); foreach (Collection c in children) { var node = new FlyTreeNode(c.Name, c.EntityID.ToString()); //node.ImageUrl = "~/Images/folder-small.png"; // if there are children out there, populate them later. if not, no point in confusing the user c.Children.Load(); if (c.Children.Count != 0) { node.PopulateNodesOnDemand = true; } else { node.PopulateNodesOnDemand = false; } e.Node.ChildNodes.Add(node); } } }
static void Main(String[] args) { Console.WriteLine("Windchime Importer"); if (args.Length != 1) { usage(); } if (! Directory.Exists(args[0])) { Console.WriteLine("Error: Invalid directory."); usage(); } DirectoryInfo di = new DirectoryInfo(args[0]); FileInfo[] files = di.GetFiles(args[0] + "\\*"); WindchimeEntities wce = new WindchimeEntities(); foreach (FileInfo f in files) { BinaryVersion b = new BinaryVersion(); b.Path = f.FullName; Asset a = new Asset(); a.Versions.Add(b); wce.AddToPermissionableEntities(a); Console.WriteLine("Added binary asset from file " + f.FullName); } wce.SaveChanges(); }
public string[] GetCompletionList(string prefixText, int count) { using (WindchimeEntities wce = new WindchimeEntities()) { return((from User u in wce.CreatorSet.OfType <User>() where u.IsStaff && (u.FirstName + " " + u.LastName).StartsWith(prefixText) select u.FirstName + " " + u.LastName).ToArray()); } }
public string[] GetCompletionList(string prefixText, int count) { using (WindchimeEntities wce = new WindchimeEntities()) { return (from User u in wce.CreatorSet.OfType<User>() where u.IsStaff && (u.FirstName + " " + u.LastName).StartsWith(prefixText) select u.FirstName + " " + u.LastName).ToArray(); } }
// // Summary: // Adds a new membership user to the data source. // // Parameters: // username: // The user name for the new user. // // password: // The password for the new user. // // email: // The e-mail address for the new user. // // passwordQuestion: // The password question for the new user. // // passwordAnswer: // The password answer for the new user // // isApproved: // Whether or not the new user is approved to be validated. // // providerUserKey: // The unique identifier from the membership data source for the user. // // status: // A System.Web.Security.MembershipCreateStatus enumeration value indicating // whether the user was created successfully. // // Returns: // A System.Web.Security.MembershipUser object populated with the information // for the newly created user. public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { using (WindchimeEntities wce = new WindchimeEntities()) { Regex re = new Regex(this.PasswordStrengthRegularExpression); User u = new User(); Group g = new Group(); u.FirstName = ""; u.LastName = ""; u.Username = username; u.Password = SecurityManager.HashPasswordForStoringInDatabase(password); u.IsStaff = false; u.Email = email; g.Name = username; g.IsSpecial = false; if (username.Length < 6) { status = MembershipCreateStatus.UserRejected; } else if ((from User k in wce.CreatorSet.OfType <User>() where k.Username == username select k).Count <User>() > 0) { status = MembershipCreateStatus.DuplicateUserName; } else if (!re.IsMatch(password)) { status = MembershipCreateStatus.InvalidPassword; } else if (!isEmail(email)) { status = MembershipCreateStatus.InvalidEmail; } else if ((from User k in wce.CreatorSet.OfType <User>() where k.Email == email select k).Count <User>() > 0) { status = MembershipCreateStatus.DuplicateEmail; } else { status = MembershipCreateStatus.Success; wce.AddToCreatorSet(u); wce.AddToGroups(g); g.Users.Add(u); wce.SaveChanges(); // log in the user WindchimeSession.Current.User = u; } } return(null); }
protected void Collections_SelectedNodeChanged(object sender, SelectedNodeChangedEventArgs e) { int collectionID = int.Parse(e.Node.Value); using (WindchimeEntities wce = new WindchimeEntities()) { Collection loadme = (from Collection c in wce.Collections where c.EntityID == collectionID select c).First(); OpenCollectionInInspector(loadme); } }
protected void Page_Load(object sender, EventArgs e) { using (WindchimeEntities wce = new WindchimeEntities()) { foreach (Issue i in wce.PermissionableEntities.OfType <Issue>()) { Issue_list.Items.Add(new ListItem(String.Format("{0} ({1})", i.Name, i.Date.ToShortDateString()), i.EntityID.ToString())); } Issue_list.Items.Insert(0, new ListItem("Any Issue", "")); var assignments = from Assignment a in wce.PermissionableEntities.OfType <Assignment>() select a; if (!string.IsNullOrEmpty(Issue_list.SelectedValue)) { int issueid = int.Parse(Issue_list.SelectedValue); assignments = from Assignment a in assignments from Issue i in a.Parents.OfType <Issue>() where i.EntityID == issueid select a; } if (!string.IsNullOrEmpty(Keywords_box.Text)) { assignments = from Assignment a in assignments where a.Name.Contains(Keywords_box.Text) || a.Summary.Contains(Keywords_box.Text) || a.Location.Contains(Keywords_box.Text) select a; } if (!string.IsNullOrEmpty(Author_box.Text)) { assignments = from Assignment a in assignments from Creator c in a.Creators where (c.FirstName + " " + c.LastName).StartsWith(Author_box.Text) select a; } Assignments_grid.DataSource = assignments; Assignments_grid.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { using (WindchimeEntities wce = new WindchimeEntities()) { Label2.Text = ""; User u = (from User user in wce.CreatorSet.OfType<User>() where user.Username.CompareTo("EIC") == 0 select user).First(); foreach (Policy p in Enum.GetValues(typeof(Policy))) { Label2.Text += p.ToString() + " " + SecurityManager.DoesUserHavePolicy(u, p) + "<br />"; } Label2.Text += "<br />"; } }
protected void Page_Load(object sender, EventArgs e) { using (WindchimeEntities wce = new WindchimeEntities()) { Label2.Text = ""; User u = (from User user in wce.CreatorSet.OfType <User>() where user.Username.CompareTo("EIC") == 0 select user).First(); foreach (Policy p in Enum.GetValues(typeof(Policy))) { Label2.Text += p.ToString() + " " + SecurityManager.DoesUserHavePolicy(u, p) + "<br />"; } Label2.Text += "<br />"; } }
protected void Page_Load(object sender, EventArgs e) { using (WindchimeEntities wce = new WindchimeEntities()) { foreach (Issue i in wce.PermissionableEntities.OfType<Issue>()) Issue_list.Items.Add(new ListItem(String.Format("{0} ({1})", i.Name, i.Date.ToShortDateString()), i.EntityID.ToString())); Issue_list.Items.Insert(0, new ListItem("Any Issue", "")); var assignments = from Assignment a in wce.PermissionableEntities.OfType<Assignment>() select a; if(!string.IsNullOrEmpty(Issue_list.SelectedValue)) { int issueid = int.Parse(Issue_list.SelectedValue); assignments = from Assignment a in assignments from Issue i in a.Parents.OfType<Issue>() where i.EntityID == issueid select a; } if (!string.IsNullOrEmpty(Keywords_box.Text)) { assignments = from Assignment a in assignments where a.Name.Contains(Keywords_box.Text) || a.Summary.Contains(Keywords_box.Text) || a.Location.Contains(Keywords_box.Text) select a; } if(!string.IsNullOrEmpty(Author_box.Text)) { assignments = from Assignment a in assignments from Creator c in a.Creators where (c.FirstName + " " + c.LastName).StartsWith(Author_box.Text) select a; } Assignments_grid.DataSource = assignments; Assignments_grid.DataBind(); } }
protected void Submit_Click(object sender, EventArgs e) { if (!Page.IsValid) reset_data(); using (WindchimeEntities wce = new WindchimeEntities()) { var user1 = (from User u in wce.CreatorSet.OfType<User>() where u.Username.Equals(WindchimeSession.Current.User.Username) select u); if (user1.Count() != 1) { Response.Redirect("~/Login.aspx?ReturnUrl=/UserPref.aspx", false); return; } User usr = user1.First<User>(); Regex RegexObj = new Regex("^\\w[\\w.]*@\\w+\\.\\w[\\.\\w]*$"); if ((!boxEmail.Text.Equals("")) && RegexObj.IsMatch(boxEmail.Text)) { usr.Email = boxEmail.Text; } if( !boxFirstName.Text.Equals( "" ) ) usr.FirstName = boxFirstName.Text; if( !boxLastName.Text.Equals( "" ) ) usr.LastName = boxLastName.Text; if (!boxAddr1.Text.Equals("")) usr.Address1 = boxAddr1.Text; if (!boxAddr2.Text.Equals("")) usr.Address2 = boxAddr2.Text; if (!boxCity.Text.Equals("")) usr.City = boxCity.Text; usr.State = listState.SelectedValue; if (!boxZip.Text.Equals("")) usr.PostalCode = boxZip.Text; WCMembershipProvider wcm = new WCMembershipProvider(); Regex regexPassword = new Regex(wcm.PasswordStrengthRegularExpression); if (boxPassword1.Text.Equals(boxPassword2.Text) && (!boxPassword1.Text.Equals( "" ))) if (regexPassword.IsMatch(boxPassword1.Text)) { usr.Password = SecurityManager.HashPasswordForStoringInDatabase(boxPassword1.Text); } wce.SaveChanges(); } reset_data(); }
public static void DeletePolicy(Group g, Policy pol) { if (!DoesUserHavePolicy(WindchimeSession.Current.User, Policy.DeletePolicy)) { throw new NoPolicyException(Policy.DeletePolicy); } using (WindchimeEntities wce = new WindchimeEntities()) { var deletePol = (from PolicyEntry pe in wce.PolicyEntries where pe.GroupID == g.GroupID && pe.Policy == pol select pe); foreach (var p in deletePol) { wce.DeleteObject(p); } wce.SaveChanges(); } }
protected void Page_Load(object sender, EventArgs e) { if (this.IsPostBack) { return; } using (WindchimeEntities wce = new WindchimeEntities()) { Author_lst.DataTextField = "Name"; Author_lst.DataValueField = "ID"; Author_lst.DataSource = from User u in wce.CreatorSet.OfType <User>() select new { Name = u.FirstName + " " + u.LastName, ID = u.CreatorID }; Author_lst.DataBind(); if (!string.IsNullOrEmpty(Request.QueryString["ID"])) { id = int.Parse(Request.QueryString["ID"]); Assignment assgn = (from Assignment a in wce.PermissionableEntities.OfType <Assignment>() where a.EntityID == id select a).FirstOrDefault(); if (assgn == null) { throw new ArgumentException("Invalid ID specified as parameter."); } Location_box.Text = assgn.Location; Completed_chk.Checked = (assgn.CompletedDate != null); DueDate_box.Text = assgn.DueDate.ToString(); Name_box.Text = assgn.Name; Summary_box.Text = assgn.Summary; } } }
void Save_Click(object sender, EventArgs e) { Assignment assgn = null; using (WindchimeEntities wce = new WindchimeEntities()) { if (id != null) { assgn = (from Assignment a in wce.PermissionableEntities.OfType <Assignment>() where a.EntityID == id select a).FirstOrDefault(); } if (assgn == null) { assgn = new Assignment(); wce.AddToPermissionableEntities(assgn); } assgn.Summary = Summary_box.Text; assgn.Name = Name_box.Text; assgn.DueDate = DateTime.Parse(DueDate_box.Text); assgn.Location = Location_box.Text; if (Completed_chk.Checked && assgn.CompletedDate == null) { assgn.CompletedDate = DateTime.Now; } else if (!Completed_chk.Checked) { assgn.CompletedDate = null; } wce.SaveChanges(); wce.Refresh(System.Data.Objects.RefreshMode.StoreWins, assgn); id = assgn.EntityID; } }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { return; } // fresh tree //Collections_tree.Nodes.Clear(); using (WindchimeEntities wce = new WindchimeEntities()) { // only want to display top level collections at the root level var topLevelCollections = from Collection c in wce.Collections where c.Parents.Count == 0 select c; foreach (Collection c in topLevelCollections) { var node = new FlyTreeNode(c.Name, c.EntityID.ToString()); //node.ImageUrl = "~/Images/folder-small.png"; // if there are children out there, populate them later. if not, no point in confusing the user c.Children.Load(); if (c.Children.Count != 0) { node.PopulateNodesOnDemand = true; } else { node.PopulateNodesOnDemand = false; } Collections_tree.Nodes.Add(node); } } }
protected void Page_Load(object sender, EventArgs e) { if (this.IsPostBack) { return; } using (WindchimeEntities wce = new WindchimeEntities()) { Author_lst.DataTextField = "Name"; Author_lst.DataValueField = "ID"; Author_lst.DataSource = from User u in wce.CreatorSet.OfType<User>() select new { Name = u.FirstName + " " + u.LastName, ID = u.CreatorID }; Author_lst.DataBind(); if (!string.IsNullOrEmpty(Request.QueryString["ID"])) { id = int.Parse(Request.QueryString["ID"]); Assignment assgn = (from Assignment a in wce.PermissionableEntities.OfType<Assignment>() where a.EntityID == id select a).FirstOrDefault(); if (assgn == null) throw new ArgumentException("Invalid ID specified as parameter."); Location_box.Text = assgn.Location; Completed_chk.Checked = (assgn.CompletedDate != null); DueDate_box.Text = assgn.DueDate.ToString(); Name_box.Text = assgn.Name; Summary_box.Text = assgn.Summary; } } }
public static void DeletePermissionEntry(Group g, PermissionableEntity ent, Permission perm) { if (!DoesUserHavePerm(WindchimeSession.Current.User, ent, Permission.EditPermissions)) { throw new NoPermissionException(Permission.EditPermissions); } if (g == null || ent == null) { return; } using (WindchimeEntities wce = new WindchimeEntities()) { var deletePerm = (from PermissionEntry pe in wce.PermissionEntrySet where pe.GroupID == g.GroupID && pe.EntityID == ent.EntityID && pe.Permission == (int)perm select pe); foreach (var pe in deletePerm) { wce.DeleteObject(pe); } } }
protected void ClearDBButton_Click(object sender, EventArgs e) { using (WindchimeEntities wce = new WindchimeEntities()) { var deleteAssetTypes = (from x in wce.AssetTypeSet select x); var deleteComments = (from x in wce.CommentSet select x); var deleteCreators = (from x in wce.CreatorSet select x); var deleteGroups = (from x in wce.Groups select x); var deleteEnts = (from x in wce.PermissionableEntities select x); var deletePerms = (from x in wce.PermissionEntrySet select x); var deletePols = (from x in wce.PolicyEntries select x); var deleteVers = (from x in wce.VersionSet select x); var deleteAssets = (from x in wce.Assets select x); var deleteColls = (from x in wce.Collections select x); foreach (Group go in wce.Groups) { go.Parents.Load(); var Parents = go.Parents.ToList(); foreach (Group gi in Parents) go.Parents.Remove(gi); } wce.SaveChanges(); foreach (Collection co in wce.Collections) { co.Parents.Load(); var Parents = co.Parents.ToList(); foreach (Collection ci in Parents) co.Parents.Remove(ci); } wce.SaveChanges(); foreach (Asset ao in wce.Assets) { ao.Collections.Load(); var Parents = ao.Collections.ToList(); foreach (Collection ci in Parents) ao.Collections.Remove(ci); } wce.SaveChanges(); foreach (Group go in wce.Groups) { go.Users.Load(); var Parents = go.Users.ToList(); foreach (User ui in Parents) go.Users.Remove(ui); } wce.SaveChanges(); foreach (var a in deleteAssetTypes) wce.DeleteObject(a); foreach (var c in deleteComments) wce.DeleteObject(c); foreach (var c in deleteCreators) wce.DeleteObject(c); foreach (var g in deleteGroups) wce.DeleteObject(g); foreach (var d in deleteEnts) wce.DeleteObject(d); foreach (var p in deletePerms) wce.DeleteObject(p); foreach (var p in deletePols) wce.DeleteObject(p); foreach (var v in deleteVers) wce.DeleteObject(v); foreach (var a in deleteAssets) wce.DeleteObject(a); foreach (var c in deleteColls) wce.DeleteObject(c); wce.SaveChanges(); } LoadTestDataButton.Enabled = true; }
// // Summary: // Adds a new membership user to the data source. // // Parameters: // username: // The user name for the new user. // // password: // The password for the new user. // // email: // The e-mail address for the new user. // // passwordQuestion: // The password question for the new user. // // passwordAnswer: // The password answer for the new user // // isApproved: // Whether or not the new user is approved to be validated. // // providerUserKey: // The unique identifier from the membership data source for the user. // // status: // A System.Web.Security.MembershipCreateStatus enumeration value indicating // whether the user was created successfully. // // Returns: // A System.Web.Security.MembershipUser object populated with the information // for the newly created user. public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { using (WindchimeEntities wce = new WindchimeEntities()) { Regex re = new Regex(this.PasswordStrengthRegularExpression); User u = new User(); Group g = new Group(); u.FirstName = ""; u.LastName = ""; u.Username = username; u.Password = SecurityManager.HashPasswordForStoringInDatabase(password); u.IsStaff = false; u.Email = email; g.Name = username; g.IsSpecial = false; if (username.Length < 6) { status = MembershipCreateStatus.UserRejected; } else if ((from User k in wce.CreatorSet.OfType<User>() where k.Username == username select k).Count<User>() > 0) { status = MembershipCreateStatus.DuplicateUserName; } else if (!re.IsMatch(password)) { status = MembershipCreateStatus.InvalidPassword; } else if (!isEmail(email)) { status = MembershipCreateStatus.InvalidEmail; } else if ((from User k in wce.CreatorSet.OfType<User>() where k.Email == email select k).Count<User>() > 0) { status = MembershipCreateStatus.DuplicateEmail; } else { status = MembershipCreateStatus.Success; wce.AddToCreatorSet(u); wce.AddToGroups(g); g.Users.Add(u); wce.SaveChanges(); // log in the user WindchimeSession.Current.User = u; } } return null; }
public override bool ValidateUser(string strName, string strPassword) { using (WindchimeEntities wce = new WindchimeEntities()) { string pw = SecurityManager.HashPasswordForStoringInDatabase(strPassword); var users = (from User u in wce.CreatorSet.OfType<User>() where u.Username == strName && u.Password == pw select u); int num = users.Count<User>(); if (num > 1) { //throw new MultipleUsersException(); //doesn't exist right now throw new Exception("Multiple users in system with same credentials!"); } else if (num == 0) { return false; } else { WindchimeSession.Current.User = users.First<User>(); return true; } } }
protected void ClearDBButton_Click(object sender, EventArgs e) { using (WindchimeEntities wce = new WindchimeEntities()) { var deleteAssetTypes = (from x in wce.AssetTypeSet select x); var deleteComments = (from x in wce.CommentSet select x); var deleteCreators = (from x in wce.CreatorSet select x); var deleteGroups = (from x in wce.Groups select x); var deleteEnts = (from x in wce.PermissionableEntities select x); var deletePerms = (from x in wce.PermissionEntrySet select x); var deletePols = (from x in wce.PolicyEntries select x); var deleteVers = (from x in wce.VersionSet select x); var deleteAssets = (from x in wce.Assets select x); var deleteColls = (from x in wce.Collections select x); foreach (Group go in wce.Groups) { go.Parents.Load(); var Parents = go.Parents.ToList(); foreach (Group gi in Parents) { go.Parents.Remove(gi); } } wce.SaveChanges(); foreach (Collection co in wce.Collections) { co.Parents.Load(); var Parents = co.Parents.ToList(); foreach (Collection ci in Parents) { co.Parents.Remove(ci); } } wce.SaveChanges(); foreach (Asset ao in wce.Assets) { ao.Collections.Load(); var Parents = ao.Collections.ToList(); foreach (Collection ci in Parents) { ao.Collections.Remove(ci); } } wce.SaveChanges(); foreach (Group go in wce.Groups) { go.Users.Load(); var Parents = go.Users.ToList(); foreach (User ui in Parents) { go.Users.Remove(ui); } } wce.SaveChanges(); foreach (var a in deleteAssetTypes) { wce.DeleteObject(a); } foreach (var c in deleteComments) { wce.DeleteObject(c); } foreach (var c in deleteCreators) { wce.DeleteObject(c); } foreach (var g in deleteGroups) { wce.DeleteObject(g); } foreach (var d in deleteEnts) { wce.DeleteObject(d); } foreach (var p in deletePerms) { wce.DeleteObject(p); } foreach (var p in deletePols) { wce.DeleteObject(p); } foreach (var v in deleteVers) { wce.DeleteObject(v); } foreach (var a in deleteAssets) { wce.DeleteObject(a); } foreach (var c in deleteColls) { wce.DeleteObject(c); } wce.SaveChanges(); } LoadTestDataButton.Enabled = true; }
protected void LoadTestDataButton_Click(object sender, EventArgs e) { WindchimeEntities wce = new WindchimeEntities(); Creator c = new Creator(); c.FirstName = "EIC"; c.LastName = "EIC"; User u1 = SecurityManager.CreateUser(c, "EIC", "windchime*", true, true); c.FirstName = "Regular"; c.LastName = "Staff"; User u2 = SecurityManager.CreateUser(c, "Staff1", "windchime*", true, true); c.FirstName = "Regular"; c.LastName = "User"; User u3 = SecurityManager.CreateUser(c, "Regular1", "windchime*", false, true); Group g = new Group(); g.Name = "Staff"; g.IsSpecial = false; wce.Attach(u1); wce.Attach(u2); u1.Groups.Load(); u2.Groups.Load(); g.Children.Add(u1.Groups.First()); g.Children.Add(u2.Groups.First()); wce.AddToGroups(g); Asset a1 = new Asset(), a2 = new Asset(), a3 = new Asset(), a4 = new Asset(); AssetType at1 = new AssetType(); TextVersion tv1 = new TextVersion(), tv2 = new TextVersion(), tv3 = new TextVersion(), tv4 = new TextVersion(), tv5 = new TextVersion(); at1.Name = "Text"; a1.Approved = true; a2.Approved = false; a3.Approved = false; a4.Approved = true; a1.CompletedDate = DateTime.Now; a2.CompletedDate = DateTime.Now; a3.CompletedDate = DateTime.Now; a4.CompletedDate = DateTime.Now; a1.Creator = u1; a2.Creator = u1; a3.Creator = u2; a4.Creator = u2; a1.Headline = "Asset1!"; a2.Headline = "Asset2!"; a3.Headline = "Asset3!"; a4.Headline = "Asset4!"; a1.Summary = "An asset"; a2.Summary = "An asset"; a3.Summary = "An asset"; a4.Summary = "An asset"; a1.AssetType = at1; a2.AssetType = at1; a3.AssetType = at1; a4.AssetType = at1; tv1.Text = "Asset1 v1"; tv1.CreatedDate = DateTime.Now; tv1.Log = ""; tv2.Text = "Asset1 v2"; tv2.CreatedDate = DateTime.Now; tv2.Log = ""; tv3.Text = "Asset2 v1"; tv3.CreatedDate = DateTime.Now; tv3.Log = ""; tv4.Text = "Asset3 v1"; tv4.CreatedDate = DateTime.Now; tv4.Log = ""; tv5.Text = "Asset4 v1"; tv5.CreatedDate = DateTime.Now; tv5.Log = ""; a1.Versions.Add(tv1); a1.Versions.Add(tv2); a2.Versions.Add(tv3); a3.Versions.Add(tv4); a4.Versions.Add(tv5); wce.AddToPermissionableEntities(a1); wce.AddToPermissionableEntities(a2); wce.AddToPermissionableEntities(a3); wce.AddToPermissionableEntities(a4); wce.AddToVersionSet(tv1); wce.AddToVersionSet(tv2); wce.AddToVersionSet(tv3); wce.AddToVersionSet(tv4); wce.AddToVersionSet(tv5); Collection col1 = new Collection(), col2 = new Collection(), col3 = new Collection(), col4 = new Collection(); col1.Name = "Text stuff1"; col1.Assets.Add(a1); col2.Name = "Text stuff2"; col2.Assets.Add(a2); col3.Name = "Text stuff3"; col3.Assets.Add(a3); col4.Name = "Text stuff4"; col4.Assets.Add(a4); col1.Children.Add(col2); col1.Children.Add(col3); col4.Children.Add(col3); wce.SaveChanges(); g = (from Group gr in wce.Groups where gr.IsSpecial && gr.Name.CompareTo("EIC") == 0 select gr).First(); g.PolicyEntries.Load(); foreach (Policy p in Enum.GetValues(typeof(Policy))) { PolicyEntry pe = new PolicyEntry(); pe.Policy = p; pe.GroupID = g.GroupID; g.PolicyEntries.Add(pe); wce.SaveChanges(); } LoadTestDataButton.Enabled = false; }
protected void Submit_Click(object sender, EventArgs e) { if (!Page.IsValid) { reset_data(); } using (WindchimeEntities wce = new WindchimeEntities()) { var user1 = (from User u in wce.CreatorSet.OfType <User>() where u.Username.Equals(WindchimeSession.Current.User.Username) select u); if (user1.Count() != 1) { Response.Redirect("~/Login.aspx?ReturnUrl=/UserPref.aspx", false); return; } User usr = user1.First <User>(); Regex RegexObj = new Regex("^\\w[\\w.]*@\\w+\\.\\w[\\.\\w]*$"); if ((!boxEmail.Text.Equals("")) && RegexObj.IsMatch(boxEmail.Text)) { usr.Email = boxEmail.Text; } if (!boxFirstName.Text.Equals("")) { usr.FirstName = boxFirstName.Text; } if (!boxLastName.Text.Equals("")) { usr.LastName = boxLastName.Text; } if (!boxAddr1.Text.Equals("")) { usr.Address1 = boxAddr1.Text; } if (!boxAddr2.Text.Equals("")) { usr.Address2 = boxAddr2.Text; } if (!boxCity.Text.Equals("")) { usr.City = boxCity.Text; } usr.State = listState.SelectedValue; if (!boxZip.Text.Equals("")) { usr.PostalCode = boxZip.Text; } WCMembershipProvider wcm = new WCMembershipProvider(); Regex regexPassword = new Regex(wcm.PasswordStrengthRegularExpression); if (boxPassword1.Text.Equals(boxPassword2.Text) && (!boxPassword1.Text.Equals(""))) { if (regexPassword.IsMatch(boxPassword1.Text)) { usr.Password = SecurityManager.HashPasswordForStoringInDatabase(boxPassword1.Text); } } wce.SaveChanges(); } reset_data(); }
public static Group CreateGroup(string name, bool isSpecial, bool overRide) { if (!overRide && !DoesUserHavePolicy(WindchimeSession.Current.User, Policy.CreateGroup)) throw new NoPolicyException(Policy.CreateGroup); if (name.Length < 1) return null; Group g = new Group(); g.Name = name; g.IsSpecial = isSpecial; using (WindchimeEntities wce = new WindchimeEntities()) { wce.AddToGroups(g); wce.SaveChanges(); wce.Detach(g); } return g; }
protected void LoadTestDataButton_Click(object sender, EventArgs e) { WindchimeEntities wce = new WindchimeEntities(); Creator c = new Creator(); c.FirstName = "EIC"; c.LastName = "EIC"; User u1 = SecurityManager.CreateUser(c, "EIC", "windchime*", true, true); c.FirstName = "Regular"; c.LastName = "Staff"; User u2 = SecurityManager.CreateUser(c, "Staff1", "windchime*", true, true); c.FirstName = "Regular"; c.LastName = "User"; User u3 = SecurityManager.CreateUser(c, "Regular1", "windchime*", false, true); Group g = new Group(); g.Name = "Staff"; g.IsSpecial = false; wce.Attach(u1); wce.Attach(u2); u1.Groups.Load(); u2.Groups.Load(); g.Children.Add(u1.Groups.First()); g.Children.Add(u2.Groups.First()); wce.AddToGroups(g); Asset a1 = new Asset(), a2 = new Asset(), a3 = new Asset(), a4 = new Asset(); AssetType at1 = new AssetType(); TextVersion tv1 = new TextVersion(), tv2 = new TextVersion(), tv3 = new TextVersion(), tv4 = new TextVersion(), tv5 = new TextVersion(); at1.Name = "Text"; a1.Approved = true; a2.Approved = false; a3.Approved = false; a4.Approved = true; a1.CompletedDate = DateTime.Now; a2.CompletedDate = DateTime.Now; a3.CompletedDate = DateTime.Now; a4.CompletedDate = DateTime.Now; a1.Creator = u1; a2.Creator = u1; a3.Creator = u2; a4.Creator = u2; a1.Headline = "Asset1!"; a2.Headline = "Asset2!"; a3.Headline = "Asset3!"; a4.Headline = "Asset4!"; a1.Summary = "An asset"; a2.Summary = "An asset"; a3.Summary = "An asset"; a4.Summary = "An asset"; a1.AssetType = at1; a2.AssetType = at1; a3.AssetType = at1; a4.AssetType = at1; tv1.Text = "Asset1 v1"; tv1.CreatedDate = DateTime.Now; tv1.Log = ""; tv2.Text = "Asset1 v2"; tv2.CreatedDate = DateTime.Now; tv2.Log = ""; tv3.Text = "Asset2 v1"; tv3.CreatedDate = DateTime.Now; tv3.Log = ""; tv4.Text = "Asset3 v1"; tv4.CreatedDate = DateTime.Now; tv4.Log = ""; tv5.Text = "Asset4 v1"; tv5.CreatedDate = DateTime.Now; tv5.Log = ""; a1.Versions.Add(tv1); a1.Versions.Add(tv2); a2.Versions.Add(tv3); a3.Versions.Add(tv4); a4.Versions.Add(tv5); wce.AddToPermissionableEntities(a1); wce.AddToPermissionableEntities(a2); wce.AddToPermissionableEntities(a3); wce.AddToPermissionableEntities(a4); wce.AddToVersionSet(tv1); wce.AddToVersionSet(tv2); wce.AddToVersionSet(tv3); wce.AddToVersionSet(tv4); wce.AddToVersionSet(tv5); Collection col1 = new Collection(), col2 = new Collection(), col3 = new Collection(), col4 = new Collection(); col1.Name = "Text stuff1"; col1.Assets.Add(a1); col2.Name = "Text stuff2"; col2.Assets.Add(a2); col3.Name = "Text stuff3"; col3.Assets.Add(a3); col4.Name = "Text stuff4"; col4.Assets.Add(a4); col1.Children.Add(col2); col1.Children.Add(col3); col4.Children.Add(col3); wce.SaveChanges(); g = (from Group gr in wce.Groups where gr.IsSpecial && gr.Name.CompareTo("EIC") == 0 select gr).First(); g.PolicyEntries.Load(); foreach (Policy p in Enum.GetValues(typeof(Policy))) { PolicyEntry pe = new PolicyEntry(); pe.Policy = p; pe.GroupID = g.GroupID; g.PolicyEntries.Add(pe); wce.SaveChanges(); } LoadTestDataButton.Enabled = false; }
/// <summary> /// Creates a new permission and adds it to the database. /// </summary> /// <param name="g">The group to give permission to.</param> /// <param name="ent">The entity on which the permissio act.</param> /// <param name="perm">The permission to give to the group.</param> /// <param name="deny">Whether or not to explicitly deny this permission.</param> /// <param name="applytarget">Whether or not the permission applies to this entity (versus its contents).</param> /// <param name="applycolls">Whether or not the permission applies to collections within this entity.</param> /// <param name="applyassets">Whether or not the permission applies to assets within this entity.</param> /// <returns>The new permission entry or null.</returns> /// <exception cref="NoPolicyException">If the current user does not have the ability to create a new permission.</exception> public static PermissionEntry CreatePermissionEntry(Group g, PermissionableEntity ent, Permission perm, bool deny, bool applytarget, bool applycolls, bool applyassets) { if (!DoesUserHavePerm(WindchimeSession.Current.User, ent, Permission.EditPermissions)) throw new NoPermissionException(Permission.EditPermissions); if (g == null || ent == null) return null; PermissionEntry pent = new PermissionEntry(); pent.GroupID = g.GroupID; pent.EntityID = ent.EntityID; pent.Permission = (int)perm; pent.IsDeny = deny; pent.DoesApplyToTarget = applytarget; pent.DoesApplyToCollections = applycolls; pent.DoesApplyToAssets = applyassets; using (WindchimeEntities wce = new WindchimeEntities()) { wce.AddToPermissionEntrySet(pent); wce.SaveChanges(); wce.Detach(pent); } return pent; }
public static PolicyEntry CreatePolicy(Group g, Policy pol, bool overRide) { if (!overRide && !DoesUserHavePolicy(WindchimeSession.Current.User, Policy.CreatePolicy)) throw new NoPolicyException(Policy.CreatePolicy); if (g == null) return null; PolicyEntry pent = new PolicyEntry(); pent.GroupID = g.GroupID; pent.Policy = pol; using (WindchimeEntities wce = new WindchimeEntities()) { wce.AddToPolicyEntries(pent); wce.SaveChanges(); wce.Detach(pent); } return pent; }
public static User CreateUser(Creator c, string username, string password, bool isStaff, bool overRide) { if (!overRide && !DoesUserHavePolicy(WindchimeSession.Current.User, Policy.CreateUser)) throw new NoPolicyException(Policy.CreateUser); WCMembershipProvider wcm = new WCMembershipProvider(); Regex re = new Regex(wcm.PasswordStrengthRegularExpression); User u; Group g = new Group(); if (c == null || username.Length < 1 || !re.IsMatch(password)) { return null; } u = User.CreateUser(c.CreatorID, c.FirstName, c.LastName, username, SecurityManager.HashPasswordForStoringInDatabase(password), isStaff); g.Name = username; g.IsSpecial = true; using (WindchimeEntities wce = new WindchimeEntities()) { wce.AddToCreatorSet(u); wce.AddToGroups(g); g.Users.Add(u); wce.SaveChanges(); wce.Detach(g); wce.Detach(u); } return u; }
public static void DeletePermissionEntry(Group g, PermissionableEntity ent, Permission perm) { if (!DoesUserHavePerm(WindchimeSession.Current.User, ent, Permission.EditPermissions)) throw new NoPermissionException(Permission.EditPermissions); if (g == null || ent == null) return; using (WindchimeEntities wce = new WindchimeEntities()) { var deletePerm = (from PermissionEntry pe in wce.PermissionEntrySet where pe.GroupID == g.GroupID && pe.EntityID == ent.EntityID && pe.Permission == (int)perm select pe); foreach (var pe in deletePerm) wce.DeleteObject(pe); } }
public static void DeletePolicy(Group g, Policy pol) { if (!DoesUserHavePolicy(WindchimeSession.Current.User, Policy.DeletePolicy)) throw new NoPolicyException(Policy.DeletePolicy); using (WindchimeEntities wce = new WindchimeEntities()) { var deletePol = (from PolicyEntry pe in wce.PolicyEntries where pe.GroupID == g.GroupID && pe.Policy == pol select pe); foreach (var p in deletePol) wce.DeleteObject(p); wce.SaveChanges(); } }