Exemplo n.º 1
0
        /// <summary>
        /// Handles the load event of the base page.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BasePage_Load(object sender, EventArgs e)
        {
            User user = null;

            if (this.IdUser.HasValue)
            {
                user = this.Core.Users.GetSingle(IdUser.Value);
            }

            if (Request.UrlReferrer == null || Request.UrlReferrer.ToString() != Request.Url.ToString())
            {
                if (this.IdUser.HasValue)
                {
                    ApplicationUtilities.UsageLogger logger = new ApplicationUtilities.UsageLogger(
                        this.Core.ClientName,
                        user
                        );

                    logger.Log(ApplicationUtilities.UsageLogVariable.AccessedPage, Request.Url.PathAndQuery.Split('?')[0]);
                    //to call usagelogdetails only once
                    logger.UsageLogDetails(
                        Request.Url.PathAndQuery.Split('?')[0]
                        );
                }
            }

            if (this.IdUser.HasValue && user.Validated == false)
            {
                UserValidation userValidation = new UserValidation(Path.Combine(
                                                                       Request.PhysicalApplicationPath,
                                                                       "App_Data",
                                                                       "UserValidation",
                                                                       this.Core.ClientName + ".xml"
                                                                       ));

                if (userValidation.Exists)
                {
                    if (Request.Url.ToString().Contains("Pages/Default.aspx") == false)
                    {
                        Response.Redirect("/Pages/Default.aspx");
                        return;
                    }

                    Page.Controls[0].Controls.Add(userValidation.Render());
                }
            }

            // Check if the page requires an authenticated user.
            if (this.CheckUser)
            {
                // Check if the current session has an authenticated user.
                if (this.IdUser == null)
                {
                    // Redirect to the login page.
                    Response.Redirect("/Pages/Login.aspx?RedirectUrl=" + HttpUtility.UrlEncode(Request.Url.ToString()));

                    return;
                }
            }

            if (!HasPagePermission(Request.Url.LocalPath))
            {
                Response.Redirect("/Default.aspx");
            }

            if (Request.Params["ContentWidth"] != null)
            {
                int contentWidth;

                if (int.TryParse(Request.Params["ContentWidth"].ToString(), out contentWidth))
                {
                    this.ContentWidth = contentWidth;
                }
            }

            if (this.IdUser != null)
            {
                Page.ClientScript.RegisterStartupScript(
                    this.GetType(),
                    "SetCurrentUsername",
                    "var currentUserName='******';",
                    true
                    );
            }
        }
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            SetPageDimensions();

            User user = null;

            if ((ConfigurationManager.AppSettings["Overrides"] != null) && (this.ClientName.ToLower() == ConfigurationManager.AppSettings["Overrides"].ToString()))
            {
                try
                {
                    XmlDocument document = new XmlDocument();
                    document.Load(System.IO.Path.Combine(
                                      System.Web.HttpContext.Current.Request.PhysicalApplicationPath,
                                      "App_Data",
                                      "Overrides",
                                      this.ClientName + ".xml"
                                      ));

                    ApplicationUtilities.Classes.Client client = Global.ClientManager.GetSingle(Request.Url.Host.Split('.')[0].Trim());

                    string Db = null;

                    foreach (XmlNode item in document.DocumentElement.SelectNodes("User"))
                    {
                        if ((txtUsername.Text.ToLower() == item.Attributes["Name"].Value.ToLower()))
                        {
                            Db = item.Attributes["Db"].Value.ToLower();
                        }
                    }

                    if (Db != null)
                    {
                        string connectionString = string.Format(
                            ConfigurationManager.AppSettings["ConnectionString"],
                            Db
                            );

                        Global.Core = new DatabaseCore.Core(
                            ConfigurationManager.AppSettings["DatabaseProvider"],
                            connectionString,
                            ConfigurationManager.AppSettings["DatabaseProviderUserManagement"],
                            connectionString,
                            client.SynchServers
                            );

                        // Create a new database core for the session.
                        Global.Core = new DatabaseCore.Core(
                            ConfigurationManager.AppSettings["DatabaseProvider"],
                            connectionString,
                            ConfigurationManager.AppSettings["DatabaseProviderUserManagement"],
                            connectionString,
                            client.SynchServers
                            );

                        // Initialize the session's permission core.
                        Global.PermissionCore = new PermissionCore.PermissionCore(
                            Request.PhysicalApplicationPath,
                            "LinkOnline",
                            this.ClientName
                            );

                        // Initialize the session's language manager.
                        Global.LanguageManager = new LanguageManager(
                            this.ClientName,
                            Request.PhysicalApplicationPath
                            );

                        // Set the database core's file storage path.
                        Global.Core.FileStorageRoot = string.Format(
                            ConfigurationManager.AppSettings["FileStorageRoot"],
                            this.ClientName
                            );

                        /*if (!Directory.Exists(Global.Core.FileStorageRoot))
                         *  Directory.CreateDirectory(Global.Core.FileStorageRoot);
                         *
                         * Global.Core.LogDirectory = ConfigurationManager.AppSettings["DatabaseChangeLogDirectory"];*/

                        Global.Core.ClientName       = this.ClientName;
                        Global.Core.CaseDataVersion  = Global.ClientManager.GetSingle(this.ClientName).CaseDataVersion;
                        Global.Core.CaseDataLocation = Global.ClientManager.GetSingle(this.ClientName).CaseDataLocation;
                    }
                }
                catch (Exception)
                {
                }
            }


            // Check if the entered login data is valid.
            user = Global.Core.Users.Valid(
                txtUsername.Text,
                txtPassword.Text
                );
            if (user != null)
            {
                Global.User = user;

                if (!Global.AllSessions.ContainsKey(this.ClientName))
                {
                    Global.AllSessions.Add(this.ClientName, new Dictionary <Guid, System.Web.SessionState.HttpSessionState>());
                }

                if (Global.AllSessions[this.ClientName].ContainsKey(user.Id))
                {
                    if (Global.AllSessions[this.ClientName][user.Id] != null)
                    {
                        Global.AllSessions[this.ClientName][user.Id].RemoveAll();
                    }

                    try
                    {
                        Global.AllSessions[this.ClientName][user.Id]["KickedOut"] = true;
                        Global.AllSessions[this.ClientName].Remove(user.Id);
                    }
                    catch { }
                }

                if (!Global.IdUser.HasValue)
                {
                    Response.Redirect(Request.Url.ToString());
                    return;
                }

                if (Global.AllSessions[this.ClientName] != null)
                {
                    Global.AllSessions[this.ClientName].Add(user.Id, HttpContext.Current.Session);

                    /*The below GridLines is used for PasswordAssistance Module*/

                    Session["UserDetails"] = Global.User.Name + "," + Global.User.FirstName + "," + Global.User.LastName + "," + Global.User.Mail;

                    ApplicationUtilities.UsageLogger logger = new ApplicationUtilities.UsageLogger(
                        this.Core.ClientName,
                        this.Core.Users.GetSingle(IdUser.Value)
                        );

                    logger.Log(
                        ApplicationUtilities.UsageLogVariable.Login,
                        DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss tt")
                        );
                    logger.Log(
                        ApplicationUtilities.UsageLogVariable.Browser,
                        (Request.UserAgent.IndexOf("Edge") > -1) ? "Microsoft Edge" : Request.Browser.Browser
                        );
                    logger.Log(
                        ApplicationUtilities.UsageLogVariable.EmailId,
                        Global.User.Mail
                        );

                    //to call initlog only once
                    logger.InitLog(
                        (Request.UserAgent.IndexOf("Edge") > -1) ? "Microsoft Edge" : Request.Browser.Browser
                        );

                    Global.UserDefaults = new UserDefaults(Path.Combine(
                                                               HttpContext.Current.Request.PhysicalApplicationPath,
                                                               "Fileadmin",
                                                               "UserDefaults",
                                                               this.ClientName,
                                                               Global.IdUser.Value + ".xml"
                                                               ));

                    if (Request.Params["RedirectUrl"] == null)
                    {
                        Response.Redirect("/Pages/Default.aspx");
                    }
                    else
                    {
                        Response.Redirect(HttpUtility.UrlDecode(Request.Params["RedirectUrl"]));
                    }
                }
            }
            else
            {
                Response.Redirect("/Pages/Login.aspx?msg=3");
            }
        }