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);
                }
            }
        }