コード例 #1
0
 private MembershipUser UserToMembershipUser(User user)
 {
   return new MembershipUser(Membership.Provider.Name, user.Username, user.OpenID,
     user.Email, user.UserID_pk.ToString(), null, true, false, user.CreatedDate, 
     user.LastLoginDate ?? new DateTime(1900, 01, 01), user.LastActivityDate ?? new DateTime(1900, 01, 01),
     new DateTime(1900, 01, 01), user.LastLockedOutDate ?? new DateTime(1900, 01, 01));
 }
コード例 #2
0
    public override MembershipUser CreateUser(string username, string password,
      string email, string passwordQuestion, string passwordAnswer, bool isApproved,
      object providerUserKey, out MembershipCreateStatus status)
    {
      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;
      }
      if (string.IsNullOrEmpty(username))
      {
        status = MembershipCreateStatus.InvalidUserName;
        return null;
      }
      if (string.IsNullOrEmpty(password))
      {
        status = MembershipCreateStatus.InvalidPassword;
        return null;
      }
      if (RequiresUniqueEmail && string.IsNullOrEmpty(email))
      {
        status = MembershipCreateStatus.InvalidEmail;
        return null;
      }
      if (RequiresUniqueEmail && mvcMembershipService.GetUserNameByEmail(email) != string.Empty)
      {
        status = MembershipCreateStatus.DuplicateEmail;
        return null;
      }

      var userByOpenID = GetUser(providerUserKey, true);
      var userByUsername = GetUser(username, false);

      if (userByOpenID != null || userByUsername != null)
      {
        status = MembershipCreateStatus.DuplicateUserName;
        return null;
      }

      var userSalt = mvcMembershipService.CreateSalt();
      var hashedPassword = mvcMembershipService.CreatePasswordHash(password, userSalt);

      var newUser = new User
      {
        UserID_pk = Guid.NewGuid(),
        OpenID = (Guid)providerUserKey,
        Username = username,
        Email = email,
        Password = hashedPassword,
        PasswordSalt = userSalt,
        CreatedDate = DateTime.Now,
        IsActivated = false,
        IsApproved = false,
        IsLockedOut = false,
        LastLockedOutDate = DateTime.Now,
        LastActivityDate = DateTime.Now,
        LastLoginDate = DateTime.Now
      };

      mvcMembershipService.AddUser(newUser);

      status = MembershipCreateStatus.Success;
      return GetUser(username, true);
    }
コード例 #3
0
 private MembershipUser UserTouched(User user)
 {
   mvcMembershipService.UserTouched(user);
   return UserToMembershipUser(user);
 }
コード例 #4
0
 public void DeleteUser(User user)
 {
   throw new NotImplementedException();
 }
コード例 #5
0
 public User UserTouched(User user)
 {
   user.LastActivityDate = DateTime.UtcNow;
   SaveChanges();
   return user;
 }
コード例 #6
0
 public User AddUser(User user)
 {
   Add<User>(user);
   Save<User>(user);
   return user;
 }
コード例 #7
0
 public void RemoveUser(User user)
 {
   Delete<User>(user);
 }