1
0

IUserAccountService.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 Boolean LocalToGrid = true;
  88. public Dictionary<string, object> ServiceURLs;
  89. public int Created;
  90. public string Name
  91. {
  92. get { return FirstName + " " + LastName; }
  93. }
  94. public UserAccount(Dictionary<string, object> kvp)
  95. {
  96. if (kvp.ContainsKey("FirstName"))
  97. FirstName = kvp["FirstName"].ToString();
  98. if (kvp.ContainsKey("LastName"))
  99. LastName = kvp["LastName"].ToString();
  100. if (kvp.ContainsKey("Email"))
  101. Email = kvp["Email"].ToString();
  102. if (kvp.ContainsKey("PrincipalID"))
  103. UUID.TryParse(kvp["PrincipalID"].ToString(), out PrincipalID);
  104. if (kvp.ContainsKey("ScopeID"))
  105. UUID.TryParse(kvp["ScopeID"].ToString(), out ScopeID);
  106. if (kvp.ContainsKey("UserLevel"))
  107. UserLevel = Convert.ToInt32(kvp["UserLevel"].ToString());
  108. if (kvp.ContainsKey("UserFlags"))
  109. UserFlags = Convert.ToInt32(kvp["UserFlags"].ToString());
  110. if (kvp.ContainsKey("UserTitle"))
  111. UserTitle = kvp["UserTitle"].ToString();
  112. if (kvp.ContainsKey("LocalToGrid"))
  113. Boolean.TryParse(kvp["LocalToGrid"].ToString(), out LocalToGrid);
  114. if (kvp.ContainsKey("Created"))
  115. Created = Convert.ToInt32(kvp["Created"].ToString());
  116. if (kvp.ContainsKey("ServiceURLs") && kvp["ServiceURLs"] != null)
  117. {
  118. ServiceURLs = new Dictionary<string, object>();
  119. string str = kvp["ServiceURLs"].ToString();
  120. if (str != string.Empty)
  121. {
  122. string[] parts = str.Split(new char[] { ';' });
  123. // Dictionary<string, object> dic = new Dictionary<string, object>();
  124. foreach (string s in parts)
  125. {
  126. string[] parts2 = s.Split(new char[] { '*' });
  127. if (parts2.Length == 2)
  128. ServiceURLs[parts2[0]] = parts2[1];
  129. }
  130. }
  131. }
  132. }
  133. public Dictionary<string, object> ToKeyValuePairs()
  134. {
  135. Dictionary<string, object> result = new Dictionary<string, object>();
  136. result["FirstName"] = FirstName;
  137. result["LastName"] = LastName;
  138. result["Email"] = Email;
  139. result["PrincipalID"] = PrincipalID.ToString();
  140. result["ScopeID"] = ScopeID.ToString();
  141. result["Created"] = Created.ToString();
  142. result["UserLevel"] = UserLevel.ToString();
  143. result["UserFlags"] = UserFlags.ToString();
  144. result["UserTitle"] = UserTitle;
  145. result["LocalToGrid"] = LocalToGrid.ToString();
  146. string str = string.Empty;
  147. foreach (KeyValuePair<string, object> kvp in ServiceURLs)
  148. {
  149. str += kvp.Key + "*" + (kvp.Value == null ? "" : kvp.Value) + ";";
  150. }
  151. result["ServiceURLs"] = str;
  152. return result;
  153. }
  154. };
  155. public interface IUserAccountService
  156. {
  157. UserAccount GetUserAccount(UUID scopeID, UUID userID);
  158. UserAccount GetUserAccount(UUID scopeID, string FirstName, string LastName);
  159. UserAccount GetUserAccount(UUID scopeID, string Email);
  160. /// <summary>
  161. /// Returns the list of avatars that matches both the search criterion and the scope ID passed
  162. /// </summary>
  163. /// <param name="scopeID"></param>
  164. /// <param name="query"></param>
  165. /// <returns></returns>
  166. List<UserAccount> GetUserAccounts(UUID scopeID, string query);
  167. /// <summary>
  168. /// Store the data given, wich replaces the stored data, therefore must be complete.
  169. /// </summary>
  170. /// <param name="data"></param>
  171. /// <returns></returns>
  172. bool StoreUserAccount(UserAccount data);
  173. void InvalidateCache(UUID userID);
  174. }
  175. }