示例#1
0
        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);
        }
示例#2
0
        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);
        }
        //
        // 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);
        }
示例#4
0
        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;
        }
        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 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;
        }
        //
        // 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 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;
        }