Exemplo n.º 1
0
        public Session(IDictionary<string, string> parameters, byte[] postData)
        {
            this._request = new FastCgi.Request (parameters, postData);

            if (!this._request.CookieJar.Exist ("sorentosessionid"))
            {
                this._id = Guid.NewGuid ();
                FastCgi.Cookie cookie = new FastCgi.Cookie();
                cookie.Name = "sorentosessionid";
                cookie.Value = this._id.ToString ();
                cookie.Path = "/";
                this._request.CookieJar.Add (cookie);
            }
            else
            {
                bool expired = false;

                try
                {
                    Session session = Session.Load (new Guid (this._request.CookieJar.Get ("sorentosessionid").Value));

                    this._id = session.Id;
                    this._createtimestamp = session._createtimestamp;
                    this._user = session._user;

                    if ((Date.DateTimeToTimestamp (DateTime.Now) - session._updatetimestamp) > Services.Config.Get<int> (Enums.ConfigKey.core_sessiontimeout) || session._remoteaddress != this._request.Environment.RemoteAddress)
                    {
                        expired = true;
                    }
                }
                catch (Exception exception)
                {
                    // LOG: LogDebug.ExceptionUnknown
                    Services.Logging.LogDebug (string.Format (Strings.LogDebug.ExceptionUnknown, "SORENTOLIB.SESSION", exception.Message));

                    expired = true;
                }

                if (expired)
                {
                    Services.Logging.LogDebug (string.Format (Strings.LogDebug.SessionTimeout, this._request.CookieJar.Get ("sorentosessionid").Value));

                    this._id = Guid.NewGuid ();
                    this._createtimestamp = Date.CurrentDateTimeToTimestamp ();
                    this._user = null;
                    this._request.CookieJar.Get ("sorentosessionid").Value = this._id.ToString ();
                }
            }

            if (this._user != null)
            {
                if (this._user.Status == Enums.UserStatus.Disabled)
                {
                    this._user = null;
                }
            }

            this._remoteaddress = this._request.Environment.RemoteAddress;

            // Fill accepted languages.
            this._languages = new List<string> ();
            foreach (string language in this._request.Environment.HttpAcceptLanguage.Split (";".ToCharArray ())[0].ToString ().Split (",".ToCharArray ()))
            {
                this._languages.Add (language);
            }

            this._timeout = Services.Config.Get<int> (Enums.ConfigKey.core_sessiontimeout);
            this._page = new Page (this._request.Environment.HttpHost);
            this._error = new Error ();

            this.Save ();
        }
Exemplo n.º 2
0
        public bool SignOut()
        {
            if (this._user != null)
            {
                string username = this._user.Username;

                try
                {
                    this._user = null;
                    this.Save ();
                    ServiceStatsUpdate ();
                    Services.Events.Invoke.SessionLogout (this);

                    // LOG: LogDebug.SessionUserSignOut
                    Services.Logging.LogDebug (string.Format (Strings.LogDebug.SessionUserSignOut, username));
                }
                catch (Exception exception)
                {
                    // LOG: LogDebug.ExceptionUnknown
                    Services.Logging.LogDebug (string.Format (Strings.LogDebug.ExceptionUnknown, "SORENTOLIB.SESSION", exception.Message));

                    // LOG: LogError.SessionSignOut
                    Services.Logging.LogError (string.Format (Strings.LogError.SessionSignOut, username));
                }
            }

            return true;
        }
Exemplo n.º 3
0
        public bool SignIn(string Username, string Password)
        {
            bool result = false;

            try
            {
                this._user = User.Load (Username);

                string password = string.Empty;
                switch (Services.Config.Get<string> (Enums.ConfigKey.core_authenticationtype))
                {
                    case "rsa":
                    {
            //						Console.WriteLine ("RSA DECODE");
                        password = SorentoLib.Tools.StringHelper.ASCIIBytesToString (SorentoLib.Services.Crypto.Decrypt (SorentoLib.Tools.StringHelper.HexStringToBytes (Password)));
                        break;
                    }

                    default:
                    {
                        password = SNDK.Crypto.SHAHash (SHAHashAlgorithm.SHA1, Password + Password);
                        break;
                    }
                }

                if (this._user.Authenticate (password))
                {
                    this.Save ();

                    result = true;
                    ServiceStatsUpdate ();
                    SorentoLib.Services.Events.Invoke.SessionLoginSuccess (this);
                }
                else
                {
                    this._user = null;
                    SorentoLib.Services.Events.Invoke.SessionLoginFailed (this);
                }
            }
            catch (Exception exception)
            {
                // LOG: LogDebug.ExceptionUnknown
                Services.Logging.LogDebug (string.Format (Strings.LogDebug.ExceptionUnknown, "SORENTOLIB.SESSION", exception.Message));

                // LOG: LogError.SessionSignIn
                Services.Logging.LogError (string.Format (Strings.LogError.SessionSignIn, Username));
            }

            return result;
        }
Exemplo n.º 4
0
        private static User Load(Guid id, string username)
        {
            User result = new User ();

            try
            {
                Hashtable item;

                if (id != Guid.Empty)
                {
                    item = (Hashtable)SNDK.Convert.FromXmlDocument (SNDK.Convert.XmlNodeToXmlDocument (Services.Datastore.Get<XmlDocument> (DatastoreAisle, id.ToString ()).SelectSingleNode ("(//sorentolib.user)[1]")));
                }
                else
                {
                    item = (Hashtable)SNDK.Convert.FromXmlDocument (SNDK.Convert.XmlNodeToXmlDocument (Services.Datastore.Get<XmlDocument> (DatastoreAisle, new Services.Datastore.MetaSearch ("username", Enums.DatastoreMetaSearchComparisonOperator.Equal, username)).SelectSingleNode ("(//sorentolib.user)[1]")));
                }

                result._id = new Guid ((string)item["id"]);

                if (item.ContainsKey ("createtimestamp"))
                {
                    result._createtimestamp = int.Parse ((string)item["createtimestamp"]);
                }

                if (item.ContainsKey ("updatetimestamp"))
                {
                    result._updatetimestamp = int.Parse ((string)item["updatetimestamp"]);
                }

                if (item.ContainsKey ("usergroupids"))
                {
                    result._usergroupsasstring = (string)item["usergroupids"];
                }

                if (item.ContainsKey ("username"))
                {
                    result._username = (string)item["username"];
                }

                if (item.ContainsKey ("password"))
                {
                    result._password = (string)item["password"];
                }

                if (item.ContainsKey ("email"))
                {
                    result._email = (string)item["email"];
                }

                if (item.ContainsKey ("realname"))
                {
                    result._realname = (string)item["realname"];
                }

                if (item.ContainsKey ("status"))
                {
                    result._status = SNDK.Convert.StringToEnum<SorentoLib.Enums.UserStatus> ((string)item["status"]);
                }

                if (item.ContainsKey ("scope"))
                {
                    result._scope = (string)item["scope"];
                }
            }
            catch (Exception exception)
            {
                // LOG: LogDebug.ExceptionUnknown
                Services.Logging.LogDebug (string.Format (Strings.LogDebug.ExceptionUnknown, "SORENTOLIB.USER", exception.Message));

                Console.WriteLine (exception);

                if (id != Guid.Empty)
                {
                    // EXCEPTION: Exception.UserLoadGuid
                    throw new Exception (string.Format (Strings.Exception.UserLoadGuid, id));
                }
                else
                {
                    // EXCEPTION: Exception.UserLoadUsername
                    throw new Exception (string.Format (Strings.Exception.UserLoadUsername, username));
                }
            }

            return result;
        }
Exemplo n.º 5
0
        public static User FromXmlDocument(XmlDocument xmlDocument)
        {
            Hashtable item;
            User result;

            try
            {
                item = (Hashtable)SNDK.Convert.FromXmlDocument (SNDK.Convert.XmlNodeToXmlDocument (xmlDocument.SelectSingleNode ("(//sorentolib.user)[1]")));
            }
            catch
            {
                item = (Hashtable)SNDK.Convert.FromXmlDocument (xmlDocument);
            }

            if (item.ContainsKey ("id"))
            {
                try
                {
                    result = Load (new Guid ((string)item["id"]));
                }
                catch
                {
                    result = new User ();
                    result._id = new Guid ((string)item["id"]);
                    result._username = (string)item["name"];
                    result._email = (string)item["email"];
                }
            }
            else
            {
                throw new Exception (Strings.Exception.UserFromXMLDocument);
            }

            if (item.ContainsKey ("createtimestamp"))
            {
                result._createtimestamp = int.Parse ((string)item["createtimestamp"]);
            }

            if (item.ContainsKey ("updatetimestamp"))
            {
                result._updatetimestamp = int.Parse ((string)item["updatetimestamp"]);
            }

            if (item.ContainsKey ("usergroups"))
            {
                result._usergroups.Clear ();

                foreach (XmlDocument usergroup in (List<XmlDocument>)item["usergroups"])
                {
                    result._usergroups.Add (Usergroup.FromXmlDocument (usergroup));
                }
            }

            if (item.ContainsKey ("username"))
            {
                result.Username = (string)item["username"];
            }

            if (item.ContainsKey ("email"))
            {
                result.Email = (string)item["email"];
            }

            if (item.ContainsKey ("realname"))
            {
                result._realname = (string)item["realname"];
            }

            if (item.ContainsKey ("status"))
            {
                result._status = SNDK.Convert.StringToEnum<SorentoLib.Enums.UserStatus> ((string)item["status"]);
            }

            if (item.ContainsKey ("scope"))
            {
                result._scope = (string)item["scope"];
            }

            return result;
        }
Exemplo n.º 6
0
        public void Save()
        {
            try
            {
                this._updatetimestamp = SNDK.Date.CurrentDateTimeToTimestamp ();

                if (this._userid == Guid.Empty)
                {
                    if (this._email != string.Empty)
                    {
                        SorentoLib.User user = new SorentoLib.User (this._email);
                        user.Email = this._email;
                        user.Realname = this._name;

                        if (this.Status == Didius.Enums.CustomerStatus.Enabled)
                        {
                            user.Status = SorentoLib.Enums.UserStatus.Enabled;
                        }
                        else
                        {
                            user.Status = SorentoLib.Enums.UserStatus.Disabled;
                        }

                        user.Save ();
                        this._userid = user.Id;
                    }
                }
                else
                {
                    if (this._email != string.Empty)
                    {
                        SorentoLib.User user = SorentoLib.User.Load (this._userid);
                        user.Username = this._email;
                        user.Email = this._email;
                        user.Realname = this._name;
                        user.Save ();
                    }
                    else
                    {
                        try
                        {
                            this._newsemail = false;
                            SorentoLib.User.Delete (this._userid);
                            this._userid = Guid.Empty;
                        }
                        catch {}
                    }
                }

                Hashtable item = new Hashtable ();

                item.Add ("id", this._id);
                item.Add ("createtimestamp", this._createtimestamp);
                item.Add ("updatetimestamp", this._updatetimestamp);

                item.Add ("no", this._no);

                item.Add ("groupids", this._groupsasstring);

                item.Add ("name", this._name);
                item.Add ("address1", this._address1);
                item.Add ("address2", this._address2);
                item.Add ("postcode", this._postcode);
                item.Add ("city", this._city);
                item.Add ("country", this._country);

                item.Add ("att", this._att);

                item.Add ("phone", this._phone);
                item.Add ("mobile", this._mobile);
                item.Add ("email", this._email);

            //				item.Add ("newsemail", this._newsemail);
                item.Add ("newssms", this._newssms);

                item.Add ("vat", this._vat);
                item.Add ("vatno", this._vatno);

                item.Add ("bankname", this._bankname);
                item.Add ("bankregistrationno", this._bankregistrationno);
                item.Add ("bankaccountno", this._bankaccountno);

                item.Add ("notes", this._notes);

                item.Add ("status", this._status);

                item.Add ("userid", this._userid);

                SorentoLib.Services.Datastore.Meta meta = new SorentoLib.Services.Datastore.Meta ();
                meta.Add ("customergroupids", this._groupsasstring);
                meta.Add ("userid", this._userid);

                SorentoLib.Services.Datastore.Set (DatastoreAisle, this._id.ToString (), SNDK.Convert.ToXmlDocument (item, this.GetType ().FullName.ToLower ()), meta);
            }
            catch (Exception exception)
            {
                Console.WriteLine (exception);

                // LOG: LogDebug.ExceptionUnknown
                SorentoLib.Services.Logging.LogDebug (string.Format (SorentoLib.Strings.LogDebug.ExceptionUnknown, "DIDIUS.CUSTOMER", exception.Message));

                // EXCEPTION: Exception.PageSave
                throw new Exception (string.Format (Strings.Exception.CustomerSave, this._id.ToString ()));
            }
        }