diff --git a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs index f17a8deaed..344b513ad2 100644 --- a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs +++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs @@ -55,7 +55,7 @@ namespace OpenSim.Server.Handlers.UserAccounts Object[] args = new Object[] { config }; m_UserAccountService = ServerUtils.LoadPlugin(service, args); - server.AddStreamHandler(new UserAccountServerPostHandler(m_UserAccountService)); + server.AddStreamHandler(new UserAccountServerPostHandler(m_UserAccountService, serverConfig)); } } } diff --git a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs index a1d487128d..deadce25be 100644 --- a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs +++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs @@ -38,6 +38,7 @@ using System.Xml.Serialization; using System.Collections.Generic; using OpenSim.Server.Base; using OpenSim.Services.Interfaces; +using OpenSim.Services.UserAccountService; using OpenSim.Framework; using OpenSim.Framework.Servers.HttpServer; using OpenMetaverse; @@ -49,11 +50,18 @@ namespace OpenSim.Server.Handlers.UserAccounts private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private IUserAccountService m_UserAccountService; + private bool m_AllowCreateUser = false; - public UserAccountServerPostHandler(IUserAccountService service) : + public UserAccountServerPostHandler(IUserAccountService service) + : this(service, null) {} + + public UserAccountServerPostHandler(IUserAccountService service, IConfig config) : base("POST", "/accounts") { m_UserAccountService = service; + + if (config != null) + m_AllowCreateUser = config.GetBoolean("AllowCreateUser", m_AllowCreateUser); } public override byte[] Handle(string path, Stream requestData, @@ -81,6 +89,11 @@ namespace OpenSim.Server.Handlers.UserAccounts switch (method) { + case "createuser": + if (m_AllowCreateUser) + return CreateUser(request); + else + break; case "getaccount": return GetAccount(request); case "getaccounts": @@ -123,16 +136,20 @@ namespace OpenSim.Server.Handlers.UserAccounts if (UUID.TryParse(request["UserID"].ToString(), out userID)) account = m_UserAccountService.GetUserAccount(scopeID, userID); } - else if (request.ContainsKey("Email") && request["Email"] != null) + { account = m_UserAccountService.GetUserAccount(scopeID, request["Email"].ToString()); - + } else if (request.ContainsKey("FirstName") && request.ContainsKey("LastName") && request["FirstName"] != null && request["LastName"] != null) + { account = m_UserAccountService.GetUserAccount(scopeID, request["FirstName"].ToString(), request["LastName"].ToString()); + } if (account == null) + { result["result"] = "null"; + } else { result["result"] = account.ToKeyValuePairs(); @@ -180,6 +197,47 @@ namespace OpenSim.Server.Handlers.UserAccounts return FailureResult(); } + byte[] CreateUser(Dictionary request) + { + if (! + request.ContainsKey("FirstName") + && request.ContainsKey("LastName") + && request.ContainsKey("Password")) + return FailureResult(); + + Dictionary result = new Dictionary(); + + UUID scopeID = UUID.Zero; + if (request.ContainsKey("ScopeID") && !UUID.TryParse(request["ScopeID"].ToString(), out scopeID)) + return FailureResult(); + + UUID principalID = UUID.Random(); + if (request.ContainsKey("UserID") && !UUID.TryParse(request["UserID"].ToString(), out principalID)) + return FailureResult(); + + string firstName = request["FirstName"].ToString(); + string lastName = request["LastName"].ToString(); + string password = request["Password"].ToString(); + + string email = ""; + if (request.ContainsKey("Email")) + email = request["Email"].ToString(); + + UserAccount createdUserAccount = null; + + if (m_UserAccountService is UserAccountService) + createdUserAccount + = ((UserAccountService)m_UserAccountService).CreateUser( + scopeID, principalID, firstName, lastName, password, email); + + if (createdUserAccount == null) + return FailureResult(); + + result["result"] = createdUserAccount.ToKeyValuePairs(); + + return ResultToBytes(result); + } + private byte[] SuccessResult() { XmlDocument doc = new XmlDocument(); diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs index 94258161c1..4a296900b7 100644 --- a/OpenSim/Services/UserAccountService/UserAccountService.cs +++ b/OpenSim/Services/UserAccountService/UserAccountService.cs @@ -505,8 +505,10 @@ namespace OpenSim.Services.UserAccountService firstName, lastName); } else + { m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to retrieve home region for account {0} {1}.", firstName, lastName); + } if (m_InventoryService != null) { @@ -516,13 +518,19 @@ namespace OpenSim.Services.UserAccountService m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to create inventory for account {0} {1}.", firstName, lastName); } - else if (m_CreateDefaultAvatarEntries) + else { - CreateDefaultAppearanceEntries(account.PrincipalID); + m_log.DebugFormat( + "[USER ACCOUNT SERVICE]; Created user inventory for {0} {1}", firstName, lastName); } + + if (m_CreateDefaultAvatarEntries) + CreateDefaultAppearanceEntries(account.PrincipalID); } - m_log.InfoFormat("[USER ACCOUNT SERVICE]: Account {0} {1} created successfully", firstName, lastName); + m_log.InfoFormat( + "[USER ACCOUNT SERVICE]: Account {0} {1} {2} created successfully", + firstName, lastName, account.PrincipalID); } else { diff --git a/bin/Robust.HG.ini.example b/bin/Robust.HG.ini.example index 7f2636ccad..962c2f4344 100644 --- a/bin/Robust.HG.ini.example +++ b/bin/Robust.HG.ini.example @@ -166,14 +166,17 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003 PresenceService = "OpenSim.Services.PresenceService.dll:PresenceService" GridService = "OpenSim.Services.GridService.dll:GridService" InventoryService = "OpenSim.Services.InventoryService.dll:XInventoryService" - ; AvatarService = "OpenSim.Services.AvatarService.dll:AvatarService" + AvatarService = "OpenSim.Services.AvatarService.dll:AvatarService" ;; This switch creates the minimum set of body parts and avatar entries for a viewer 2 ;; to show a default "Ruth" avatar rather than a cloud for a newly created user. ;; Default is false - ;; If you enable this you will also need to uncomment the AvatarService line above ; CreateDefaultAvatarEntries = false + ;; Allow the service to process HTTP create user calls. + ;; Default is false. + ; AllowCreateUser = false + [GridUserService] ; for the server connector diff --git a/bin/Robust.ini.example b/bin/Robust.ini.example index a299a73790..661a15e9a1 100644 --- a/bin/Robust.ini.example +++ b/bin/Robust.ini.example @@ -149,7 +149,7 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003 PresenceService = "OpenSim.Services.PresenceService.dll:PresenceService" GridService = "OpenSim.Services.GridService.dll:GridService" InventoryService = "OpenSim.Services.InventoryService.dll:XInventoryService" - ; AvatarService = "OpenSim.Services.AvatarService.dll:AvatarService" + AvatarService = "OpenSim.Services.AvatarService.dll:AvatarService" ;; This switch creates the minimum set of body parts and avatar entries for a viewer 2 ;; to show a default "Ruth" avatar rather than a cloud for a newly created user. @@ -157,6 +157,10 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003 ;; If you enable this you will also need to uncomment the AvatarService line above ; CreateDefaultAvatarEntries = false + ;; Allow the service to process HTTP create user calls. + ;; Default is false. + ; AllowCreateUser = false + [GridUserService] ; for the server connector diff --git a/prebuild.xml b/prebuild.xml index 8a451569e9..d6db614563 100644 --- a/prebuild.xml +++ b/prebuild.xml @@ -1326,6 +1326,7 @@ +