Exemplo n.º 1
0
        public override MembershipUser CreateUser(string username, string password, string email,
                                                  string passwordQuestion, string passwordAnswer, bool isApproved,
                                                  object providerUserKey, out MembershipCreateStatus status)
        {
            if (string.IsNullOrEmpty(username))
            {
                status = MembershipCreateStatus.InvalidUserName;
                return null;
            }
            if (string.IsNullOrEmpty(password))
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            string hashedPassword = Crypto.HashPassword(password);
            if (hashedPassword.Length > 128)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            using (var context = new FootyFeudContext())
            {
                if (context.Users.Any(usr => usr.Username == username))
                {
                    status = MembershipCreateStatus.DuplicateUserName;
                    return null;
                }

                var newUser = new User
                                  {
                                      UserId = Guid.NewGuid(),
                                      Username = username,
                                      Password = hashedPassword,
                                      IsApproved = isApproved,
                                      Email = "*****@*****.**",
                                      CreateDate = DateTime.UtcNow,
                                      LastPasswordChangedDate = DateTime.UtcNow,
                                      PasswordFailuresSinceLastSuccess = 0,
                                      LastLoginDate = DateTime.UtcNow,
                                      LastActivityDate = DateTime.UtcNow,
                                      LastLockoutDate = DateTime.UtcNow,
                                      IsLockedOut = false,
                                      LastPasswordFailureDate = DateTime.UtcNow
                                  };

                context.Users.Add(newUser);
                context.SaveChanges();
                status = MembershipCreateStatus.Success;
                return new MembershipUser(Membership.Provider.Name, newUser.Username, newUser.UserId, newUser.Email,
                                          null, null, newUser.IsApproved, newUser.IsLockedOut, newUser.CreateDate.Value,
                                          newUser.LastLoginDate.Value, newUser.LastActivityDate.Value,
                                          newUser.LastPasswordChangedDate.Value, newUser.LastLockoutDate.Value);
            }
        }
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            if (string.IsNullOrEmpty(username))
            {
                status = MembershipCreateStatus.InvalidUserName;
                return null;
            }
            if (string.IsNullOrEmpty(password))
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }
            if (string.IsNullOrEmpty(email))
            {
                status = MembershipCreateStatus.InvalidEmail;
                return null;
            }

            string HashedPassword = Crypto.HashPassword(password);
            if (HashedPassword.Length > 128)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            using (DataContext Context = new DataContext())
            {
                if (Context.Users.Where(Usr => Usr.Username == username).Any())
                {
                    status = MembershipCreateStatus.DuplicateUserName;
                    return null;
                }

                if (Context.Users.Where(Usr => Usr.Email == email).Any())
                {
                    status = MembershipCreateStatus.DuplicateEmail;
                    return null;
                }

                User NewUser = new User
                {
                    UserId = Guid.NewGuid(),
                    Username = username,
                    Password = HashedPassword,
                    IsApproved = isApproved,
                    Email = email,
                    CreateDate = DateTime.UtcNow,
                    LastPasswordChangedDate = DateTime.UtcNow,
                    PasswordFailuresSinceLastSuccess = 0,
                    LastLoginDate = DateTime.UtcNow,
                    LastActivityDate = DateTime.UtcNow,
                    LastLockoutDate = DateTime.UtcNow,
                    IsLockedOut = false,
                    LastPasswordFailureDate = DateTime.UtcNow
                };

                Context.Users.Add(NewUser);
                Context.SaveChanges();
                status = MembershipCreateStatus.Success;
                return new MembershipUser(System.Web.Security.Membership.Provider.Name, NewUser.Username, NewUser.UserId, NewUser.Email, null, null, NewUser.IsApproved, NewUser.IsLockedOut, NewUser.CreateDate.Value, NewUser.LastLoginDate.Value, NewUser.LastActivityDate.Value, NewUser.LastPasswordChangedDate.Value, NewUser.LastLockoutDate.Value);
            }
        }