示例#1
0
        private static bool _CheckRight(EUserRights requestedRight)
        {
            Guid sessionKey = _GetSession();

            if (sessionKey == Guid.Empty)
            {
                if (WebOperationContext.Current != null)
                {
                    WebOperationContext.Current.OutgoingResponse.StatusCode        = HttpStatusCode.Forbidden;
                    WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
                }
                return(false);
            }

            if (!CSessionControl.RequestRight(sessionKey, requestedRight))
            {
                if (WebOperationContext.Current != null)
                {
                    WebOperationContext.Current.OutgoingResponse.StatusCode        = HttpStatusCode.Forbidden;
                    WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
                }
                return(false);
            }
            return(true);
        }
示例#2
0
        public int GetOwnProfileId()
        {
            Guid sessionKey = _GetSession();

            if (sessionKey == Guid.Empty)
            {
                if (WebOperationContext.Current != null)
                {
                    WebOperationContext.Current.OutgoingResponse.StatusCode        = HttpStatusCode.Forbidden;
                    WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
                }
                return(-1);
            }
            int profileId = CSessionControl.GetUserIdFromSession(sessionKey);

            if (profileId < 0)
            {
                if (WebOperationContext.Current != null)
                {
                    WebOperationContext.Current.OutgoingResponse.StatusCode        = HttpStatusCode.Forbidden;
                    WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
                }
                return(-1);
            }
            return(profileId);
        }
示例#3
0
        public Guid Login(string username, string password)
        {
            Guid sessionId = CSessionControl.OpenSession(username, password);

            if (sessionId == Guid.Empty)
            {
                if (WebOperationContext.Current != null)
                {
                    WebOperationContext.Current.OutgoingResponse.StatusCode        = HttpStatusCode.Forbidden;
                    WebOperationContext.Current.OutgoingResponse.StatusDescription = "Wrong username or password";
                }
            }
            return(sessionId);
        }
示例#4
0
        public SProfileData GetProfile(int profileId)
        {
            Guid sessionKey = _GetSession();

            if (CSessionControl.GetUserIdFromSession(sessionKey) == profileId || _CheckRight(EUserRights.ViewOtherProfiles))
            {
                bool isReadonly = (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles) &&
                                   CSessionControl.GetUserIdFromSession(sessionKey) != profileId);


                return(CVocaluxeServer.DoTask(CVocaluxeServer.GetProfileData, profileId, isReadonly));
            }
            return(new SProfileData());
        }
示例#5
0
        public void SendProfile(SProfileData profile)
        {
            Guid sessionKey = _GetSession();

            if (profile.ProfileId != -1) //-1 is the id for a new profile
            {
                if (CSessionControl.GetUserIdFromSession(sessionKey) != profile.ProfileId &&
                    !(_CheckRight(EUserRights.EditAllProfiles)))
                {
                    return;
                }
            }

            CVocaluxeServer.DoTask(CVocaluxeServer.SendProfileData, profile);
        }
示例#6
0
        private static bool _CheckRightWithNoErrorMessage(EUserRights requestedRight)
        {
            Guid sessionKey = _GetSession();

            if (sessionKey == Guid.Empty)
            {
                return(false);
            }

            if (!CSessionControl.RequestRight(sessionKey, requestedRight))
            {
                return(false);
            }

            return(true);
        }
示例#7
0
        private static Guid _GetSession()
        {
            Guid   sessionKey    = Guid.Empty;
            string sessionHeader =
                ((HttpRequestMessageProperty)OperationContext.Current.IncomingMessageProperties["httpRequest"]).Headers["session"];

            if (string.IsNullOrEmpty(sessionHeader))
            {
                return(sessionKey);
            }
            try
            {
                sessionKey = Guid.Parse(sessionHeader);
            }
            catch (Exception)
            { }
            CSessionControl.ResetSessionTimeout(sessionKey);
            return(sessionKey);
        }
示例#8
0
        public void Logout()
        {
            Guid sessionKey = _GetSession();

            CSessionControl.InvalidateSessions(sessionKey);
        }