IUserAccountService.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. public UserAccount(UUID scopeID, string firstName, string lastName, string email)
  43. {
  44. PrincipalID = UUID.Random();
  45. ScopeID = scopeID;
  46. FirstName = firstName;
  47. LastName = lastName;
  48. Email = email;
  49. ServiceURLs = new Dictionary<string, object>();
  50. Created = Util.UnixTimeSinceEpoch();
  51. }
  52. public string FirstName;
  53. public string LastName;
  54. public string Email;
  55. public UUID PrincipalID;
  56. public UUID ScopeID;
  57. public int UserLevel;
  58. public int UserFlags;
  59. public string UserTitle;
  60. public Dictionary<string, object> ServiceURLs;
  61. public int Created;
  62. public string Name
  63. {
  64. get { return FirstName + " " + LastName; }
  65. }
  66. public UserAccount(Dictionary<string, object> kvp)
  67. {
  68. if (kvp.ContainsKey("FirstName"))
  69. FirstName = kvp["FirstName"].ToString();
  70. if (kvp.ContainsKey("LastName"))
  71. LastName = kvp["LastName"].ToString();
  72. if (kvp.ContainsKey("Email"))
  73. Email = kvp["Email"].ToString();
  74. if (kvp.ContainsKey("PrincipalID"))
  75. UUID.TryParse(kvp["PrincipalID"].ToString(), out PrincipalID);
  76. if (kvp.ContainsKey("ScopeID"))
  77. UUID.TryParse(kvp["ScopeID"].ToString(), out ScopeID);
  78. if (kvp.ContainsKey("UserLevel"))
  79. UserLevel = Convert.ToInt32(kvp["UserLevel"].ToString());
  80. if (kvp.ContainsKey("UserFlags"))
  81. UserFlags = Convert.ToInt32(kvp["UserFlags"].ToString());
  82. if (kvp.ContainsKey("UserTitle"))
  83. UserTitle = kvp["UserTitle"].ToString();
  84. if (kvp.ContainsKey("Created"))
  85. Created = Convert.ToInt32(kvp["Created"].ToString());
  86. if (kvp.ContainsKey("ServiceURLs") && kvp["ServiceURLs"] != null)
  87. {
  88. ServiceURLs = new Dictionary<string, object>();
  89. string str = kvp["ServiceURLs"].ToString();
  90. if (str != string.Empty)
  91. {
  92. string[] parts = str.Split(new char[] { ';' });
  93. // Dictionary<string, object> dic = new Dictionary<string, object>();
  94. foreach (string s in parts)
  95. {
  96. string[] parts2 = s.Split(new char[] { '*' });
  97. if (parts2.Length == 2)
  98. ServiceURLs[parts2[0]] = parts2[1];
  99. }
  100. }
  101. }
  102. }
  103. public Dictionary<string, object> ToKeyValuePairs()
  104. {
  105. Dictionary<string, object> result = new Dictionary<string, object>();
  106. result["FirstName"] = FirstName;
  107. result["LastName"] = LastName;
  108. result["Email"] = Email;
  109. result["PrincipalID"] = PrincipalID.ToString();
  110. result["ScopeID"] = ScopeID.ToString();
  111. result["Created"] = Created.ToString();
  112. result["UserLevel"] = UserLevel.ToString();
  113. result["UserFlags"] = UserFlags.ToString();
  114. result["UserTitle"] = UserTitle;
  115. string str = string.Empty;
  116. foreach (KeyValuePair<string, object> kvp in ServiceURLs)
  117. {
  118. str += kvp.Key + "*" + (kvp.Value == null ? "" : kvp.Value) + ";";
  119. }
  120. result["ServiceURLs"] = str;
  121. return result;
  122. }
  123. };
  124. public interface IUserAccountService
  125. {
  126. UserAccount GetUserAccount(UUID scopeID, UUID userID);
  127. UserAccount GetUserAccount(UUID scopeID, string FirstName, string LastName);
  128. UserAccount GetUserAccount(UUID scopeID, string Email);
  129. /// <summary>
  130. /// Returns the list of avatars that matches both the search criterion and the scope ID passed
  131. /// </summary>
  132. /// <param name="scopeID"></param>
  133. /// <param name="query"></param>
  134. /// <returns></returns>
  135. List<UserAccount> GetUserAccounts(UUID scopeID, string query);
  136. /// <summary>
  137. /// Store the data given, wich replaces the stored data, therefore must be complete.
  138. /// </summary>
  139. /// <param name="data"></param>
  140. /// <returns></returns>
  141. bool StoreUserAccount(UserAccount data);
  142. }
  143. }