diff options
Diffstat (limited to 'OpenSim/Services/UserAccountService')
4 files changed, 630 insertions, 0 deletions
diff --git a/OpenSim/Services/UserAccountService/GridUserService.cs b/OpenSim/Services/UserAccountService/GridUserService.cs new file mode 100644 index 0000000..c6e33bb --- /dev/null +++ b/OpenSim/Services/UserAccountService/GridUserService.cs | |||
@@ -0,0 +1,76 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using Nini.Config; | ||
32 | using OpenSim.Data; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using OpenSim.Framework.Console; | ||
35 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
36 | |||
37 | using OpenMetaverse; | ||
38 | using log4net; | ||
39 | |||
40 | namespace OpenSim.Services.UserAccountService | ||
41 | { | ||
42 | public class GridUserService : GridUserServiceBase, IGridUserService | ||
43 | { | ||
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | public GridUserService(IConfigSource config) : base(config) | ||
47 | { | ||
48 | m_log.Debug("[USER GRID SERVICE]: Starting user grid service"); | ||
49 | } | ||
50 | |||
51 | public GridUserInfo GetGridUserInfo(string userID) | ||
52 | { | ||
53 | GridUserData d = m_Database.GetGridUserData(userID); | ||
54 | |||
55 | GridUserInfo info = new GridUserInfo(); | ||
56 | info.UserID = d.UserID; | ||
57 | info.HomeRegionID = new UUID(d.Data["HomeRegionID"]); | ||
58 | info.HomePosition = Vector3.Parse(d.Data["HomePosition"]); | ||
59 | info.HomeLookAt = Vector3.Parse(d.Data["HomeLookAt"]); | ||
60 | |||
61 | return info; | ||
62 | } | ||
63 | |||
64 | public bool StoreGridUserInfo(GridUserInfo info) | ||
65 | { | ||
66 | GridUserData d = new GridUserData(); | ||
67 | |||
68 | d.Data["UserID"] = info.UserID; | ||
69 | d.Data["HomeRegionID"] = info.HomeRegionID.ToString(); | ||
70 | d.Data["HomePosition"] = info.HomePosition.ToString(); | ||
71 | d.Data["HomeLookAt"] = info.HomeLookAt.ToString(); | ||
72 | |||
73 | return m_Database.StoreGridUserData(d); | ||
74 | } | ||
75 | } | ||
76 | } \ No newline at end of file | ||
diff --git a/OpenSim/Services/UserAccountService/GridUserServiceBase.cs b/OpenSim/Services/UserAccountService/GridUserServiceBase.cs new file mode 100644 index 0000000..990cb63 --- /dev/null +++ b/OpenSim/Services/UserAccountService/GridUserServiceBase.cs | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using Nini.Config; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Data; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using OpenSim.Services.Base; | ||
35 | |||
36 | namespace OpenSim.Services.UserAccountService | ||
37 | { | ||
38 | public class GridUserServiceBase : ServiceBase | ||
39 | { | ||
40 | protected IGridUserData m_Database = null; | ||
41 | |||
42 | public GridUserServiceBase(IConfigSource config) : base(config) | ||
43 | { | ||
44 | string dllName = String.Empty; | ||
45 | string connString = String.Empty; | ||
46 | string realm = "GridUser"; | ||
47 | |||
48 | // | ||
49 | // Try reading the [DatabaseService] section, if it exists | ||
50 | // | ||
51 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
52 | if (dbConfig != null) | ||
53 | { | ||
54 | if (dllName == String.Empty) | ||
55 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
56 | if (connString == String.Empty) | ||
57 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
58 | } | ||
59 | |||
60 | // | ||
61 | // [GridUsetService] section overrides [DatabaseService], if it exists | ||
62 | // | ||
63 | IConfig presenceConfig = config.Configs["GridUserService"]; | ||
64 | if (presenceConfig != null) | ||
65 | { | ||
66 | dllName = presenceConfig.GetString("StorageProvider", dllName); | ||
67 | connString = presenceConfig.GetString("ConnectionString", connString); | ||
68 | realm = presenceConfig.GetString("Realm", realm); | ||
69 | } | ||
70 | |||
71 | // | ||
72 | // We tried, but this doesn't exist. We can't proceed. | ||
73 | // | ||
74 | if (dllName.Equals(String.Empty)) | ||
75 | throw new Exception("No StorageProvider configured"); | ||
76 | |||
77 | m_Database = LoadPlugin<IGridUserData>(dllName, new Object[] { connString, realm }); | ||
78 | if (m_Database == null) | ||
79 | throw new Exception("Could not find a storage interface in the given module " + dllName); | ||
80 | } | ||
81 | } | ||
82 | } \ No newline at end of file | ||
diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs new file mode 100644 index 0000000..35e2826 --- /dev/null +++ b/OpenSim/Services/UserAccountService/UserAccountService.cs | |||
@@ -0,0 +1,399 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using Nini.Config; | ||
32 | using OpenSim.Data; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using OpenSim.Framework.Console; | ||
35 | using GridRegion = OpenSim.Services.Interfaces.GridRegion; | ||
36 | |||
37 | using OpenMetaverse; | ||
38 | using log4net; | ||
39 | |||
40 | namespace OpenSim.Services.UserAccountService | ||
41 | { | ||
42 | public class UserAccountService : UserAccountServiceBase, IUserAccountService | ||
43 | { | ||
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | private static UserAccountService m_RootInstance; | ||
46 | |||
47 | protected IGridService m_GridService; | ||
48 | protected IAuthenticationService m_AuthenticationService; | ||
49 | protected IPresenceService m_PresenceService; | ||
50 | protected IInventoryService m_InventoryService; | ||
51 | |||
52 | public UserAccountService(IConfigSource config) | ||
53 | : base(config) | ||
54 | { | ||
55 | IConfig userConfig = config.Configs["UserAccountService"]; | ||
56 | if (userConfig == null) | ||
57 | throw new Exception("No UserAccountService configuration"); | ||
58 | |||
59 | // In case there are several instances of this class in the same process, | ||
60 | // the console commands are only registered for the root instance | ||
61 | if (m_RootInstance == null) | ||
62 | { | ||
63 | m_RootInstance = this; | ||
64 | string gridServiceDll = userConfig.GetString("GridService", string.Empty); | ||
65 | if (gridServiceDll != string.Empty) | ||
66 | m_GridService = LoadPlugin<IGridService>(gridServiceDll, new Object[] { config }); | ||
67 | |||
68 | string authServiceDll = userConfig.GetString("AuthenticationService", string.Empty); | ||
69 | if (authServiceDll != string.Empty) | ||
70 | m_AuthenticationService = LoadPlugin<IAuthenticationService>(authServiceDll, new Object[] { config }); | ||
71 | |||
72 | string presenceServiceDll = userConfig.GetString("PresenceService", string.Empty); | ||
73 | if (presenceServiceDll != string.Empty) | ||
74 | m_PresenceService = LoadPlugin<IPresenceService>(presenceServiceDll, new Object[] { config }); | ||
75 | |||
76 | string invServiceDll = userConfig.GetString("InventoryService", string.Empty); | ||
77 | if (invServiceDll != string.Empty) | ||
78 | m_InventoryService = LoadPlugin<IInventoryService>(invServiceDll, new Object[] { config }); | ||
79 | |||
80 | if (MainConsole.Instance != null) | ||
81 | { | ||
82 | MainConsole.Instance.Commands.AddCommand("UserService", false, | ||
83 | "create user", | ||
84 | "create user [<first> [<last> [<pass> [<email>]]]]", | ||
85 | "Create a new user", HandleCreateUser); | ||
86 | MainConsole.Instance.Commands.AddCommand("UserService", false, "reset user password", | ||
87 | "reset user password [<first> [<last> [<password>]]]", | ||
88 | "Reset a user password", HandleResetUserPassword); | ||
89 | } | ||
90 | |||
91 | } | ||
92 | |||
93 | } | ||
94 | |||
95 | #region IUserAccountService | ||
96 | |||
97 | public UserAccount GetUserAccount(UUID scopeID, string firstName, | ||
98 | string lastName) | ||
99 | { | ||
100 | UserAccountData[] d; | ||
101 | |||
102 | if (scopeID != UUID.Zero) | ||
103 | { | ||
104 | d = m_Database.Get( | ||
105 | new string[] { "ScopeID", "FirstName", "LastName" }, | ||
106 | new string[] { scopeID.ToString(), firstName, lastName }); | ||
107 | if (d.Length < 1) | ||
108 | { | ||
109 | d = m_Database.Get( | ||
110 | new string[] { "ScopeID", "FirstName", "LastName" }, | ||
111 | new string[] { UUID.Zero.ToString(), firstName, lastName }); | ||
112 | } | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | d = m_Database.Get( | ||
117 | new string[] { "FirstName", "LastName" }, | ||
118 | new string[] { firstName, lastName }); | ||
119 | } | ||
120 | |||
121 | if (d.Length < 1) | ||
122 | return null; | ||
123 | |||
124 | return MakeUserAccount(d[0]); | ||
125 | } | ||
126 | |||
127 | private UserAccount MakeUserAccount(UserAccountData d) | ||
128 | { | ||
129 | UserAccount u = new UserAccount(); | ||
130 | u.FirstName = d.FirstName; | ||
131 | u.LastName = d.LastName; | ||
132 | u.PrincipalID = d.PrincipalID; | ||
133 | u.ScopeID = d.ScopeID; | ||
134 | if (d.Data.ContainsKey("Email") && d.Data["Email"] != null) | ||
135 | u.Email = d.Data["Email"].ToString(); | ||
136 | else | ||
137 | u.Email = string.Empty; | ||
138 | u.Created = Convert.ToInt32(d.Data["Created"].ToString()); | ||
139 | if (d.Data.ContainsKey("UserTitle") && d.Data["UserTitle"] != null) | ||
140 | u.UserTitle = d.Data["UserTitle"].ToString(); | ||
141 | else | ||
142 | u.UserTitle = string.Empty; | ||
143 | if (d.Data.ContainsKey("UserLevel") && d.Data["UserLevel"] != null) | ||
144 | Int32.TryParse(d.Data["UserLevel"], out u.UserLevel); | ||
145 | if (d.Data.ContainsKey("UserFlags") && d.Data["UserFlags"] != null) | ||
146 | Int32.TryParse(d.Data["UserFlags"], out u.UserFlags); | ||
147 | |||
148 | if (d.Data.ContainsKey("ServiceURLs") && d.Data["ServiceURLs"] != null) | ||
149 | { | ||
150 | string[] URLs = d.Data["ServiceURLs"].ToString().Split(new char[] { ' ' }); | ||
151 | u.ServiceURLs = new Dictionary<string, object>(); | ||
152 | |||
153 | foreach (string url in URLs) | ||
154 | { | ||
155 | string[] parts = url.Split(new char[] { '=' }); | ||
156 | |||
157 | if (parts.Length != 2) | ||
158 | continue; | ||
159 | |||
160 | string name = System.Web.HttpUtility.UrlDecode(parts[0]); | ||
161 | string val = System.Web.HttpUtility.UrlDecode(parts[1]); | ||
162 | |||
163 | u.ServiceURLs[name] = val; | ||
164 | } | ||
165 | } | ||
166 | else | ||
167 | u.ServiceURLs = new Dictionary<string, object>(); | ||
168 | |||
169 | return u; | ||
170 | } | ||
171 | |||
172 | public UserAccount GetUserAccount(UUID scopeID, string email) | ||
173 | { | ||
174 | UserAccountData[] d; | ||
175 | |||
176 | if (scopeID != UUID.Zero) | ||
177 | { | ||
178 | d = m_Database.Get( | ||
179 | new string[] { "ScopeID", "Email" }, | ||
180 | new string[] { scopeID.ToString(), email }); | ||
181 | if (d.Length < 1) | ||
182 | { | ||
183 | d = m_Database.Get( | ||
184 | new string[] { "ScopeID", "Email" }, | ||
185 | new string[] { UUID.Zero.ToString(), email }); | ||
186 | } | ||
187 | } | ||
188 | else | ||
189 | { | ||
190 | d = m_Database.Get( | ||
191 | new string[] { "Email" }, | ||
192 | new string[] { email }); | ||
193 | } | ||
194 | |||
195 | if (d.Length < 1) | ||
196 | return null; | ||
197 | |||
198 | return MakeUserAccount(d[0]); | ||
199 | } | ||
200 | |||
201 | public UserAccount GetUserAccount(UUID scopeID, UUID principalID) | ||
202 | { | ||
203 | UserAccountData[] d; | ||
204 | |||
205 | if (scopeID != UUID.Zero) | ||
206 | { | ||
207 | d = m_Database.Get( | ||
208 | new string[] { "ScopeID", "PrincipalID" }, | ||
209 | new string[] { scopeID.ToString(), principalID.ToString() }); | ||
210 | if (d.Length < 1) | ||
211 | { | ||
212 | d = m_Database.Get( | ||
213 | new string[] { "ScopeID", "PrincipalID" }, | ||
214 | new string[] { UUID.Zero.ToString(), principalID.ToString() }); | ||
215 | } | ||
216 | } | ||
217 | else | ||
218 | { | ||
219 | d = m_Database.Get( | ||
220 | new string[] { "PrincipalID" }, | ||
221 | new string[] { principalID.ToString() }); | ||
222 | } | ||
223 | |||
224 | if (d.Length < 1) | ||
225 | { | ||
226 | return null; | ||
227 | } | ||
228 | |||
229 | return MakeUserAccount(d[0]); | ||
230 | } | ||
231 | |||
232 | public bool StoreUserAccount(UserAccount data) | ||
233 | { | ||
234 | UserAccountData d = new UserAccountData(); | ||
235 | |||
236 | d.FirstName = data.FirstName; | ||
237 | d.LastName = data.LastName; | ||
238 | d.PrincipalID = data.PrincipalID; | ||
239 | d.ScopeID = data.ScopeID; | ||
240 | d.Data = new Dictionary<string, string>(); | ||
241 | d.Data["Email"] = data.Email; | ||
242 | d.Data["Created"] = data.Created.ToString(); | ||
243 | d.Data["UserLevel"] = data.UserLevel.ToString(); | ||
244 | d.Data["UserFlags"] = data.UserFlags.ToString(); | ||
245 | if (data.UserTitle != null) | ||
246 | d.Data["UserTitle"] = data.UserTitle.ToString(); | ||
247 | |||
248 | List<string> parts = new List<string>(); | ||
249 | |||
250 | foreach (KeyValuePair<string, object> kvp in data.ServiceURLs) | ||
251 | { | ||
252 | string key = System.Web.HttpUtility.UrlEncode(kvp.Key); | ||
253 | string val = System.Web.HttpUtility.UrlEncode(kvp.Value.ToString()); | ||
254 | parts.Add(key + "=" + val); | ||
255 | } | ||
256 | |||
257 | d.Data["ServiceURLs"] = string.Join(" ", parts.ToArray()); | ||
258 | |||
259 | return m_Database.Store(d); | ||
260 | } | ||
261 | |||
262 | public List<UserAccount> GetUserAccounts(UUID scopeID, string query) | ||
263 | { | ||
264 | UserAccountData[] d = m_Database.GetUsers(scopeID, query); | ||
265 | |||
266 | if (d == null) | ||
267 | return new List<UserAccount>(); | ||
268 | |||
269 | List<UserAccount> ret = new List<UserAccount>(); | ||
270 | |||
271 | foreach (UserAccountData data in d) | ||
272 | ret.Add(MakeUserAccount(data)); | ||
273 | |||
274 | return ret; | ||
275 | } | ||
276 | |||
277 | #endregion | ||
278 | |||
279 | #region Console commands | ||
280 | /// <summary> | ||
281 | /// Create a new user | ||
282 | /// </summary> | ||
283 | /// <param name="cmdparams">string array with parameters: firstname, lastname, password, locationX, locationY, email</param> | ||
284 | protected void HandleCreateUser(string module, string[] cmdparams) | ||
285 | { | ||
286 | string firstName; | ||
287 | string lastName; | ||
288 | string password; | ||
289 | string email; | ||
290 | |||
291 | if (cmdparams.Length < 3) | ||
292 | firstName = MainConsole.Instance.CmdPrompt("First name", "Default"); | ||
293 | else firstName = cmdparams[2]; | ||
294 | |||
295 | if (cmdparams.Length < 4) | ||
296 | lastName = MainConsole.Instance.CmdPrompt("Last name", "User"); | ||
297 | else lastName = cmdparams[3]; | ||
298 | |||
299 | if (cmdparams.Length < 5) | ||
300 | password = MainConsole.Instance.PasswdPrompt("Password"); | ||
301 | else password = cmdparams[4]; | ||
302 | |||
303 | if (cmdparams.Length < 6) | ||
304 | email = MainConsole.Instance.CmdPrompt("Email", ""); | ||
305 | else email = cmdparams[5]; | ||
306 | |||
307 | UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName); | ||
308 | if (null == account) | ||
309 | { | ||
310 | account = new UserAccount(UUID.Zero, firstName, lastName, email); | ||
311 | if (account.ServiceURLs == null || (account.ServiceURLs != null && account.ServiceURLs.Count == 0)) | ||
312 | { | ||
313 | account.ServiceURLs = new Dictionary<string, object>(); | ||
314 | account.ServiceURLs["HomeURI"] = string.Empty; | ||
315 | account.ServiceURLs["GatekeeperURI"] = string.Empty; | ||
316 | account.ServiceURLs["InventoryServerURI"] = string.Empty; | ||
317 | account.ServiceURLs["AssetServerURI"] = string.Empty; | ||
318 | } | ||
319 | |||
320 | if (StoreUserAccount(account)) | ||
321 | { | ||
322 | bool success = false; | ||
323 | if (m_AuthenticationService != null) | ||
324 | success = m_AuthenticationService.SetPassword(account.PrincipalID, password); | ||
325 | if (!success) | ||
326 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set password for account {0} {1}.", | ||
327 | firstName, lastName); | ||
328 | |||
329 | GridRegion home = null; | ||
330 | if (m_GridService != null) | ||
331 | { | ||
332 | List<GridRegion> defaultRegions = m_GridService.GetDefaultRegions(UUID.Zero); | ||
333 | if (defaultRegions != null && defaultRegions.Count >= 1) | ||
334 | home = defaultRegions[0]; | ||
335 | |||
336 | if (m_PresenceService != null && home != null) | ||
337 | m_PresenceService.SetHomeLocation(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0)); | ||
338 | else | ||
339 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to set home for account {0} {1}.", | ||
340 | firstName, lastName); | ||
341 | |||
342 | } | ||
343 | else | ||
344 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to retrieve home region for account {0} {1}.", | ||
345 | firstName, lastName); | ||
346 | |||
347 | if (m_InventoryService != null) | ||
348 | success = m_InventoryService.CreateUserInventory(account.PrincipalID); | ||
349 | if (!success) | ||
350 | m_log.WarnFormat("[USER ACCOUNT SERVICE]: Unable to create inventory for account {0} {1}.", | ||
351 | firstName, lastName); | ||
352 | |||
353 | |||
354 | m_log.InfoFormat("[USER ACCOUNT SERVICE]: Account {0} {1} created successfully", firstName, lastName); | ||
355 | } | ||
356 | } | ||
357 | else | ||
358 | { | ||
359 | m_log.ErrorFormat("[USER ACCOUNT SERVICE]: A user with the name {0} {1} already exists!", firstName, lastName); | ||
360 | } | ||
361 | |||
362 | } | ||
363 | |||
364 | protected void HandleResetUserPassword(string module, string[] cmdparams) | ||
365 | { | ||
366 | string firstName; | ||
367 | string lastName; | ||
368 | string newPassword; | ||
369 | |||
370 | if (cmdparams.Length < 4) | ||
371 | firstName = MainConsole.Instance.CmdPrompt("First name"); | ||
372 | else firstName = cmdparams[3]; | ||
373 | |||
374 | if (cmdparams.Length < 5) | ||
375 | lastName = MainConsole.Instance.CmdPrompt("Last name"); | ||
376 | else lastName = cmdparams[4]; | ||
377 | |||
378 | if (cmdparams.Length < 6) | ||
379 | newPassword = MainConsole.Instance.PasswdPrompt("New password"); | ||
380 | else newPassword = cmdparams[5]; | ||
381 | |||
382 | UserAccount account = GetUserAccount(UUID.Zero, firstName, lastName); | ||
383 | if (account == null) | ||
384 | m_log.ErrorFormat("[USER ACCOUNT SERVICE]: No such user"); | ||
385 | |||
386 | bool success = false; | ||
387 | if (m_AuthenticationService != null) | ||
388 | success = m_AuthenticationService.SetPassword(account.PrincipalID, newPassword); | ||
389 | if (!success) | ||
390 | m_log.ErrorFormat("[USER ACCOUNT SERVICE]: Unable to reset password for account {0} {1}.", | ||
391 | firstName, lastName); | ||
392 | else | ||
393 | m_log.InfoFormat("[USER ACCOUNT SERVICE]: Password reset for user {0} {1}", firstName, lastName); | ||
394 | } | ||
395 | |||
396 | #endregion | ||
397 | |||
398 | } | ||
399 | } | ||
diff --git a/OpenSim/Services/UserAccountService/UserAccountServiceBase.cs b/OpenSim/Services/UserAccountService/UserAccountServiceBase.cs new file mode 100644 index 0000000..c1a7b76 --- /dev/null +++ b/OpenSim/Services/UserAccountService/UserAccountServiceBase.cs | |||
@@ -0,0 +1,73 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Reflection; | ||
30 | using Nini.Config; | ||
31 | using OpenSim.Data; | ||
32 | using OpenSim.Services.Interfaces; | ||
33 | using OpenSim.Services.Base; | ||
34 | |||
35 | namespace OpenSim.Services.UserAccountService | ||
36 | { | ||
37 | public class UserAccountServiceBase: ServiceBase | ||
38 | { | ||
39 | protected IUserAccountData m_Database = null; | ||
40 | |||
41 | public UserAccountServiceBase(IConfigSource config) : base(config) | ||
42 | { | ||
43 | string dllName = String.Empty; | ||
44 | string connString = String.Empty; | ||
45 | string realm = "UserAccounts"; | ||
46 | |||
47 | IConfig dbConfig = config.Configs["DatabaseService"]; | ||
48 | if (dbConfig != null) | ||
49 | { | ||
50 | dllName = dbConfig.GetString("StorageProvider", String.Empty); | ||
51 | connString = dbConfig.GetString("ConnectionString", String.Empty); | ||
52 | } | ||
53 | |||
54 | IConfig userConfig = config.Configs["UserAccountService"]; | ||
55 | if (userConfig == null) | ||
56 | throw new Exception("No UserAccountService configuration"); | ||
57 | |||
58 | dllName = userConfig.GetString("StorageProvider", dllName); | ||
59 | |||
60 | if (dllName == String.Empty) | ||
61 | throw new Exception("No StorageProvider configured"); | ||
62 | |||
63 | connString = userConfig.GetString("ConnectionString", connString); | ||
64 | |||
65 | realm = userConfig.GetString("Realm", realm); | ||
66 | |||
67 | m_Database = LoadPlugin<IUserAccountData>(dllName, new Object[] {connString, realm}); | ||
68 | |||
69 | if (m_Database == null) | ||
70 | throw new Exception("Could not find a storage interface in the given module"); | ||
71 | } | ||
72 | } | ||
73 | } | ||