private IEnumerable<CsvUser> LoadMappedUsers(List<DictionaryMapped> mapped)
		{
			foreach (var map in mapped)
			{
				var user = new CsvUser(IdentityFieldName.Raw, NameFields, EmailFieldName.Raw, map.Attributes);
				if (string.IsNullOrEmpty(user.Identity))
				{
					Log.Debug("User contained no identity data. \nRow Data = " + map.DictionaryData, this);
					continue;
				}
				if (string.IsNullOrEmpty(user.Email))
				{
					Log.Debug("User contained no email data. \nRow Data = "+ map.DictionaryData, this);
					
					//Email isn't required if we have a separate identity column.
					//continue;
				}
				
				yield return user;
			}
		}
コード例 #2
0
		private void CreateUser(CsvUser csvUser)
		{
			UserRole = GetOrCreateRole();

			if (UserRole == null)
			{
				throw new MembershipCreateUserException("Could not get role " + _roleName);
			}

			User membershipUser = GetOrCreateUser(csvUser);
			if (membershipUser == null)
			{
				throw new MembershipCreateUserException(string.Format("Error creating user {0}, {1}", csvUser.Identity, csvUser.Email));
			}

			// Add Role
			if (!membershipUser.IsInRole(UserRole))
			{
				membershipUser.Roles.Add(UserRole);
			}

			// Update Profile
			UpdateProfile(membershipUser, csvUser);
		}
コード例 #3
0
		private void UpdateProfile(User user, CsvUser csvUser)
		{
			Log.Debug("Processing user " + user.Name, this);
			if (user.Profile.UserName != csvUser.Email || user.Profile.Email != csvUser.Email)
			{
				user.Profile.Email = csvUser.Email;
				user.Profile.FullName = csvUser.Name;
			}
			
			foreach (string profileField in GetProfileFields())
			{
				if (string.IsNullOrEmpty(profileField))
				{
					continue;
				}

				if (!csvUser.ProfileProperties.ContainsKey(profileField))
				{
					Log.Warn(string.Format("User profile property {0} was not set for user {1} {2}.", profileField, csvUser.Identity, csvUser.Name), this);
				}
				if (user.Profile.GetCustomProperty(profileField) != csvUser.ProfileProperties[profileField])
				{
					user.Profile.SetCustomProperty(profileField, csvUser.ProfileProperties[profileField]);
				}
			}

			if (user.Profile.IsDirty)
			{
				user.Profile.Save();
			}
		}
コード例 #4
0
		private User GetOrCreateUser(CsvUser csvUser)
		{
			string userName = AddDomain(csvUser.Identity);
			try
			{
				foreach (System.Web.Security.MembershipUser mUser in
					System.Web.Security.Membership.FindUsersByName(userName))
				{
					// have to pass authenticate param to edit profiles
					return User.FromName(mUser.UserName, true);
				}

				// User does not exist so create it
				var newUser = User.Create(userName, UserCsvImportSettings.DefaultUserPassword);
				newUser.Profile.ProfileItemId = _customProfileItem.ID.ToString();
				newUser.Profile.Save();
				Log.Info(string.Format("User {0} created.", newUser.Name), this);
				return newUser;
			}
			catch (Exception ex)
			{
				Log.Error(string.Format("Error creating user {0}, {1}", csvUser.Identity, csvUser.Email), ex, this);
				throw;
			}
		}