* refactor: move CreateUser into UserServiceAdmin

0.6.1-post-fixes
Justin Clarke Casey 2008-11-28 15:34:30 +00:00
parent 27d9e715c0
commit 0862627b34
16 changed files with 135 additions and 191 deletions

View File

@ -474,7 +474,9 @@ namespace OpenSim.ApplicationPlugins.RemoteController
{
m_log.InfoFormat("master avatar does not exist, creating it");
// ...or create new user
userID = m_app.CreateUser(masterFirst, masterLast, masterPassword, "", region.RegionLocX, region.RegionLocY);
userID = m_app.CommunicationsManager.UserServiceAdmin.AddUser(
masterFirst, masterLast, masterPassword, "", region.RegionLocX, region.RegionLocY);
if (userID == UUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}",
masterFirst, masterLast));
}
@ -668,7 +670,9 @@ namespace OpenSim.ApplicationPlugins.RemoteController
if (null != userProfile)
throw new Exception(String.Format("avatar {0} {1} already exists", firstname, lastname));
UUID userID = m_app.CreateUser(firstname, lastname, passwd, email, regX, regY);
UUID userID
= m_app.CommunicationsManager.UserServiceAdmin.AddUser(
firstname, lastname, passwd, email, regX, regY);
if (userID == UUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}",
firstname, lastname));
@ -764,7 +768,9 @@ namespace OpenSim.ApplicationPlugins.RemoteController
if (null != userProfile)
throw new Exception(String.Format("avatar {0} {1} already exists", firstname, lastname));
UUID userID = m_app.CreateUser(firstname, lastname, passwd, email, regX, regY);
UUID userID
= m_app.CommunicationsManager.UserServiceAdmin.AddUser(
firstname, lastname, passwd, email, regX, regY);
if (userID == UUID.Zero) throw new Exception(String.Format("failed to create new user {0} {1}",
firstname, lastname));

View File

@ -106,8 +106,12 @@ namespace OpenSim.Framework.Communications
protected NetworkServersInfo m_networkServersInfo;
/// <summary>
/// Interface to administrative user service calls.
/// Interface to user service for administrating users.
/// </summary>
public IUserServiceAdmin UserServiceAdmin
{
get { return m_userServiceAdmin; }
}
protected IUserServiceAdmin m_userServiceAdmin;
public BaseHttpServer HttpServer
@ -247,63 +251,6 @@ namespace OpenSim.Framework.Communications
}
#endregion
/// <summary>
/// Persistently adds a user to OpenSim.
/// </summary>
/// <param name="firstName"></param>
/// <param name="lastName"></param>
/// <param name="password"></param>
/// <param name="email"></param>
/// <param name="regX"></param>
/// <param name="regY"></param>
/// <returns>The UUID of the added user. Returns UUID.Zero if the add was unsuccessful</returns>
public UUID AddUser(string firstName, string lastName, string password, string email, uint regX, uint regY)
{
string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) + ":" + String.Empty);
m_userServiceAdmin.AddUserProfile(firstName, lastName, md5PasswdHash, email, regX, regY);
UserProfileData userProf = UserService.GetUserProfile(firstName, lastName);
if (userProf == null)
{
return UUID.Zero;
}
else
{
InterServiceInventoryService.CreateNewUserInventory(userProf.ID);
m_log.Info("[USERS]: Created new inventory set for " + firstName + " " + lastName);
return userProf.ID;
}
}
/// <summary>
/// Adds the user.
/// </summary>
/// <param name="firstName">The first name.</param>
/// <param name="lastName">The last name.</param>
/// <param name="password">The password.</param>
/// <param name="email">The email.</param>
/// <param name="regX">The reg X.</param>
/// <param name="regY">The reg Y.</param>
/// <param name="SetUUID">The set UUID.</param>
/// <returns></returns>
public UUID AddUser(string firstName, string lastName, string password, string email, uint regX, uint regY, UUID SetUUID)
{
string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) + ":" + String.Empty);
m_userServiceAdmin.AddUserProfile(firstName, lastName, md5PasswdHash, email, regX, regY, SetUUID);
UserProfileData userProf = UserService.GetUserProfile(firstName, lastName);
if (userProf == null)
{
return UUID.Zero;
}
else
{
InterServiceInventoryService.CreateNewUserInventory(userProf.ID);
m_log.Info("[USERS]: Created new inventory set for " + firstName + " " + lastName);
return userProf.ID;
}
}
/// <summary>
/// Reset a user password

View File

@ -32,29 +32,29 @@ namespace OpenSim.Framework.Communications
public interface IUserServiceAdmin
{
/// <summary>
/// Add a new user profile
/// Add a new user
/// </summary>
/// <param name="firstName">The first name.</param>
/// <param name="lastName">The last name.</param>
/// <param name="firstName">The first name</param>
/// <param name="lastName">The last name</param>
/// <param name="pass">password of avatar</param>
/// <param name="email">email of user</param>
/// <param name="regX">region X.</param>
/// <param name="regY">region Y.</param>
/// <returns></returns>
UUID AddUserProfile(string firstName, string lastName, string pass, string email, uint regX, uint regY);
/// <param name="regX">region X</param>
/// <param name="regY">region Y</param>
/// <returns>The UUID of the created user profile. On failure, returns UUID.Zero</returns>
UUID AddUser(string firstName, string lastName, string pass, string email, uint regX, uint regY);
/// <summary>
/// Adds one for allowing setting of the UUID from modules.. SHOULD ONLY BE USED in very special circumstances!
/// Add a new user with a specified UUID. SHOULD ONLY BE USED in very special circumstances from modules!
/// </summary>
/// <param name="firstName">The first name.</param>
/// <param name="lastName">The last name.</param>
/// <param name="firstName">The first name</param>
/// <param name="lastName">The last name</param>
/// <param name="pass">password of avatar</param>
/// <param name="email">email of user</param>
/// <param name="regX">region X.</param>
/// <param name="regY">region Y.</param>
/// <param name="setUUID">The set UUID.</param>
/// <returns></returns>
UUID AddUserProfile(string firstName, string lastName, string pass, string email, uint regX, uint regY, UUID setUUID);
/// <param name="regX">region X</param>
/// <param name="regY">region Y</param>
/// <param name="setUUID">The set UUID</param>
/// <returns>The UUID of the created user profile. On failure, returns UUID.Zero</returns>
UUID AddUser(string firstName, string lastName, string pass, string email, uint regX, uint regY, UUID setUUID);
/// <summary>
/// Reset a user password

View File

@ -82,7 +82,6 @@ namespace OpenSim.Framework.Communications
get { return "default"; }
}
// See IInventoryServices
public List<InventoryFolderBase> GetInventorySkeleton(UUID userId)
{
// m_log.DebugFormat("[AGENT INVENTORY]: Getting inventory skeleton for {0}", userId);

View File

@ -52,6 +52,17 @@ namespace OpenSim.Framework.Communications
/// List of plugins to search for user data
/// </value>
private List<IUserDataPlugin> _plugins = new List<IUserDataPlugin>();
private IInterServiceInventoryServices m_interServiceInventoryService;
/// <summary>
/// Constructor
/// </summary>
/// <param name="interServiceInventoryService"></param>
public UserManagerBase(IInterServiceInventoryServices interServiceInventoryService)
{
m_interServiceInventoryService = interServiceInventoryService;
}
/// <summary>
/// Add a new user data plugin - plugins will be requested in the order they were added.
@ -80,7 +91,7 @@ namespace OpenSim.Framework.Communications
_plugins.AddRange(loader.Plugins);
}
#region Get UserProfile
#region Get UserProfile
// see IUserService
public UserProfileData GetUserProfile(string fname, string lname)
@ -586,39 +597,42 @@ namespace OpenSim.Framework.Communications
#endregion
/// <summary>
/// Add a new user profile
/// Add a new user
/// </summary>
/// <param name="firstName">first name.</param>
/// <param name="lastName">last name.</param>
/// <param name="pass">password</param>
/// <param name="email">email.</param>
/// <param name="regX">location X.</param>
/// <param name="regY">location Y.</param>
/// <returns></returns>
public UUID AddUserProfile(string firstName, string lastName, string pass, string email, uint regX, uint regY)
/// <param name="firstName">first name</param>
/// <param name="lastName">last name</param>
/// <param name="password">password</param>
/// <param name="email">email</param>
/// <param name="regX">location X</param>
/// <param name="regY">location Y</param>
/// <returns>The UUID of the created user profile. On failure, returns UUID.Zero</returns>
public UUID AddUser(string firstName, string lastName, string password, string email, uint regX, uint regY)
{
return AddUserProfile(firstName, lastName, pass, email, regX, regY, UUID.Random());
return AddUser(firstName, lastName, password, email, regX, regY, UUID.Random());
}
/// <summary>
/// Adds the user profile.
/// Add a new user
/// </summary>
/// <param name="firstName">first name.</param>
/// <param name="lastName">last name.</param>
/// <param name="pass">password</param>
/// <param name="email">email.</param>
/// <param name="regX">location X.</param>
/// <param name="regY">location Y.</param>
/// <param name="firstName">first name</param>
/// <param name="lastName">last name</param>
/// <param name="password">password</param>
/// <param name="email">email</param>
/// <param name="regX">location X</param>
/// <param name="regY">location Y</param>
/// <param name="SetUUID">UUID of avatar.</param>
/// <returns></returns>
public UUID AddUserProfile(string firstName, string lastName, string pass, string email, uint regX, uint regY, UUID SetUUID)
/// <returns>The UUID of the created user profile. On failure, returns UUID.Zero</returns>
public UUID AddUser(
string firstName, string lastName, string password, string email, uint regX, uint regY, UUID SetUUID)
{
string md5PasswdHash = Util.Md5Hash(Util.Md5Hash(password) + ":" + String.Empty);
UserProfileData user = new UserProfileData();
user.HomeLocation = new Vector3(128, 128, 100);
user.ID = SetUUID;
user.FirstName = firstName;
user.SurName = lastName;
user.PasswordHash = pass;
user.PasswordHash = md5PasswdHash;
user.PasswordSalt = String.Empty;
user.Created = Util.UnixTimeSinceEpoch();
user.HomeLookAt = new Vector3(100, 100, 100);
@ -638,7 +652,17 @@ namespace OpenSim.Framework.Communications
}
}
return user.ID;
UserProfileData userProf = GetUserProfile(firstName, lastName);
if (userProf == null)
{
return UUID.Zero;
}
else
{
m_interServiceInventoryService.CreateNewUserInventory(userProf.ID);
return userProf.ID;
}
}
/// <summary>

View File

@ -41,6 +41,15 @@ namespace OpenSim.Grid.MessagingServer
{
class UserManager : UserManagerBase
{
/// <summary>
/// Constructor.
/// </summary>
/// Passing null to parent because we never use any function that requires an interservice inventory call.
public UserManager()
: base(null)
{
}
public UserAgentData GetUserAgentData(UUID AgentID)
{
UserProfileData userProfile = GetUserProfile(AgentID);
@ -53,8 +62,6 @@ namespace OpenSim.Grid.MessagingServer
return null;
}
public override UserProfileData SetupMasterUser(string firstName, string lastName)
{
//throw new Exception("The method or operation is not implemented.");

View File

@ -56,7 +56,6 @@ namespace OpenSim.Grid.UserServer
public UserLoginService m_loginService;
public GridInfoService m_gridInfoService;
public MessageServersConnector m_messagesService;
protected IInterServiceInventoryServices m_interServiceInventoryService;
private UUID m_lastCreatedUser = UUID.Random();
@ -94,17 +93,16 @@ namespace OpenSim.Grid.UserServer
m_stats = StatsManager.StartCollectingUserStats();
m_log.Info("[REGION]: Establishing data connection");
StartupUserManager();
m_log.Info("[STARTUP]: Establishing data connection");
IInterServiceInventoryServices inventoryService = new OGS1InterServiceInventoryService(Cfg.InventoryUrl);
StartupUserManager(inventoryService);
m_userManager.AddPlugin(Cfg.DatabaseProvider, Cfg.DatabaseConnect);
m_gridInfoService = new GridInfoService();
m_interServiceInventoryService = new OGS1InterServiceInventoryService(Cfg.InventoryUrl);
StartupLoginService();
StartupLoginService(inventoryService);
m_messagesService = new MessageServersConnector();
@ -116,22 +114,30 @@ namespace OpenSim.Grid.UserServer
m_messagesService.OnRegionStartup += HandleRegionStartup;
m_messagesService.OnRegionShutdown += HandleRegionShutdown;
m_log.Info("[REGION]: Starting HTTP process");
m_log.Info("[STARTUP]: Starting HTTP process");
m_httpServer = new BaseHttpServer(Cfg.HttpPort);
AddHttpHandlers();
m_httpServer.Start();
}
protected virtual void StartupUserManager()
/// <summary>
/// Start up the user manager
/// </summary>
/// <param name="inventoryService"></param>
protected virtual void StartupUserManager(IInterServiceInventoryServices inventoryService)
{
m_userManager = new UserManager();
m_userManager = new UserManager(new OGS1InterServiceInventoryService(Cfg.InventoryUrl));
}
protected virtual void StartupLoginService()
/// <summary>
/// Start up the login service
/// </summary>
/// <param name="inventoryService"></param>
protected virtual void StartupLoginService(IInterServiceInventoryServices inventoryService)
{
m_loginService = new UserLoginService(
m_userManager, m_interServiceInventoryService, new LibraryRootFolder(), Cfg, Cfg.DefaultStartupMsg);
m_userManager, inventoryService, new LibraryRootFolder(), Cfg, Cfg.DefaultStartupMsg);
}
protected virtual void AddHttpHandlers()
@ -256,39 +262,7 @@ namespace OpenSim.Grid.UserServer
if (null == m_userManager.GetUserProfile(firstName, lastName))
{
password = Util.Md5Hash(Util.Md5Hash(password) + ":" + String.Empty);
UUID userID = new UUID();
try
{
userID = m_userManager.AddUserProfile(firstName, lastName, password, email, regX, regY);
}
catch (Exception ex)
{
m_log.ErrorFormat("[USERS]: Error creating user: {0}", ex.ToString());
}
try
{
if (!m_interServiceInventoryService.CreateNewUserInventory(userID))
{
throw new Exception(
String.Format("The inventory creation request for user {0} did not succeed."
+ " Please contact your inventory service provider for more information.", userID));
}
}
catch (WebException)
{
m_log.ErrorFormat("[USERS]: Could not contact the inventory service at {0} to create an inventory for {1}",
Cfg.InventoryUrl + "CreateInventory/", userID);
}
catch (Exception e)
{
m_log.ErrorFormat("[USERS]: Error creating inventory for user: {0}", e);
}
m_lastCreatedUser = userID;
m_lastCreatedUser = m_userManager.AddUser(firstName, lastName, password, email, regX, regY);
}
else
{

View File

@ -44,6 +44,9 @@ namespace OpenSim.Grid.UserServer
ulong regionhandle, float positionX, float positionY, float positionZ,
string firstname, string lastname);
/// <summary>
/// Login service used in grid mode.
/// </summary>
public class UserLoginService : LoginService
{
protected static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
@ -65,17 +68,16 @@ namespace OpenSim.Grid.UserServer
m_config = config;
m_inventoryService = inventoryService;
}
public void setloginlevel(int level)
{
m_minLoginLevel = level;
m_log.InfoFormat("[GRID] Login Level set to {0} ", level);
}
public void setwelcometext(string text)
{
m_welcomeMessage = text;
m_log.InfoFormat("[GRID] Login text set to {0} ", text);
}
public override void LogOffUser(UserProfileData theUser, string message)

View File

@ -46,6 +46,14 @@ namespace OpenSim.Grid.UserServer
public event logOffUser OnLogOffUser;
private logOffUser handlerLogOffUser;
/// <summary>
/// Constructor
/// </summary>
/// <param name="interServiceInventoryService"></param>
public UserManager(IInterServiceInventoryServices interServiceInventoryService)
: base(interServiceInventoryService)
{}
/// <summary>
/// Deletes an active agent session

View File

@ -535,7 +535,7 @@ namespace OpenSim
}
else
{
m_console.Notice("Create user is not available in grid mode, use the user-server.");
m_console.Notice("Create user is not available in grid mode, use the user server.");
}
break;
}
@ -800,7 +800,7 @@ namespace OpenSim
if (null == m_commsManager.UserService.GetUserProfile(firstName, lastName))
{
CreateUser(firstName, lastName, password, email, regX, regY);
m_commsManager.UserServiceAdmin.AddUser(firstName, lastName, password, email, regX, regY);
}
else
{

View File

@ -298,11 +298,6 @@ namespace OpenSim
m_assetCache = new AssetCache(assetServer);
}
public UUID CreateUser(string tempfirstname, string templastname, string tempPasswd, string email, uint regX, uint regY)
{
return m_commsManager.AddUser(tempfirstname, templastname, tempPasswd, email, regX, regY);
}
public void ProcessLogin(bool LoginEnabled)
{
if (LoginEnabled)
@ -314,8 +309,7 @@ namespace OpenSim
{
m_log.Info("[Login] Login are now disabled ");
m_commsManager.GridService.RegionLoginsEnabled = false;
}
}
}
/// <summary>

View File

@ -94,16 +94,11 @@ namespace OpenSim.Region.Communications.Local
//no current user account so make one
m_log.Info("[LOGIN]: No user account found so creating a new one.");
m_userManager.AddUserProfile(firstname, lastname, "test", "", defaultHomeX, defaultHomeY);
m_userManager.AddUser(firstname, lastname, "test", "", defaultHomeX, defaultHomeY);
profile = m_userManager.GetUserProfile(firstname, lastname);
if (profile != null)
{
m_interServiceInventoryService.CreateNewUserInventory(profile.ID);
}
return profile;
return m_userManager.GetUserProfile(firstname, lastname);
}
return null;
}

View File

@ -34,13 +34,11 @@ namespace OpenSim.Region.Communications.Local
{
public class LocalUserServices : UserManagerBase
{
// private readonly NetworkServersInfo m_serversInfo;
private readonly uint m_defaultHomeX;
private readonly uint m_defaultHomeY;
private IInterServiceInventoryServices m_interServiceInventoryService;
/// <summary>
///
/// User services used when OpenSim is running in standalone mode.
/// </summary>
/// <param name="serversInfo"></param>
/// <param name="defaultHomeLocX"></param>
@ -49,13 +47,12 @@ namespace OpenSim.Region.Communications.Local
/// <param name="statsCollector">Can be null if stats collection is not required.</param>
public LocalUserServices(NetworkServersInfo serversInfo, uint defaultHomeLocX, uint defaultHomeLocY,
IInterServiceInventoryServices interServiceInventoryService)
: base(interServiceInventoryService)
{
// m_serversInfo = serversInfo;
m_defaultHomeX = defaultHomeLocX;
m_defaultHomeY = defaultHomeLocY;
m_interServiceInventoryService = interServiceInventoryService;
}
public override UserProfileData SetupMasterUser(string firstName, string lastName)
@ -72,20 +69,8 @@ namespace OpenSim.Region.Communications.Local
}
Console.WriteLine("Unknown Master User. Sandbox Mode: Creating Account");
AddUserProfile(firstName, lastName, password, "", m_defaultHomeX, m_defaultHomeY);
profile = GetUserProfile(firstName, lastName);
if (profile == null)
{
Console.WriteLine("[LOCAL USER SERVICES]: Unknown Master User after creation attempt. No clue what to do here.");
}
else
{
m_interServiceInventoryService.CreateNewUserInventory(profile.ID);
}
return profile;
AddUser(firstName, lastName, password, "", m_defaultHomeX, m_defaultHomeY);
return GetUserProfile(firstName, lastName);
}
public override UserProfileData SetupMasterUser(UUID uuid)

View File

@ -530,7 +530,10 @@ namespace OpenSim.Region.Environment.Modules.InterGrid
// get seed capagentData.firstname = FirstName;agentData.lastname = LastName;
if (homeScene.CommsManager.UserService.GetUserProfile(agentData.AgentID) == null && !GridMode)
{
homeScene.CommsManager.AddUser(agentData.firstname, agentData.lastname, CreateRandomStr(7), "", homeScene.RegionInfo.RegionLocX, homeScene.RegionInfo.RegionLocY, agentData.AgentID);
homeScene.CommsManager.UserServiceAdmin.AddUser(
agentData.firstname, agentData.lastname, CreateRandomStr(7), "",
homeScene.RegionInfo.RegionLocX, homeScene.RegionInfo.RegionLocY, agentData.AgentID);
UserProfileData userProfile2 = homeScene.CommsManager.UserService.GetUserProfile(agentData.AgentID);
if (userProfile2 != null)
{
@ -539,7 +542,6 @@ namespace OpenSim.Region.Environment.Modules.InterGrid
userProfile.FirstLifeAboutText = "OGP USER";
homeScene.CommsManager.UserService.UpdateUserProfile(userProfile);
}
}
// Stick our data in the cache so the region will know something about us

View File

@ -105,7 +105,8 @@ namespace OpenSim.Region.Environment.Scenes.Tests
((LocalInventoryService)scene.CommsManager.InventoryService).AddPlugin(new TestInventoryDataPlugin());
Assert.That(
scene.CommsManager.AddUser("Bob", "Hoskins", "test", "test@test.com", 1000, 1000, agentId),
scene.CommsManager.UserServiceAdmin.AddUser(
"Bob", "Hoskins", "test", "test@test.com", 1000, 1000, agentId),
Is.EqualTo(agentId));
IClientAPI client = SceneTestUtils.AddRootAgent(scene, agentId);

View File

@ -38,13 +38,13 @@ namespace OpenSim.Region.Environment.Scenes.Tests
public TestCommunicationsManager()
: base(null, null, null, false, null)
{
LocalUserServices lus = new LocalUserServices(null, 991, 992, null);
m_userService = lus;
m_userServiceAdmin = lus;
LocalInventoryService lis = new LocalInventoryService();
m_interServiceInventoryService = lis;
AddInventoryService(lis);
LocalUserServices lus = new LocalUserServices(null, 991, 992, lis);
m_userService = lus;
m_userServiceAdmin = lus;
}
}
}