public OnlineListItem(User u) { ID = u.ID; IP = "Unknown"; Name = u.Name; NickName = u.NickName; }
public bool Authenticate(string userName, string password) { if (CurrentUser != null) return false; byte[] pwdHash = SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(password)); using (DB db = new DB()) { var user = (from u in db.Users where u.Name == userName && u.Password == pwdHash select u).SingleOrDefault(); if (user == null) { return false; } lock (App.Clients) { if (App.Clients.ContainsKey(user.ID)) throw new FaultException<AlreadyLoggedInError>(new AlreadyLoggedInError()); App.Clients.Add(user.ID, this); } CurrentUser = user; if (UserLoggedIn != null) System.Threading.Tasks.Task.Factory.StartNew(() => UserLoggedIn(user.ID)); foreach (var s in App.Clients.Values.Where(s => s.SessionMode == LocalCenaServer.SessionType.Server)) { System.Threading.Tasks.Task.Factory.StartNew(() => s.Callback.UserLogin(user.ID)); } return true; } }