当前位置: 首页>>代码示例>>C#>>正文


C# UserAccount.Create方法代码示例

本文整理汇总了C#中UserAccount.Create方法的典型用法代码示例。如果您正苦于以下问题:C# UserAccount.Create方法的具体用法?C# UserAccount.Create怎么用?C# UserAccount.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UserAccount的用法示例。


在下文中一共展示了UserAccount.Create方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateUser

        /// <summary>
        ///     Make a new end user in the database
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="email"></param>
        /// <param name="passwordQuestion"></param>
        /// <param name="passwordAnswer"></param>
        /// <param name="isApproved"></param>
        /// <param name="providerUserKey"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public override MembershipUser CreateUser(
            string username,
            string password,
            string email,
            string passwordQuestion,
            string passwordAnswer,
            bool isApproved,
            object providerUserKey,
            out MembershipCreateStatus status
            )
        {
            username = username.Trim();
            password = password.Trim();
            email = email.Trim();
            if (passwordQuestion != null)
            {
                passwordQuestion = passwordQuestion.Trim();
            }

            if (passwordAnswer != null)
            {
                passwordAnswer = passwordAnswer.Trim();
            }

            // Validate username/password
            var args = new ValidatePasswordEventArgs(username, password, true);
            OnValidatingPassword(args);

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

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

            // Check whether user with passed username already exists
            MembershipUser mu = GetUser(username, false);

            if (mu == null)
            {
                var eu = new UserAccount
                {
                    UserName = username,
                    EMail = email,
                    Password = EncodePassword(password),
                    PasswordFormat = MembershipPasswordFormat.Hashed.ToString(),
                    PasswordSalt = string.Empty,
                    PasswordQuestion = passwordQuestion,
                    PasswordAnswer = EncodePassword(passwordAnswer),
                    FailedPasswordAttemptCount = 0,
                    IsOnLine = false,
                    IsApproved = isApproved,
                    Comment = string.Empty,
                    IsLockedOut = false,
                };
                try
                {
                    eu.Create();

                    status = eu.UserAccountID > 0 ? MembershipCreateStatus.Success : MembershipCreateStatus.UserRejected;
                }
                catch
                {
                    status = MembershipCreateStatus.UserRejected;
                }

                return GetUser(username, false);
            }
            status = MembershipCreateStatus.DuplicateUserName;

            return null;
        }
开发者ID:ryn0,项目名称:kommunity,代码行数:89,代码来源:MembershipProvider.cs


注:本文中的UserAccount.Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。