* SiteMapNode.cs (GetExplicitResourceString): implement.
[mono-project.git] / mcs / class / System.Web / System.Web.Security / MembershipUser.cs
blob598ecfeab4daf82590aa2c2635e9ecdaf812dd27
1 //
2 // System.Web.Security.MembershipUser
3 //
4 // Authors:
5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 //
7 // (C) 2003 Ben Maurer
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 #if NET_2_0
32 namespace System.Web.Security
34 [Serializable]
35 public class MembershipUser
37 string providerName;
38 string name;
39 object providerUserKey;
40 string email;
41 string passwordQuestion;
42 string comment;
43 bool isApproved;
44 bool isLockedOut;
45 DateTime creationDate;
46 DateTime lastLoginDate;
47 DateTime lastActivityDate;
48 DateTime lastPasswordChangedDate;
49 DateTime lastLockoutDate;
51 protected MembershipUser ()
55 public MembershipUser (string providerName, string name, object providerUserKey, string email,
56 string passwordQuestion, string comment, bool isApproved, bool isLockedOut,
57 DateTime creationDate, DateTime lastLoginDate, DateTime lastActivityDate,
58 DateTime lastPasswordChangedDate, DateTime lastLockoutDate)
60 this.providerName = providerName;
61 this.name = name;
62 this.providerUserKey = providerUserKey;
63 this.email = email;
64 this.passwordQuestion = passwordQuestion;
65 this.comment = comment;
66 this.isApproved = isApproved;
67 this.isLockedOut = isLockedOut;
68 this.creationDate = creationDate.ToUniversalTime ();
69 this.lastLoginDate = lastLoginDate.ToUniversalTime ();
70 this.lastActivityDate = lastActivityDate.ToUniversalTime ();
71 this.lastPasswordChangedDate = lastPasswordChangedDate.ToUniversalTime ();
72 this.lastLockoutDate = lastLockoutDate.ToUniversalTime ();
75 void UpdateSelf (MembershipUser fromUser)
77 try { Comment = fromUser.Comment; } catch (NotSupportedException) {}
78 try { creationDate = fromUser.CreationDate; } catch (NotSupportedException) {}
79 try { Email = fromUser.Email; } catch (NotSupportedException) {}
80 try { IsApproved = fromUser.IsApproved; } catch (NotSupportedException) {}
81 try { isLockedOut = fromUser.IsLockedOut; } catch (NotSupportedException) {}
82 try { LastActivityDate = fromUser.LastActivityDate; } catch (NotSupportedException) {}
83 try { lastLockoutDate = fromUser.LastLockoutDate; } catch (NotSupportedException) {}
84 try { LastLoginDate = fromUser.LastLoginDate; } catch (NotSupportedException) {}
85 try { lastPasswordChangedDate = fromUser.LastPasswordChangedDate; } catch (NotSupportedException) {}
86 try { passwordQuestion = fromUser.PasswordQuestion; } catch (NotSupportedException) {}
87 try { providerUserKey = fromUser.ProviderUserKey; } catch (NotSupportedException) {}
90 internal void UpdateUser ()
92 MembershipUser newUser = Provider.GetUser (name, false);
93 UpdateSelf (newUser);
96 public virtual bool ChangePassword (string oldPassword, string newPassword)
98 bool success = Provider.ChangePassword (UserName, oldPassword, newPassword);
100 UpdateUser ();
102 return success;
105 public virtual bool ChangePasswordQuestionAndAnswer (string password, string newPasswordQuestion, string newPasswordAnswer)
107 bool success = Provider.ChangePasswordQuestionAndAnswer (UserName, password, newPasswordQuestion, newPasswordAnswer);
109 UpdateUser ();
111 return success;
114 public virtual string GetPassword ()
116 return GetPassword (null);
119 public virtual string GetPassword (string answer)
121 return Provider.GetPassword (UserName, answer);
124 public virtual string ResetPassword ()
126 return ResetPassword (null);
129 public virtual string ResetPassword (string answer)
131 string newPass = Provider.ResetPassword (UserName, answer);
133 UpdateUser ();
135 return newPass;
138 public virtual string Comment {
139 get { return comment; }
140 set { comment = value; }
143 public virtual DateTime CreationDate {
144 get { return creationDate.ToLocalTime (); }
147 public virtual string Email {
148 get { return email; }
149 set { email = value; }
152 public virtual bool IsApproved {
153 get { return isApproved; }
154 set { isApproved = value; }
157 public virtual bool IsLockedOut {
158 get { return isLockedOut; }
161 public bool IsOnline {
162 get {
163 return LastActivityDate > DateTime.Now - TimeSpan.FromMinutes (Membership.UserIsOnlineTimeWindow);
167 public virtual DateTime LastActivityDate {
168 get { return lastActivityDate.ToLocalTime (); }
169 set { lastActivityDate = value.ToUniversalTime (); }
172 public virtual DateTime LastLoginDate {
173 get { return lastLoginDate.ToLocalTime (); }
174 set { lastLoginDate = value.ToUniversalTime (); }
177 public virtual DateTime LastPasswordChangedDate {
178 get { return lastPasswordChangedDate.ToLocalTime (); }
181 public virtual DateTime LastLockoutDate {
182 get { return lastLockoutDate.ToLocalTime (); }
185 public virtual string PasswordQuestion {
186 get { return passwordQuestion; }
189 public virtual string ProviderName {
190 get { return providerName; }
193 public virtual string UserName {
194 get { return name; }
197 public virtual object ProviderUserKey {
198 get { return providerUserKey; }
201 public override string ToString ()
203 return UserName;
206 public virtual bool UnlockUser ()
208 bool retval = Provider.UnlockUser (UserName);
210 UpdateUser ();
212 return retval;
215 MembershipProvider Provider {
216 get {
217 MembershipProvider p = Membership.Providers [ProviderName];
218 if (p == null) throw new InvalidOperationException ("Membership provider '" + ProviderName + "' not found.");
219 return p;
224 #endif