Allow an http call to set account details if AllowSetAccount = true in [UserAccountService].

As before, default is false to not allow these calls.
remove-scene-viewer
Justin Clark-Casey (justincc) 2011-10-19 00:06:40 +01:00
parent c85a780583
commit 9d59b285bb
3 changed files with 67 additions and 4 deletions

View File

@ -51,6 +51,7 @@ namespace OpenSim.Server.Handlers.UserAccounts
private IUserAccountService m_UserAccountService;
private bool m_AllowCreateUser = false;
private bool m_AllowSetAccount = false;
public UserAccountServerPostHandler(IUserAccountService service)
: this(service, null) {}
@ -61,7 +62,10 @@ namespace OpenSim.Server.Handlers.UserAccounts
m_UserAccountService = service;
if (config != null)
{
m_AllowCreateUser = config.GetBoolean("AllowCreateUser", m_AllowCreateUser);
m_AllowSetAccount = config.GetBoolean("AllowSetAccount", m_AllowSetAccount);
}
}
public override byte[] Handle(string path, Stream requestData,
@ -99,8 +103,12 @@ namespace OpenSim.Server.Handlers.UserAccounts
case "getaccounts":
return GetAccounts(request);
case "setaccount":
return StoreAccount(request);
if (m_AllowSetAccount)
return StoreAccount(request);
else
break;
}
m_log.DebugFormat("[USER SERVICE HANDLER]: unknown method request: {0}", method);
}
catch (Exception e)
@ -193,8 +201,56 @@ namespace OpenSim.Server.Handlers.UserAccounts
byte[] StoreAccount(Dictionary<string, object> request)
{
// No can do. No changing user accounts from remote sims
return FailureResult();
UUID principalID = UUID.Zero;
if (!(request.ContainsKey("UserID") && UUID.TryParse(request["UserID"].ToString(), out principalID)))
return FailureResult();
UUID scopeID = UUID.Zero;
if (request.ContainsKey("ScopeID") && !UUID.TryParse(request["ScopeID"].ToString(), out scopeID))
return FailureResult();
UserAccount existingAccount = m_UserAccountService.GetUserAccount(scopeID, principalID);
if (existingAccount == null)
return FailureResult();
Dictionary<string, object> result = new Dictionary<string, object>();
if (request.ContainsKey("FirstName"))
existingAccount.FirstName = request["FirstName"].ToString();
if (request.ContainsKey("LastName"))
existingAccount.LastName = request["LastName"].ToString();
if (request.ContainsKey("Email"))
existingAccount.Email = request["Email"].ToString();
int created = 0;
if (request.ContainsKey("Created") && int.TryParse(request["Created"].ToString(), out created))
existingAccount.Created = created;
int userLevel = 0;
if (request.ContainsKey("UserLevel") && int.TryParse(request["UserLevel"].ToString(), out userLevel))
existingAccount.UserFlags = userLevel;
int userFlags = 0;
if (request.ContainsKey("UserFlags") && int.TryParse(request["UserFlags"].ToString(), out userFlags))
existingAccount.UserFlags = userFlags;
if (request.ContainsKey("UserTitle"))
existingAccount.UserTitle = request["UserTitle"].ToString();
if (!m_UserAccountService.StoreUserAccount(existingAccount))
{
m_log.ErrorFormat(
"[USER ACCOUNT SERVER POST HANDLER]: Account store failed for account {0} {1} {2}",
existingAccount.FirstName, existingAccount.LastName, existingAccount.PrincipalID);
return FailureResult();
}
result["result"] = existingAccount.ToKeyValuePairs();
return ResultToBytes(result);
}
byte[] CreateUser(Dictionary<string, object> request)

View File

@ -177,6 +177,10 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003
;; Default is false.
; AllowCreateUser = false
;; Allow the service to process HTTP set account calls.
;; Default is false.
; AllowSetAccount = false
[GridUserService]
; for the server connector

View File

@ -154,13 +154,16 @@ ServiceConnectors = "8003/OpenSim.Server.Handlers.dll:AssetServiceConnector,8003
;; 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
;; Allow the service to process HTTP set account calls.
;; Default is false.
; AllowSetAccount = false
[GridUserService]
; for the server connector