diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Services/UserAccountService/UserAccountService.cs | 184 |
1 files changed, 184 insertions, 0 deletions
diff --git a/OpenSim/Services/UserAccountService/UserAccountService.cs b/OpenSim/Services/UserAccountService/UserAccountService.cs new file mode 100644 index 0000000..c14651d --- /dev/null +++ b/OpenSim/Services/UserAccountService/UserAccountService.cs | |||
@@ -0,0 +1,184 @@ | |||
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 System.Collections.Generic; | ||
34 | using OpenMetaverse; | ||
35 | |||
36 | namespace OpenSim.Services.UserAccountService | ||
37 | { | ||
38 | public class UserAccountService : UserAccountServiceBase, IUserAccountService | ||
39 | { | ||
40 | public UserAccountService(IConfigSource config) : base(config) | ||
41 | { | ||
42 | } | ||
43 | |||
44 | public UserAccount GetUserAccount(UUID scopeID, string firstName, | ||
45 | string lastName) | ||
46 | { | ||
47 | UserAccountData[] d; | ||
48 | |||
49 | if (scopeID != UUID.Zero) | ||
50 | { | ||
51 | d = m_Database.Get( | ||
52 | new string[] {"ScopeID", "FirstName", "LastName"}, | ||
53 | new string[] {scopeID.ToString(), firstName, lastName}); | ||
54 | } | ||
55 | else | ||
56 | { | ||
57 | d = m_Database.Get( | ||
58 | new string[] {"FirstName", "LastName"}, | ||
59 | new string[] {firstName, lastName}); | ||
60 | } | ||
61 | |||
62 | if (d.Length < 1) | ||
63 | return null; | ||
64 | |||
65 | return MakeUserAccount(d[0]); | ||
66 | } | ||
67 | |||
68 | private UserAccount MakeUserAccount(UserAccountData d) | ||
69 | { | ||
70 | UserAccount u = new UserAccount(); | ||
71 | u.FirstName = d.FirstName; | ||
72 | u.LastName = d.LastName; | ||
73 | u.PrincipalID = d.PrincipalID; | ||
74 | u.ScopeID = d.ScopeID; | ||
75 | u.Email = d.Data["Email"].ToString(); | ||
76 | u.Created = Convert.ToInt32(d.Data["Created"].ToString()); | ||
77 | |||
78 | string[] URLs = d.Data["ServiceURLs"].ToString().Split(new char[] {' '}); | ||
79 | u.ServiceURLs = new Dictionary<string, object>(); | ||
80 | |||
81 | foreach(string url in URLs) | ||
82 | { | ||
83 | string[] parts = url.Split(new char[] {'='}); | ||
84 | |||
85 | if (parts.Length != 2) | ||
86 | continue; | ||
87 | |||
88 | string name = System.Web.HttpUtility.UrlDecode(parts[0]); | ||
89 | string val = System.Web.HttpUtility.UrlDecode(parts[1]); | ||
90 | |||
91 | u.ServiceURLs[name] = val; | ||
92 | } | ||
93 | |||
94 | return u; | ||
95 | } | ||
96 | |||
97 | public UserAccount GetUserAccount(UUID scopeID, string email) | ||
98 | { | ||
99 | UserAccountData[] d; | ||
100 | |||
101 | if (scopeID != UUID.Zero) | ||
102 | { | ||
103 | d = m_Database.Get( | ||
104 | new string[] {"ScopeID", "Email"}, | ||
105 | new string[] {scopeID.ToString(), email}); | ||
106 | } | ||
107 | else | ||
108 | { | ||
109 | d = m_Database.Get( | ||
110 | new string[] {"Email"}, | ||
111 | new string[] {email}); | ||
112 | } | ||
113 | |||
114 | if (d.Length < 1) | ||
115 | return null; | ||
116 | |||
117 | return MakeUserAccount(d[0]); | ||
118 | } | ||
119 | |||
120 | public UserAccount GetUserAccount(UUID scopeID, UUID principalID) | ||
121 | { | ||
122 | UserAccountData[] d; | ||
123 | |||
124 | if (scopeID != UUID.Zero) | ||
125 | { | ||
126 | d = m_Database.Get( | ||
127 | new string[] {"ScopeID", "PrincipalID"}, | ||
128 | new string[] {scopeID.ToString(), principalID.ToString()}); | ||
129 | } | ||
130 | else | ||
131 | { | ||
132 | d = m_Database.Get( | ||
133 | new string[] {"PrincipalID"}, | ||
134 | new string[] {principalID.ToString()}); | ||
135 | } | ||
136 | |||
137 | if (d.Length < 1) | ||
138 | return null; | ||
139 | |||
140 | return MakeUserAccount(d[0]); | ||
141 | } | ||
142 | |||
143 | public bool StoreUserAccount(UserAccount data) | ||
144 | { | ||
145 | UserAccountData d = new UserAccountData(); | ||
146 | |||
147 | d.FirstName = data.FirstName; | ||
148 | d.LastName = data.LastName; | ||
149 | d.PrincipalID = data.PrincipalID; | ||
150 | d.ScopeID = data.ScopeID; | ||
151 | d.Data = new Dictionary<string,string>(); | ||
152 | d.Data["Email"] = data.Email; | ||
153 | d.Data["Created"] = data.Created.ToString(); | ||
154 | |||
155 | List<string> parts = new List<string>(); | ||
156 | |||
157 | foreach (KeyValuePair<string,object> kvp in data.ServiceURLs) | ||
158 | { | ||
159 | string key = System.Web.HttpUtility.UrlEncode(kvp.Key); | ||
160 | string val = System.Web.HttpUtility.UrlEncode(kvp.Value.ToString()); | ||
161 | parts.Add(key + "=" + val); | ||
162 | } | ||
163 | |||
164 | d.Data["ServiceURLs"] = string.Join(" ", parts.ToArray()); | ||
165 | |||
166 | return m_Database.Store(d); | ||
167 | } | ||
168 | |||
169 | public List<UserAccount> GetUserAccounts(UUID scopeID, string query) | ||
170 | { | ||
171 | UserAccountData[] d = m_Database.GetUsers(scopeID, query); | ||
172 | |||
173 | if (d == null) | ||
174 | return new List<UserAccount>(); | ||
175 | |||
176 | List<UserAccount> ret = new List<UserAccount>(); | ||
177 | |||
178 | foreach (UserAccountData data in d) | ||
179 | ret.Add(MakeUserAccount(data)); | ||
180 | |||
181 | return ret; | ||
182 | } | ||
183 | } | ||
184 | } | ||