コード例 #1
0
        /// <summary>Verifies a transaction.</summary>
        /// <param name="userSessionID">The user session identifier.</param>
        /// <param name="url">The URL.</param>
        /// <param name="transactionKey">The transaction key.</param>
        /// <returns></returns>
        public XmlDeserializer VerifyTransaction(long userSessionID, string url, string transactionKey)
        {
            if (Session.SessionID <= 0)
            {
                throw new InvalidOperationException("No valid software session!");
            }

            if (userSessionID <= 0)
            {
                throw new ArgumentNullException(nameof(userSessionID));
            }

            if (string.IsNullOrEmpty(transactionKey))
            {
                throw new ArgumentNullException(nameof(transactionKey));
            }

            if (string.IsNullOrEmpty(url))
            {
                throw new ArgumentNullException(nameof(url));
            }

            string urlHash = Base64.UrlChars.Encode(Hash.FromString(Hash.Type.SHA256, url));

            Trace.TraceInformation("Session <white>{0}<default> TransactionKey <yellow>{1}<default> URL <cyan>{2}<default> UrlHash <cyan>{3}", Base64.UrlChars.Encode(userSessionID), transactionKey, url, urlHash);
            var request = XmlRequest.Prepare(Server, "VerifyTransaction", $"userSessionID={userSessionID}", $"urlHash={urlHash}", $"transactionKey={transactionKey}");

            request.Headers["Session"] = Session.SessionID.ToString();
            WebMessage message = request.Post();

            Trace.TraceInformation(message.ToString());
            return(request.Result);
        }
コード例 #2
0
ファイル: XAuth.cs プロジェクト: CaveSystems/cave-webserver
        /// <summary>Gets the user details.</summary>
        /// <returns></returns>
        public FullUserDetails GetUserDetails()
        {
            lock (this)
            {
                var request = XmlRequest.Prepare(Server, "GetUserDetails");
                request.Headers["Session"] = Session.ID.ToString();
                WebMessage message = request.Post();
                if (message.Error != WebError.None)
                {
                    throw new XAuthException(message, request);
                }

                XmlDeserializer des = request.Result;

                var result = new FullUserDetails
                {
                    User           = des.GetRow <User>("User"),
                    UserDetail     = des.GetRow <UserDetail>("UserDetail"),
                    Licenses       = des.GetTable <License>("Licenses"),
                    Addresses      = des.GetTable <Address>("Addresses"),
                    PhoneNumbers   = des.GetTable <PhoneNumber>("PhoneNumbers"),
                    EmailAddresses = des.GetTable <EmailAddress>("EmailAddresses"),
                    Groups         = des.GetTable <Group>("Groups"),
                    GroupMembers   = des.GetTable <GroupMember>("GroupMembers"),
                };
                return(result);
            }
        }
コード例 #3
0
        void CheckSession(object state)
        {
            try
            {
                var request = XmlRequest.Prepare(Server, "SoftwareCheckSession");
                request.Headers["Session"] = Session.SessionID.ToString();
                request.Credentials        = new NetworkCredential(AssemblyVersionInfo.Program.Product + "/" + AssemblyVersionInfo.Program.AssemblyVersion + "/" + AppDom.ProgramID, password);
                WebMessage message = request.Post();
                if (message.Error != WebError.None)
                {
                    throw new XAuthException(message, request);
                }

                message = LoadSessionResult(request);
                OnSessionUpdated(new EventArgs());
            }
            catch (WebServerException ex)
            {
                Exception = ex;
                switch (ex.Error)
                {
                case WebError.AuthenticationRequired:
                case WebError.SessionRequired:
                {
                    SoftwareSession session = Session;
                    session.Expiration = DateTime.UtcNow.AddSeconds(-1);
                    Session            = session;
                }
                break;
                }
                if (true.Equals(state))
                {
                    throw;
                }
            }
            catch (Exception ex)
            {
                Exception = ex;
                Trace.TraceError("CheckSession error!");
                if (true.Equals(state))
                {
                    throw;
                }
            }
            finally
            {
                if (Session.IsExpired)
                {
                    timer?.Dispose();
                    timer = null;
                    OnSessionUpdated(new EventArgs());
                }
            }
        }
コード例 #4
0
ファイル: XAuth.cs プロジェクト: CaveSystems/cave-webserver
        /// <summary>Requests a new password.</summary>
        /// <param name="email">The email.</param>
        /// <returns></returns>
        public WebMessage RequestNewPassword(string email)
        {
            lock (this)
            {
                var        request = XmlRequest.Prepare(Server, "RequestNewPassword", $"email={email}");
                WebMessage message = request.Post();
                if (message.Error != WebError.None)
                {
                    throw new XAuthException(message, request);
                }

                return(message);
            }
        }
コード例 #5
0
ファイル: XAuth.cs プロジェクト: CaveSystems/cave-webserver
        WebMessage LoadSessionResult(XmlRequest request)
        {
            WebMessage message = request.Result.GetRow <WebMessage>("Result");

            if (message.Error != WebError.None)
            {
                throw new XAuthException(message, request);
            }

            Trace.TraceError("{0}", message);
            User    = request.Result.GetRow <User>("User");
            Session = request.Result.GetRow <UserSession>("Session");
            return(message);
        }
コード例 #6
0
        WebMessage LoadSessionResult(XmlRequest request)
        {
            WebMessage message = request.Result.GetRow <WebMessage>("Result");

            if (message.Error != WebError.None)
            {
                throw new XAuthException(message, request);
            }

            Trace.TraceInformation("{0}", message);
            Software = request.Result.GetRow <Software>("Software");
            Session  = request.Result.GetRow <SoftwareSession>("SoftwareSession");
            return(message);
        }
コード例 #7
0
ファイル: XAuth.cs プロジェクト: CaveSystems/cave-webserver
        /// <summary>Performs a leave group command.</summary>
        /// <param name="groupID">The group identifier.</param>
        /// <returns></returns>
        public WebMessage GroupLeave(long groupID)
        {
            lock (this)
            {
                var request = XmlRequest.Prepare(Server, "GroupLeave", $"groupID={groupID}");
                request.Headers["Session"] = Session.ID.ToString();
                WebMessage message = request.Post();
                if (message.Error != WebError.None)
                {
                    throw new XAuthException(message, request);
                }

                return(message);
            }
        }
コード例 #8
0
ファイル: XAuth.cs プロジェクト: CaveSystems/cave-webserver
        /// <summary>Performs a create group command.</summary>
        /// <param name="groupName">Name of the group.</param>
        /// <returns></returns>
        public XmlDeserializer GroupCreate(string groupName)
        {
            lock (this)
            {
                var request = XmlRequest.Prepare(Server, "GroupCreate", $"groupName={groupName}");
                request.Headers["Session"] = Session.ID.ToString();
                WebMessage message = request.Post();
                if (message.Error != WebError.None)
                {
                    throw new XAuthException(message, request);
                }

                return(request.Result);
            }
        }
コード例 #9
0
ファイル: XAuth.cs プロジェクト: CaveSystems/cave-webserver
        /// <summary>Gets a transaction key.</summary>
        /// <param name="url">The URL.</param>
        /// <returns></returns>
        public TransactionKey GetTransactionKey(string url)
        {
            lock (this)
            {
                string hash    = Base64.UrlChars.Encode(Hash.FromString(Hash.Type.SHA256, url));
                var    request = XmlRequest.Prepare(Server, "GetTransactionKey", $"urlHash={hash}");
                request.Headers["Session"] = Session.ID.ToString();
                WebMessage message = request.Post();
                if (message.Error != WebError.None)
                {
                    throw new XAuthException(message, request);
                }

                return(request.Result.GetRow <TransactionKey>("TransactionKey"));
            }
        }
コード例 #10
0
ファイル: XAuth.cs プロジェクト: CaveSystems/cave-webserver
        /// <summary>Creates a new account.</summary>
        /// <param name="user">The user.</param>
        /// <param name="email">The email.</param>
        /// <param name="firstname">The firstname.</param>
        /// <param name="lastname">The lastname.</param>
        /// <param name="birthday">The birthday.</param>
        /// <param name="gender">The gender.</param>
        /// <returns></returns>
        public WebMessage CreateAccount(string user, string email, string firstname, string lastname, DateTime birthday, Gender gender)
        {
            lock (this)
            {
                var request = XmlRequest.Prepare(Server, "CreateAccount", $"user={user}",
                                                 $"email={email}", $"firstname={firstname}", $"lastname={lastname}", $"gender={gender}",
                                                 $"birthday={birthday.Date}");
                WebMessage message = request.Post();
                if (message.Error != WebError.None)
                {
                    throw new XAuthException(message, request);
                }

                return(message);
            }
        }
コード例 #11
0
ファイル: XAuth.cs プロジェクト: CaveSystems/cave-webserver
        /// <summary>Performs a session check. A successful check extends the session.</summary>
        public void CheckSession()
        {
            Trace.TraceInformation("Checking session {0}", Session);
            var request = XmlRequest.Prepare(Server, "CheckSession");

            request.Headers["Session"] = Session.ID.ToString();
            WebMessage message = request.Post();

            if (message.Error != WebError.None)
            {
                throw new XAuthException(message, request);
            }

            message = LoadSessionResult(request);
            OnSessionUpdated(new EventArgs());
        }
コード例 #12
0
ファイル: XAuth.cs プロジェクト: CaveSystems/cave-webserver
        /// <summary>Closes the current session.</summary>
        /// <returns></returns>
        public WebMessage CloseSession()
        {
            lock (this)
            {
                if (Session.IsValid())
                {
                    var        request = XmlRequest.Prepare(Server, "CloseSession");
                    WebMessage message = request.Post();
                    if (message.Error != WebError.None)
                    {
                        throw new XAuthException(message, request);
                    }

                    return(message);
                }
                return(WebMessage.Create("CloseSession", "Session was already expired!", error: WebError.None));
            }
        }
コード例 #13
0
ファイル: XAuth.cs プロジェクト: CaveSystems/cave-webserver
        /// <summary>Creates a new session.</summary>
        /// <param name="user">The user.</param>
        /// <param name="pass">The pass.</param>
        /// <returns></returns>
        public WebMessage CreateSession(string user, string pass)
        {
            lock (this)
            {
                var request = XmlRequest.Prepare(Server, "CreateSession");
                request.Credentials = new NetworkCredential(user, pass);
                WebMessage message = request.Post();
                if (message.Error != WebError.None)
                {
                    throw new XAuthException(message, request);
                }

                message = LoadSessionResult(request);
                timer?.Dispose();
                timer = new System.Threading.Timer(CheckSession, null, 1000 * 10, 1000 * 10);
                return(message);
            }
        }