Beispiel #1
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);
        }
        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;
        }