Provide an option to allow remote calls to the CreateUser method on the UserAccountService

Default is false, as before.
Enabling AllowCreateUser in [UserAccountService] for ROBUST allows avatars to be created via an http call, with viewer 2 appropriate bits and pieces.
Only Ruths can be created at present.
Please don't rely on the config since at some point CreateUser will be moved to a separate co-ordinating service.
remove-scene-viewer
Justin Clark-Casey (justincc) 2011-10-18 22:51:40 +01:00
parent 581885da75
commit c85a780583
6 changed files with 84 additions and 10 deletions

View File

@ -55,7 +55,7 @@ namespace OpenSim.Server.Handlers.UserAccounts
Object[] args = new Object[] { config };
m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(service, args);
server.AddStreamHandler(new UserAccountServerPostHandler(m_UserAccountService));
server.AddStreamHandler(new UserAccountServerPostHandler(m_UserAccountService, serverConfig));
}
}
}

View File

@ -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<string, object> request)
{
if (!
request.ContainsKey("FirstName")
&& request.ContainsKey("LastName")
&& request.ContainsKey("Password"))
return FailureResult();
Dictionary<string, object> result = new Dictionary<string, object>();
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();

View File

@ -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
{

View File

@ -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

View File

@ -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

View File

@ -1326,6 +1326,7 @@
<Reference name="OpenSim.Server.Base"/>
<Reference name="OpenSim.Services.Base"/>
<Reference name="OpenSim.Services.Interfaces"/>
<Reference name="OpenSim.Services.UserAccountService"/>
<Reference name="XMLRPC" path="../../../bin/"/>
<Reference name="Nini" path="../../../bin/"/>
<Reference name="log4net" path="../../../bin/"/>