Esempio n. 1
0
        public User Get(string nameOrGuid)
        {
            Guid userid;

            if (!Guid.TryParse(nameOrGuid, out userid))
            {
                userid = IDGenerator.GetId(nameOrGuid);
            }
            return(this.Get(userid));
        }
Esempio n. 2
0
        public User Validate(string username, string password)
        {
            if (username == null || password == null)
            {
                return(null);
            }
            Dictionary <String, string> para = new Dictionary <string, string>();

            para.Add("UserName", username);
            para.Add("Password", password);

            // check cache first for performance.
            Guid userid = IDGenerator.GetId(username);

            if (this.Cache.ContainsKey(userid) && !Data.AppSettings.IsOnlineServer)
            {
                var cacheuser = this.Cache[userid];
                if (cacheuser.Password != null && cacheuser.Password == password)
                {
                    return(cacheuser);
                }
            }

            var user = Lib.Helper.HttpHelper.Post <User>(ValidateUrl, para);

            if (user == null)
            {
                if (this.Cache.ContainsKey(userid))
                {
                    user = this.Cache[userid];
                }
                else
                {
                    user = GlobalDb.LocalUser.Get(username);
                }
                if (user != null)
                {
                    if (user.Password != null && user.Password == password)
                    {
                        return(user);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            else
            {
                user.Password = password;
                AddOrUpdateTemp(user, true);
            }
            return(user);
        }