示例#1
0
        public LoginAuthentication LoginSaved()
        {
            try
            {
                XmlDocument xmlDocument = Utility.LoadXmlWithXmlDocument(_path + "LoginSaved.xml");

                if ((xmlDocument == null) || (!xmlDocument.HasChildNodes))
                {
                    return(null);
                }

                XmlNodeList nodeList = xmlDocument.GetElementsByTagName("DATA");

                //Test values:

                /*XmlNode node = nodeList[0];
                 * string Login =
                 *  Utility.Decript(node["LOGIN"].InnerText);
                 * MessageBox.Show("Login = "******"PASSWORD"].InnerText);
                 * MessageBox.Show("Password = "******"LASTDATE"].InnerText), new CultureInfo("pt-BR"));
                 * MessageBox.Show("LastDate = " + LastDate.ToString());
                 * DateTime LimitDate =
                 *  DateTime.Parse(
                 *      Utility.Decript(
                 *          node["LIMITDATE"].InnerText), new CultureInfo("pt-BR"));
                 * MessageBox.Show("LimitDate = " + LimitDate.ToString());
                 * bool Remember =
                 *  Utility.Decript(node["REMEMBER"].InnerText)
                 *      .ToLower() == "true"
                 *      ? true
                 *      : false;
                 * LoginAuthentication loginAuthentication = null;*/

                LoginAuthentication loginAuthentication = (from XmlNode node in nodeList
                                                           select new LoginAuthentication
                {
                    Login =
                        Utility.Decript(node["LOGIN"].InnerText),
                    Password =
                        Utility.Decript(node["PASSWORD"].InnerText),
                    LastDate = node["LASTDATE"].InnerText != ""?
                               DateTime.Parse(
                        Utility.Decript(
                            node["LASTDATE"].InnerText), new CultureInfo("pt-BR")):DateTime.Now,
                    LimitDate = node["LIMITDATE"].InnerText != ""?
                                DateTime.Parse(
                        Utility.Decript(
                            node["LIMITDATE"].InnerText), new CultureInfo("pt-BR")) : DateTime.Now.AddDays(2),
                    Remember =
                        Utility.Decript(node["REMEMBER"].InnerText)
                        .ToLower() == "true"
                                                                                  ? true
                                                                                  : false,
                }).FirstOrDefault();

                EStatusAuthentication eStatusAuthentication = VerifyDate(loginAuthentication.LastDate,
                                                                         loginAuthentication.LimitDate);

                if (eStatusAuthentication.Equals(EStatusAuthentication.Blocked))
                {
                    throw new Exception("Sistema bloqueado para acesso.");
                }

                if (eStatusAuthentication.Equals(EStatusAuthentication.Expired))
                {
                    return(null);
                }

                loginAuthentication.Features =
                    ListFeatures.Instance().GetFeatures(Utility.Cript(loginAuthentication.Login));

                return(loginAuthentication);
            }
            catch (Exception ex)
            {
                MessageBox.Show("LoginSaved()" + ex.Message);
            }
            return(null);
        }
示例#2
0
        public LoginAuthentication LoginOffline(string login, string password, bool remember)
        {
            //Test if guest.xml exists:
            if (login == "guest" && Utility.Decript(password) == "123456")
            {
                if (!File.Exists(_path + login + ".xml"))
                {
                    CreateDataPath(new LoginAuthentication()
                    {
                        CodeSession = "GUEST",
                        Login       = login,
                        Password    = password,
                        LastDate    = DateTime.Now,
                        LimitDate   = DateTime.Now.AddDays(5),
                        Remember    = false,
                        Offline     = true,
                        Features    = new List <Features>()
                        {
                            new Features()
                            {
                                Description = EFeatures.NEW_CHART, Permission = EPermission.Permitido
                            }, new Features()
                            {
                                Description = EFeatures.HISTORICDATA, Permission = EPermission.Restringido
                            }
                        },
                        UserProfile = new UserRegister()
                        {
                            UserName = "******"
                        }
                    }, login);
                }
            }

            LoginAuthentication loginAuthentication = null;

            XmlDocument xmlDocument = Utility.LoadXmlWithXmlDocument(_path + login + ".xml");

            XmlNodeList nodeList = xmlDocument.GetElementsByTagName("DATA");

            foreach (XmlNode node in nodeList.Cast <XmlNode>().Where(node => node["LOGIN"].InnerText.Equals(Utility.Cript(login)) &&
                                                                     node["PASSWORD"].InnerText.Equals(Utility.Cript(password))))
            {
                loginAuthentication = new LoginAuthentication
                {
                    Login       = Utility.Decript(node["LOGIN"].InnerText),
                    Password    = Utility.Decript(node["PASSWORD"].InnerText),
                    LastDate    = DateTime.Now,
                    LimitDate   = DateTime.Parse(Utility.Decript(node["LIMITDATE"].InnerText), new CultureInfo("pt-BR")),
                    Remember    = remember,
                    CodeSession = "",
                    Features    = new List <Features>(),
                    Offline     = true,
                    UserProfile = new UserRegister()
                    {
                        UserName = "******"
                    }
                };

                EStatusAuthentication eStatusAuthentication = VerifyDate(loginAuthentication.LastDate, loginAuthentication.LimitDate);

                if ((eStatusAuthentication.Equals(EStatusAuthentication.Expired)) || (eStatusAuthentication.Equals(EStatusAuthentication.Blocked)))
                {
                    throw new Exception("Período de login offline acabou, realize um login online para regularizar.");
                }

                XmlNodeList nodeFeatures = xmlDocument.GetElementsByTagName("FEATURE");

                loginAuthentication.Features = (from XmlNode feature in nodeFeatures
                                                select new Features
                {
                    Description = (EFeatures)StringValue.Parse(typeof(EFeatures), Utility.Decript(feature["DESCRIPTION"].InnerText)),
                    Permission = (EPermission)StringValue.Parse(typeof(EPermission), Utility.Decript(feature["PERMISSION"].InnerText)),
                }).ToList();

                node["REMEMBER"].InnerText = Utility.Cript(remember.ToString());

                xmlDocument.Save(_path + login + ".xml");
                xmlDocument.Save(_path + "LoginSaved.xml");

                break;
            }

            return(loginAuthentication);
        }