IUserAccountService.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. using System;
  28. using System.Collections.Generic;
  29. using OpenMetaverse;
  30. using OpenSim.Framework;
  31. namespace OpenSim.Services.Interfaces
  32. {
  33. public class UserAccount
  34. {
  35. public UserAccount()
  36. {
  37. }
  38. public UserAccount(UUID principalID)
  39. {
  40. PrincipalID = principalID;
  41. }
  42. /// <summary>
  43. /// Initializes a new instance of the <see cref="OpenSim.Services.Interfaces.UserAccount"/> class.
  44. /// This method is used by externasl/3rd party management applications that need us to create a
  45. /// random UUID for the new user.
  46. /// </summary>
  47. /// <param name='scopeID'>
  48. /// Scope I.
  49. /// </param>
  50. /// <param name='firstName'>
  51. /// First name.
  52. /// </param>
  53. /// <param name='lastName'>
  54. /// Last name.
  55. /// </param>
  56. /// <param name='email'>
  57. /// Email.
  58. /// </param>
  59. public UserAccount(UUID scopeID, string firstName, string lastName, string email)
  60. {
  61. PrincipalID = UUID.Random();
  62. ScopeID = scopeID;
  63. FirstName = firstName;
  64. LastName = lastName;
  65. Email = email;
  66. ServiceURLs = new Dictionary<string, object>();
  67. Created = Util.UnixTimeSinceEpoch();
  68. }
  69. public UserAccount(UUID scopeID, UUID principalID, string firstName, string lastName, string email)
  70. {
  71. PrincipalID = principalID;
  72. ScopeID = scopeID;
  73. FirstName = firstName;
  74. LastName = lastName;
  75. Email = email;
  76. ServiceURLs = new Dictionary<string, object>();
  77. Created = Util.UnixTimeSinceEpoch();
  78. }
  79. public string FirstName;
  80. public string LastName;
  81. public string Email;
  82. public UUID PrincipalID;
  83. public UUID ScopeID;
  84. public int UserLevel;
  85. public int UserFlags;
  86. public string UserTitle;
  87. public string UserCountry;
  88. public Boolean LocalToGrid = true;
  89. public Dictionary<string, object> ServiceURLs;
  90. public int Created;
  91. public string Name
  92. {
  93. get { return FirstName + " " + LastName; }
  94. }
  95. public UserAccount(Dictionary<string, object> kvp)
  96. {
  97. if (kvp.ContainsKey("FirstName"))
  98. FirstName = kvp["FirstName"].ToString();
  99. if (kvp.ContainsKey("LastName"))
  100. LastName = kvp["LastName"].ToString();
  101. if (kvp.ContainsKey("Email"))
  102. Email = kvp["Email"].ToString();
  103. if (kvp.ContainsKey("PrincipalID"))
  104. UUID.TryParse(kvp["PrincipalID"].ToString(), out PrincipalID);
  105. if (kvp.ContainsKey("ScopeID"))
  106. UUID.TryParse(kvp["ScopeID"].ToString(), out ScopeID);
  107. if (kvp.ContainsKey("UserLevel"))
  108. UserLevel = Convert.ToInt32(kvp["UserLevel"].ToString());
  109. if (kvp.ContainsKey("UserFlags"))
  110. UserFlags = Convert.ToInt32(kvp["UserFlags"].ToString());
  111. if (kvp.ContainsKey("UserTitle"))
  112. UserTitle = kvp["UserTitle"].ToString();
  113. if (kvp.ContainsKey("UserCountry"))
  114. UserCountry = kvp["UserCountry"].ToString();
  115. if (kvp.ContainsKey("LocalToGrid"))
  116. Boolean.TryParse(kvp["LocalToGrid"].ToString(), out LocalToGrid);
  117. if (kvp.ContainsKey("Created"))
  118. Created = Convert.ToInt32(kvp["Created"].ToString());
  119. if (kvp.ContainsKey("ServiceURLs") && kvp["ServiceURLs"] != null)
  120. {
  121. ServiceURLs = new Dictionary<string, object>();
  122. string str = kvp["ServiceURLs"].ToString();
  123. if (str != string.Empty)
  124. {
  125. string[] parts = str.Split(new char[] { ';' });
  126. // Dictionary<string, object> dic = new Dictionary<string, object>();
  127. foreach (string s in parts)
  128. {
  129. string[] parts2 = s.Split(new char[] { '*' });
  130. if (parts2.Length == 2)
  131. ServiceURLs[parts2[0]] = parts2[1];
  132. }
  133. }
  134. }
  135. }
  136. public Dictionary<string, object> ToKeyValuePairs()
  137. {
  138. Dictionary<string, object> result = new Dictionary<string, object>();
  139. result["FirstName"] = FirstName;
  140. result["LastName"] = LastName;
  141. result["Email"] = Email;
  142. result["PrincipalID"] = PrincipalID.ToString();
  143. result["ScopeID"] = ScopeID.ToString();
  144. result["Created"] = Created.ToString();
  145. result["UserLevel"] = UserLevel.ToString();
  146. result["UserFlags"] = UserFlags.ToString();
  147. result["UserTitle"] = UserTitle;
  148. result["UserCountry"] = UserCountry;
  149. result["LocalToGrid"] = LocalToGrid.ToString();
  150. string str = string.Empty;
  151. foreach (KeyValuePair<string, object> kvp in ServiceURLs)
  152. {
  153. str += kvp.Key + "*" + (kvp.Value == null ? "" : kvp.Value) + ";";
  154. }
  155. result["ServiceURLs"] = str;
  156. return result;
  157. }
  158. };
  159. public interface IUserAccountService
  160. {
  161. UserAccount GetUserAccount(UUID scopeID, UUID userID);
  162. UserAccount GetUserAccount(UUID scopeID, string FirstName, string LastName);
  163. UserAccount GetUserAccount(UUID scopeID, string Email);
  164. /// <summary>
  165. /// Returns the list of avatars that matches both the search criterion and the scope ID passed
  166. /// </summary>
  167. /// <param name="scopeID"></param>
  168. /// <param name="query"></param>
  169. /// <returns></returns>
  170. List<UserAccount> GetUserAccounts(UUID scopeID, string query);
  171. List<UserAccount> GetUserAccountsWhere(UUID scopeID, string where);
  172. /// <summary>
  173. /// Store the data given, wich replaces the stored data, therefore must be complete.
  174. /// </summary>
  175. /// <param name="data"></param>
  176. /// <returns></returns>
  177. bool StoreUserAccount(UserAccount data);
  178. void InvalidateCache(UUID userID);
  179. }
  180. }