Some JS generation tests works.
[castle.git] / Samples / PestControl / Castle.Applications.PestControl / Model / Users.cs
blob8d0296fa6ed5ee747dd85fb25fe8a754db4b62b4
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Applications.PestControl.Model
17 using System;
18 using System.Security.Principal;
19 using System.Collections;
21 [Serializable]
22 public class User : Identifiable, IPrincipal, IIdentity
24 String _name; String _pass; String _email;
26 public User(string name, string email, string passwd)
28 _name = name;
29 _email = email;
30 _pass = passwd;
33 public string Name
35 get { return _name; }
36 set { _name = value; }
39 public string Email
41 get { return _email; }
42 set { _email = value; }
45 public string Password
47 get { return _pass; }
48 set { _pass = value; }
51 public bool IsInRole(string role)
53 return false;
56 public IIdentity Identity
58 get { return this; }
61 #region IIdentity Members
63 public bool IsAuthenticated
65 get { return true; }
68 string System.Security.Principal.IIdentity.Name
70 get { return _name; }
73 public string AuthenticationType
75 get { return "custom"; }
78 #endregion
81 /// <summary>
82 /// Summary description for UserCollection.
83 /// </summary>
84 [Serializable]
85 public class UserCollection : ReadOnlyCollectionBase
87 public void Add(User user)
89 lock (this.InnerList.SyncRoot)
91 InnerList.Add(user);
95 public User FindByEmail(String email)
97 lock (this.InnerList.SyncRoot)
99 foreach (User user in this)
101 if (CaseInsensitiveComparer.Default.Compare(user.Email, email) == 0)
103 return user;
108 return null;
111 public bool Authenticate(String email, String password)
113 User user = FindByEmail(email);
115 if (user == null) return false;
117 if (user.Password.Equals(password))
119 return true;
122 return false;