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 (var context = new DataContext())
            {
                if (context.Users.Any(usr => usr.Username == username))
                {
                    status = MembershipCreateStatus.DuplicateUserName;
                    return null;
                }

                if (context.Users.Any(usr => usr.Email == email))
                {
                    status = MembershipCreateStatus.DuplicateEmail;
                    return null;
                }

                User newUser = new User
                {
                    Username = username,
                    Password = password,
                    IsApproved = isApproved,
                    FirstName = username,
                    LastName = username,
                    Email = email,
                    LastPasswordChangedDate = DateTime.UtcNow,
                    PasswordFailuresSinceLastSuccess = 0,
                    LastLoginDate = DateTime.UtcNow,
                    LastActivityDate = DateTime.UtcNow,
                    LastLockoutDate = DateTime.UtcNow,
                    IsLockedOut = false,
                    LastPasswordFailureDate = DateTime.UtcNow,
                    Created = DateTime.Now,
                };

                context.Users.Add(newUser);
                context.SaveChanges();
                status = MembershipCreateStatus.Success;
                if (newUser.Created != null && newUser.LastLoginDate != null && newUser.LastActivityDate != null &&
                    newUser.LastPasswordChangedDate != null && newUser.LastLockoutDate != null)
                    return new MembershipUser(System.Web.Security.Membership.Provider.Name, newUser.Username, newUser.Id,
                                              newUser.Email, null, null, newUser.IsApproved,
                                              newUser.IsLockedOut, newUser.Created.Value,
                                              newUser.LastLoginDate.Value, newUser.LastActivityDate.Value,
                                              newUser.LastPasswordChangedDate.Value,
                                              newUser.LastLockoutDate.Value);
            }
            return null;
        }
 public ModuleFolderContext(HttpContext context, User user, ModuleFolder moduleFolder)
 {
 }
Exemple #3
0
 public ModuleContext(User user, Module module)
 {
     _module = module;
     _user = user;
 }
 public UserNotification(User user, string message)
 {
     _user = user;
     _message = message;
 }