Ejemplo n.º 1
0
        private void HandleAuthTokenKey(IDBService dbProxy, IEncryption encryption)
        {
            if (AuthTokenHelper.IsAuthTokenExits(_httpProxy))
            {
                var userId = AuthTokenHelper.GetUserId(_httpProxy, dbProxy, encryption);

                var userTempData = _httpProxy.GetTempValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY);
                if (userTempData == null)
                {
                    ISessionProvider session = new SessionProvider(_httpProxy, dbProxy, _logger);
                    var userData             = session.GetValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY);
                    if (userData != null && userData.user_id != userId)
                    {
                        throw new Exception("Session user conflict with authtoken");
                    }
                    if (userData == null)
                    {
                        userData = dbProxy.FirstOrDefault <UserModel>(CommonConst.Collection.USERS, CommonConst.CommonField.USER_ID, userId);
                        if (userData == null)
                        {
                            throw new Exception("User not found for authtoken");
                        }
                    }
                    _httpProxy.SetTempValue <UserModel>(CommonConst.CommonValue.SESSION_USER_KEY, userData);
                }
            }
        }
Ejemplo n.º 2
0
        public T GetValue <T>(string key)
        {
            var tempData = _httpProxy.GetTempValue <T>(key);

            if (tempData == null)
            {
                JObject filter = new JObject();
                filter[CommonConst.CommonField.SESSION_ID] = _httpProxy.SessionID;
                var sessionData = _dbProxy.Get(CommonConst.Collection.SESSION_DATA, filter.ToString(), new List <string> {
                    key
                });

                if (sessionData.Count == 1 && sessionData[0][key] != null)
                {
                    var value = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(sessionData[0][key].ToString());
                    return(value);
                }
                else
                {
                    return(default(T));
                }
            }
            else
            {
                return(tempData);
            }
        }