Esempio n. 1
0
        public DmUser GetUserByName(string username)
        {
            try
            {
                var user = _db.Users.FirstOrDefault(u => u.Username == username);
                var dmUser = new DmUser();

                dmUser.Username = user.Username;
                dmUser.Password = user.Password;
                dmUser.Image = user.Image;
                dmUser.LoggedIn = user.LoggedIn;
                dmUser.UserId = user.UserId;

                return dmUser;
            }
            catch (Exception)
            {
                return null;
            }
        }
Esempio n. 2
0
        /**
         * 0: Log in Completed
         * 1: Invalid username or password
         * 2: User already logged in
         * 3: Server offline
         **/
        public string Login(string username, string password)
        {
            var user = _db.Users.FirstOrDefault(u => u.Username == username && u.Password == password);

            if (user == null)
            {
                return "Incorrect username or password";
            }
            foreach (var item in ConnectedUsers)
            {
                if (item.Username == username)
                {
                    return "User already logged in";
                }
            }
            try
            {
                var client = new DmUser();
                var UserConnection = OperationContext.Current.GetCallbackChannel<IClientService>();
                client.Connection = UserConnection;
                client.Username = user.Username;
                client.Password = user.Password;
                client.Image = user.Image;
                client.LoggedIn = user.LoggedIn;
                client.UserId = user.UserId;
                ConnectedUsers.Add(client);
                UpdateHelper(true, client.Username);

                client.LoggedIn = true;
                //Console.ForegroundColor = ConsoleColor.Green;
                //Console.WriteLine("Client login: {0} with id: {1} at {2}", user.Username, user.UserId, DateTime.Now);
                //Console.ResetColor();
                return "Success";
            }
            catch (Exception e)
            {
                return e.ToString();
            }
        }