private MembershipUser getMembershipUserFromDnUser(User user)
 {
     MembershipUser mUser = new MembershipUser("DNMembershipProvider",
                             user.UserName,
                             user.AuthorizatonKey,
                             user.Email,
                             null,                       // passwordAnswer
                             null,                       // passwordQuestion
                             true,                       // isAproved 
                             false,
                             user.CreateDate,
                             new DateTime(2009, 01, 01),
                             new DateTime(2009, 01, 01),
                             new DateTime(2009, 01, 01),
                             new DateTime(2009, 01, 01));
     return mUser;
 }
        public override MembershipUser CreateUser(string username,
                     string password,
                     string email,
                     string passwordQuestion,
                     string passwordAnswer,
                     bool isApproved,
                     object providerUserKey,
                     out MembershipCreateStatus status)
        {
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);
            OnValidatingPassword(args);
            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

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

            MembershipUser u = GetUser(username, false);

            if (u == null)
            {
                DateTime createDate = DateTime.Now;

                if (providerUserKey == null)
                    providerUserKey = Guid.NewGuid();
                else if (!(providerUserKey is Guid))
                {
                    status = MembershipCreateStatus.InvalidProviderUserKey;
                    return null;
                }

                User user = new User()
                {
                    UserId = 0,
                    CreateDate = DateTime.Now,
                    Email = email,
                    UserName = username,
                    PasswordHash = CreatePasswordHash(password),
                    AuthorizatonKey = (Guid)providerUserKey
                };

                int userId = new UserDAO().Add(user);
                MembershipUser mUser = getMembershipUserFromDnUser(user);

                if (userId > 0)
                    status = MembershipCreateStatus.Success;
                else
                   status = MembershipCreateStatus.UserRejected;

                return mUser;
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }
            return null;
        }
Exemple #3
0
 public void Update(User user)
 {
     user.CreateDate = new DateTime();
     user.AuthorizatonKey = Guid.Empty;
     new UserDAO().Update(user);
 }