Пример #1
0
        /// <summary>
        /// 使用POCO初始化。
        /// </summary>
        /// <param name="poco">用来初始化的POCO对象。</param>
        public EFUser(EFUserPoco poco)
            : base("EFMembershipProvider", poco.UserName, poco.Id, poco.Email, string.Empty, poco.Comment, poco.IsApproved, false, poco.CreationDate, poco.LastLoginDate, DateTime.Now, poco.LastPasswordChangedDate, DateTime.MinValue)
        {
            if (poco == null)
            {
                poco = new EFUserPoco();
            }

            this.Password = poco.Password;
            this.RealName = poco.RealName;
            this.TelNumber = poco.TelNumber;
        }
Пример #2
0
        /// <summary>
        /// 将新的成员资格用户添加到数据源。
        /// </summary>
        /// <param name="userName">新用户的用户名。</param>
        /// <param name="password">新用户的密码。</param>
        /// <param name="email">新用户的电子邮件地址。</param>
        /// <param name="passwordQuestion">该参数暂不支持,请使用String.Empty。</param>
        /// <param name="passwordAnswer">该参数暂不支持,请使用String.Empty。</param>
        /// <param name="isApproved">是否允许验证新用户。</param>
        /// <param name="providerUserKey">该参数不支持指定,请使用null。</param>
        /// <param name="status">一个 MembershipCreateStatus 枚举值,指示是否已成功创建用户。</param>
        /// <returns>一个用新创建的用户的信息填充的 MembershipUser 对象。</returns>
        public override MembershipUser CreateUser(string userName, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            Contract.Requires(!string.IsNullOrWhiteSpace(userName));
            Contract.Requires(!string.IsNullOrWhiteSpace(password));

            using (var db = this.getDBContext())
            {
                var user = db.Users.SingleOrDefault(u => u.UserName == userName);

                if (user != null)
                {
                    status = MembershipCreateStatus.DuplicateUserName;
                    return new EFUser(user);
                }

                user = new EFUserPoco()
                {
                    UserName = userName,
                    Password = this.EncodePassword(password),
                    Email = email,
                    IsApproved = isApproved,
                    CreationDate = DateTime.Now,
                    LastLoginDate = DateTime.Now,
                    LastPasswordChangedDate = DateTime.Now
                };
                db.Users.Add(user);

                db.SaveChanges();

                status = MembershipCreateStatus.Success;
                return new EFUser(user);
            }
        }