diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs | 2 | ||||
-rw-r--r-- | OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs | 64 |
2 files changed, 62 insertions, 4 deletions
diff --git a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs index f17a8de..344b513 100644 --- a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs +++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerConnector.cs | |||
@@ -55,7 +55,7 @@ namespace OpenSim.Server.Handlers.UserAccounts | |||
55 | Object[] args = new Object[] { config }; | 55 | Object[] args = new Object[] { config }; |
56 | m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(service, args); | 56 | m_UserAccountService = ServerUtils.LoadPlugin<IUserAccountService>(service, args); |
57 | 57 | ||
58 | server.AddStreamHandler(new UserAccountServerPostHandler(m_UserAccountService)); | 58 | server.AddStreamHandler(new UserAccountServerPostHandler(m_UserAccountService, serverConfig)); |
59 | } | 59 | } |
60 | } | 60 | } |
61 | } | 61 | } |
diff --git a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs index a1d4871..deadce2 100644 --- a/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs +++ b/OpenSim/Server/Handlers/UserAccounts/UserAccountServerPostHandler.cs | |||
@@ -38,6 +38,7 @@ using System.Xml.Serialization; | |||
38 | using System.Collections.Generic; | 38 | using System.Collections.Generic; |
39 | using OpenSim.Server.Base; | 39 | using OpenSim.Server.Base; |
40 | using OpenSim.Services.Interfaces; | 40 | using OpenSim.Services.Interfaces; |
41 | using OpenSim.Services.UserAccountService; | ||
41 | using OpenSim.Framework; | 42 | using OpenSim.Framework; |
42 | using OpenSim.Framework.Servers.HttpServer; | 43 | using OpenSim.Framework.Servers.HttpServer; |
43 | using OpenMetaverse; | 44 | using OpenMetaverse; |
@@ -49,11 +50,18 @@ namespace OpenSim.Server.Handlers.UserAccounts | |||
49 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
50 | 51 | ||
51 | private IUserAccountService m_UserAccountService; | 52 | private IUserAccountService m_UserAccountService; |
53 | private bool m_AllowCreateUser = false; | ||
52 | 54 | ||
53 | public UserAccountServerPostHandler(IUserAccountService service) : | 55 | public UserAccountServerPostHandler(IUserAccountService service) |
56 | : this(service, null) {} | ||
57 | |||
58 | public UserAccountServerPostHandler(IUserAccountService service, IConfig config) : | ||
54 | base("POST", "/accounts") | 59 | base("POST", "/accounts") |
55 | { | 60 | { |
56 | m_UserAccountService = service; | 61 | m_UserAccountService = service; |
62 | |||
63 | if (config != null) | ||
64 | m_AllowCreateUser = config.GetBoolean("AllowCreateUser", m_AllowCreateUser); | ||
57 | } | 65 | } |
58 | 66 | ||
59 | public override byte[] Handle(string path, Stream requestData, | 67 | public override byte[] Handle(string path, Stream requestData, |
@@ -81,6 +89,11 @@ namespace OpenSim.Server.Handlers.UserAccounts | |||
81 | 89 | ||
82 | switch (method) | 90 | switch (method) |
83 | { | 91 | { |
92 | case "createuser": | ||
93 | if (m_AllowCreateUser) | ||
94 | return CreateUser(request); | ||
95 | else | ||
96 | break; | ||
84 | case "getaccount": | 97 | case "getaccount": |
85 | return GetAccount(request); | 98 | return GetAccount(request); |
86 | case "getaccounts": | 99 | case "getaccounts": |
@@ -123,16 +136,20 @@ namespace OpenSim.Server.Handlers.UserAccounts | |||
123 | if (UUID.TryParse(request["UserID"].ToString(), out userID)) | 136 | if (UUID.TryParse(request["UserID"].ToString(), out userID)) |
124 | account = m_UserAccountService.GetUserAccount(scopeID, userID); | 137 | account = m_UserAccountService.GetUserAccount(scopeID, userID); |
125 | } | 138 | } |
126 | |||
127 | else if (request.ContainsKey("Email") && request["Email"] != null) | 139 | else if (request.ContainsKey("Email") && request["Email"] != null) |
140 | { | ||
128 | account = m_UserAccountService.GetUserAccount(scopeID, request["Email"].ToString()); | 141 | account = m_UserAccountService.GetUserAccount(scopeID, request["Email"].ToString()); |
129 | 142 | } | |
130 | else if (request.ContainsKey("FirstName") && request.ContainsKey("LastName") && | 143 | else if (request.ContainsKey("FirstName") && request.ContainsKey("LastName") && |
131 | request["FirstName"] != null && request["LastName"] != null) | 144 | request["FirstName"] != null && request["LastName"] != null) |
145 | { | ||
132 | account = m_UserAccountService.GetUserAccount(scopeID, request["FirstName"].ToString(), request["LastName"].ToString()); | 146 | account = m_UserAccountService.GetUserAccount(scopeID, request["FirstName"].ToString(), request["LastName"].ToString()); |
147 | } | ||
133 | 148 | ||
134 | if (account == null) | 149 | if (account == null) |
150 | { | ||
135 | result["result"] = "null"; | 151 | result["result"] = "null"; |
152 | } | ||
136 | else | 153 | else |
137 | { | 154 | { |
138 | result["result"] = account.ToKeyValuePairs(); | 155 | result["result"] = account.ToKeyValuePairs(); |
@@ -180,6 +197,47 @@ namespace OpenSim.Server.Handlers.UserAccounts | |||
180 | return FailureResult(); | 197 | return FailureResult(); |
181 | } | 198 | } |
182 | 199 | ||
200 | byte[] CreateUser(Dictionary<string, object> request) | ||
201 | { | ||
202 | if (! | ||
203 | request.ContainsKey("FirstName") | ||
204 | && request.ContainsKey("LastName") | ||
205 | && request.ContainsKey("Password")) | ||
206 | return FailureResult(); | ||
207 | |||
208 | Dictionary<string, object> result = new Dictionary<string, object>(); | ||
209 | |||
210 | UUID scopeID = UUID.Zero; | ||
211 | if (request.ContainsKey("ScopeID") && !UUID.TryParse(request["ScopeID"].ToString(), out scopeID)) | ||
212 | return FailureResult(); | ||
213 | |||
214 | UUID principalID = UUID.Random(); | ||
215 | if (request.ContainsKey("UserID") && !UUID.TryParse(request["UserID"].ToString(), out principalID)) | ||
216 | return FailureResult(); | ||
217 | |||
218 | string firstName = request["FirstName"].ToString(); | ||
219 | string lastName = request["LastName"].ToString(); | ||
220 | string password = request["Password"].ToString(); | ||
221 | |||
222 | string email = ""; | ||
223 | if (request.ContainsKey("Email")) | ||
224 | email = request["Email"].ToString(); | ||
225 | |||
226 | UserAccount createdUserAccount = null; | ||
227 | |||
228 | if (m_UserAccountService is UserAccountService) | ||
229 | createdUserAccount | ||
230 | = ((UserAccountService)m_UserAccountService).CreateUser( | ||
231 | scopeID, principalID, firstName, lastName, password, email); | ||
232 | |||
233 | if (createdUserAccount == null) | ||
234 | return FailureResult(); | ||
235 | |||
236 | result["result"] = createdUserAccount.ToKeyValuePairs(); | ||
237 | |||
238 | return ResultToBytes(result); | ||
239 | } | ||
240 | |||
183 | private byte[] SuccessResult() | 241 | private byte[] SuccessResult() |
184 | { | 242 | { |
185 | XmlDocument doc = new XmlDocument(); | 243 | XmlDocument doc = new XmlDocument(); |