コード例 #1
0
        public MembershipUser NewUser(string username, string password, string email, string firstName, string lastName, UserRole userRole, bool isApproved, out MembershipCreateStatus status)
        {
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);
            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (RequiresUniqueEmail && GetUserNameByEmail(email) != "")
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            //status = MembershipCreateStatus.InvalidAnswer;
            MembershipUser user = GetUser(email, false);
            if (user == null)
            {
                UserBL userBL = new UserBL();
                string salt = userBL.getSalt();
                password = userBL.hashPassword(password, salt);
                if (userBL.Save(FirstName, LastName, username, password, email, UserRole.ID, salt, 0) > 0)
                    status = MembershipCreateStatus.Success;
                else
                    status = MembershipCreateStatus.UserRejected;
            }
            else
                status = MembershipCreateStatus.DuplicateUserName;

            return null;
        }