예제 #1
0
        public static string ValidateUser(string username, string password, string device)
        {
            //in case of login before database have been loaded
            if (Users.Count == 0)
            {
                UserDatabase.Refresh();
            }

            var userRecord = Users.FirstOrDefault(u => u.Item2.ToLower() == username.ToLower() && u.Item3 == password);

            if (userRecord == null)
            {
                //if user is invalid try to refresh cache so we add any newly added users to cache just in case
                UserDatabase.Refresh();
                return(null);
            }

            int    uid    = new Entities.JMMUser(username).JMMUserID;
            string apiKey = "";

            try
            {
                var apiKeys = ActiveApiKeys.First(u => u.Item1 == uid && u.Item2 == device.ToLower());
                apiKey = apiKeys.Item3;
            }
            catch
            {
                apiKey = Guid.NewGuid().ToString();
                ActiveApiKeys.Add(new Tuple <int, string, string>(uid, device.ToLower(), apiKey));
                Entities.AuthTokens token = new Entities.AuthTokens(uid, (device).ToLower(), apiKey);
                RepoFactory.AuthTokens.Save(token);
            }

            return(apiKey);
        }
예제 #2
0
        public static string ValidateUser(string username, string password, string device)
        {
            //in case of login before database have been loaded
            if (Users.Count == 0) { UserDatabase.Refresh(); }

            var userRecord = Users.FirstOrDefault(u => u.Item2.ToLower() == username.ToLower() && u.Item3 == password);

            if (userRecord == null)
            {
                //if user is invalid try to refresh cache so we add any newly added users to cache just in case
                UserDatabase.Refresh();
                return null;
            }

            int uid = new Entities.JMMUser(username).JMMUserID;
            string apiKey = "";
            try
            {
                var apiKeys = ActiveApiKeys.First(u => u.Item1 == uid && u.Item2 == device.ToLower());
                apiKey = apiKeys.Item3;
            }
            catch
            {
                apiKey = Guid.NewGuid().ToString();
                ActiveApiKeys.Add(new Tuple<int, string, string>(uid, device.ToLower(), apiKey));
                Entities.AuthTokens token = new Entities.AuthTokens(uid, (device).ToLower(), apiKey);
                RepoFactory.AuthTokens.Save(token);
            }

            return apiKey;
        }