Esempio n. 1
0
    /// <summary>
    /// Add new user id field will be ignored
    /// </summary>
    private static void AddNewUser(string name, string pass, int admin, string desc, string uOptions, string aOptions)
    {
        try
        {
            db_config_users dcu = new db_config_users();
            dcu.Open(); // open connection

            // user with name or pass empty
            if (name == string.Empty || pass == string.Empty) { Generic.JavaScriptInjector("NewUserError", "alert('name or pass are empty');"); return; }

            Users user = new Users
            {
                Name = name,
                Pass = pass,
                AdMIn = admin,
                Description = desc,
                UserOptions = uOptions,
                AdMInOptions = aOptions
            };

            dcu.AddUser(user);

            dcu.Close(); // close connection

            Generic.JavaScriptInjector("alert('New user added'); window.location.reload();");
        }
        catch (Exception ex)
        {
            Generic.JavaScriptInjector("alert('" + ex.Message + "');");
        }
    }
Esempio n. 2
0
        /// <summary>
        /// Check if page is from users
        /// </summary>
        /// <returns></returns>
        private bool IsPagePrivate()
        {
            db_config_users users = new db_config_users();
            users.Open();

            return users.IsPageFromUsers(_pageId);
        }
Esempio n. 3
0
    public string AddPageToUser(string userId, string pageId, string ctrl)
    {
        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        if (ctrl != crlHash) return string.Empty;

        db_config_users dcu = null;

        try
        {
            // first validation to guarantee that user is greater than zero
            int auxUserId = Convert.ToInt32(userId);
            if (auxUserId < 0) return "User ID is less then zero";

            // first validation to guarantee that page is greater than zero
            int auxPageId = Convert.ToInt32(pageId);
            if (auxPageId < 0) return "Page ID is less then zero";

            dcu = new db_config_users(auxUserId);
            dcu.Open();

            if (dcu.AllUsers.Count != 1) return "User not available";

            dcu.AddPageToUser(auxPageId);
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            if (dcu != null) dcu.Close();
        }

        return "Operation Done";
    }
Esempio n. 4
0
    public string ListAllUserPages(string userId, string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        //if (ctrl != crlHash) return js.Serialize("");

        db_config_page dcp = null;

        try
        {
            // first validation to guarantee that user is greater than zero
            int auxUserId = Convert.ToInt32(userId);
            if (auxUserId < 0) return js.Serialize("");

            dcp = new db_config_page();
            dcp.Open();

            db_config_users dcu = new db_config_users(dcp.Db, auxUserId);
            dcu.Open();

            // list user pages
            List<int> userPagesId = (from up in dcu.GetPages() select up.ID).ToList();

            if (userPagesId.Count > 0)
                dcp.SelectAuthenticatedObjectsFromDb(userPagesId); // list public pages and pages that user can have
            else
                dcp.SelectPublicObjectsFromDb();

            // --------------------------------
            // list pages that user dont have
            List<JsonUserPages> userPages = (from ap in dcp.AllPages
                                            select new JsonUserPages {Id = ap.ID, Title = ap.Title, Name = ap.Name}).ToList();

            return js.Serialize(userPages);
        }
        catch (Exception ex)
        {
            loging.Error("FrontOffice User Webservice", "List All User Pages ", ex.Message, _logRecord);
        }
        finally
        {
            if (dcp != null) dcp.Close();
        }

        return js.Serialize("");
    }
Esempio n. 5
0
    public string GetUserFavorites(string userId, string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        //if (ctrl != crlHash) return js.Serialize("");

        db_config_users dcu = null;
        db_config_page dcp = null;

        try
        {
            // first validation to guarantee that user is greater than zero
            int auxUserId = Convert.ToInt32(userId);
            if (auxUserId < 0) return js.Serialize("");

            dcu = new db_config_users(auxUserId);
            dcu.Open();

            dcp = new db_config_page();
            dcp.Open();

            object userOptions = dcu.Get(auxUserId).UserOptions;

            if (userOptions == null) return js.Serialize("");

            OptionItems oi = new OptionItems((string)userOptions);

            List<Dictionary<string, string>> favoriteList = new List<Dictionary<string, string>>();

            foreach (string favoritePage in oi.GetList("favorites"))
            {
                try
                {
                    string title = dcp.Get(favoritePage).Title;

                    favoriteList.Add(new Dictionary<string, string>()
                    {
                        {"Name", favoritePage},
                        {"Title", title}
                    });
                }
                catch {}
            }

            return js.Serialize(favoriteList);
        }
        catch (Exception ex)
        {
            loging.Error("FrontOffice User Webservice", "Get Favorites ", ex.Message, _logRecord);
        }
        finally
        {
            if (dcu != null) dcu.Close();

            try { if(dcp != null) dcp.Close(); } catch {} // needed to open a new connection (forgot to implement a page method that accepts new  )
        }

        return js.Serialize("");
    }
Esempio n. 6
0
    public string GetUserDefaultPage(string userId, string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        //if (ctrl != crlHash) return js.Serialize("");

        db_config_users dcu = null; // user
        db_config_page dcp = null;  // page

        try
        {
            // first validation to guarantee that user is greater than zero
            int auxUserId = Convert.ToInt32(userId);
            if (auxUserId < 0) return js.Serialize("");

            dcu = new db_config_users(auxUserId);
            dcu.Open();

            object userOptions = dcu.Get(auxUserId).UserOptions;

            // if user does not exist leaves
            if (userOptions == null) return string.Empty;

            OptionItems oi = new OptionItems((string)userOptions);

            string pageName = oi.GetSingle("default_frontoffice_page");

            // if no default page leave
            if (pageName == string.Empty) return string.Empty;

            dcp = new db_config_page(pageName);
            dcp.Open();

            string pageTitle = dcp.Get(pageName).Title;

            Dictionary<string, string> defPage = new Dictionary<string, string>() {{"Name", pageName}, {"Title", pageTitle}};

            return js.Serialize(defPage);
        }
        catch (Exception ex)
        {
            loging.Error("FrontOffice User Webservice", "Get Default Page ", ex.Message, _logRecord);
        }
        finally
        {
            if (dcu != null) dcu.Close();

            try { if(dcp != null) dcp.Close(); } catch { }
        }

        return string.Empty;
    }
Esempio n. 7
0
    public string AddUserFavoritePage(string userId, string pageName, string ctrl)
    {
        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        //if (ctrl != crlHash) return js.Serialize("");

        db_config_users dcu = null;

        try
        {
            // first validation to guarantee that user is greater than zero
            int auxUserId = Convert.ToInt32(userId);
            if (auxUserId < 0) return string.Empty;

            dcu = new db_config_users(auxUserId);
            dcu.Open();

            Users u = dcu.Get(auxUserId);

            if (u == null) return string.Empty; // if user does not exists will leave width no return message

            OptionItems oi = new OptionItems(u.UserOptions);

            List<string> favoriteList = oi.GetList("favorites");

            if (favoriteList.IndexOf(pageName) < 0)
            {
                favoriteList.Add(pageName);
                oi.UpdateOptions("favorites", favoriteList);
                u.UserOptions = oi.GetOptionsString();
                dcu.Commit();

                return "page added to favorites";
            }
            else
                return "page already added to favorite.";

        }
        catch (Exception ex)
        {
            loging.Error("FrontOffice User Webservice", "Add User Favorite Page", ex.Message, _logRecord);
        }
        finally
        {
            if (dcu != null) dcu.Close();
        }

        return "failed to add page";
    }
Esempio n. 8
0
    public string CloneUser(string userId, string newUserName, string ctrl)
    {
        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        if (ctrl != crlHash) return string.Empty;

        db_config_users dcu = null;

        try
        {
            // first validation to garanty that user is graiter then zero
            int auxUserId = Convert.ToInt32(userId);
            if (auxUserId < 0) return "User ID is less then zero";

            dcu = new db_config_users(auxUserId);
            dcu.Open();

            if (dcu.AllUsers.Count == 0) return "User not available";

            dcu.Clone(newUserName);

            return "User Cloned";
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        finally
        {
            if (dcu != null) dcu.Close();
        }
    }
Esempio n. 9
0
    public string SetUserDefaultFrontOfficePage(string userId, string pageName, string ctrl)
    {
        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        //if (ctrl != crlHash) return js.Serialize("");

        db_config_users dcu = null;

        try
        {
            // first validation to guarantee that user is greater than zero
            int auxUserId = Convert.ToInt32(userId);
            if (auxUserId < 0) return string.Empty;

            dcu = new db_config_users(auxUserId);
            dcu.Open();

            Users u = dcu.Get(auxUserId);

            if (u == null) return string.Empty; // if user does not exists it will leave with no return messsage

            OptionItems oi = new OptionItems(u.UserOptions);
            oi.UpdateOptions("default_frontoffice_page", new List<string> { pageName });

            u.UserOptions = oi.GetOptionsString();

            dcu.Commit();

            return pageName != ""
                                ? "Page " + pageName + " is set as default frontoffice page"
                                : "Default frontoffice page is clean";
        }
        catch (Exception ex)
        {
            loging.Error("FrontOffice User Webservice", "Add User Favorite Page", ex.Message, _logRecord);
        }
        finally
        {
            if (dcu != null) dcu.Close();
        }

        return "failed to set page";
    }
Esempio n. 10
0
    public string ChangeUserPassword(string userId, string newPass, string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        //if (ctrl != crlHash) return js.Serialize("");

        db_config_users dcu = null;

        try
        {
            // first validation to guarantee that user is greater than zero
            int auxUserId = Convert.ToInt32(userId);
            if (auxUserId < 0) return js.Serialize("");

            dcu = new db_config_users(auxUserId);
            dcu.Open();

            Users u = dcu.Get(auxUserId);

            if (u == null) return string.Empty; // if user does not exists it will leave with no return messsage

            u.Pass = newPass;
            dcu.Commit();

            return "password changed";
        }
        catch (Exception ex)
        {
            loging.Error("FrontOffice User Webservice", "User Change Password", ex.Message, _logRecord);
        }
        finally
        {
            if (dcu != null) dcu.Close();
        }

        return "password not changed";
    }
Esempio n. 11
0
    public string ListUsers(string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        if (ctrl != crlHash) return js.Serialize("");

        db_config_users dcu = null;

        try
        {
            dcu = new db_config_users();
            dcu.Open();

            List<JsonUser> users = (from u in dcu.AllUsers
                                    select new JsonUser
                                    {
                                        Id = u.ID,
                                        Name = u.Name,
                                        Pass = u.Pass,
                                        Admin = u.AdMIn == 1 ? 1 : 0,
                                        Description = u.Description,
                                        AdminOptions = u.AdMInOptions,
                                        UserOptions = u.UserOptions,
                                    }).ToList();

            return js.Serialize(users);
        }
        catch (Exception ex)
        {
            loging.Error("BackOffice User Webservice", "Error", ex.Message, _logRecord);
        }
        finally
        {
            if (dcu != null) dcu.Close();
        }

        return js.Serialize("");
    }
Esempio n. 12
0
    public string ListUserPages(string userId, string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        if (ctrl != crlHash) return js.Serialize("");

        // first validation to garanty that user is graiter then zero
        int auxUserId = Convert.ToInt32(userId);
        if (auxUserId < 0) return js.Serialize("");

        db_config_users dcu = null;

        try
        {
            dcu = new db_config_users(auxUserId);
            dcu.Open();

            List<JsonUserPages> pages = (from p in dcu.GetPages()
                                         select new JsonUserPages { Id = p.ID, Title = p.Title }).ToList();

            return js.Serialize(pages);
        }
        catch (Exception ex)
        {
            loging.Error("BackOffice User Webservice", "User Pages", ex.Message, _logRecord);
        }
        finally
        {
            if (dcu != null) dcu.Close();
        }

        return js.Serialize("");
    }
Esempio n. 13
0
    public string ListAvailablePagesToUser(string userId, string ctrl)
    {
        JavaScriptSerializer js = new JavaScriptSerializer();

        string crlHash = Generic.GetHash(Generic.GetWebConfigValue("WebServiceKey"));

        if (ctrl != crlHash) return js.Serialize("");

        db_config_page dcp = null;

        try
        {
            // first validation to guarantee that user is greater than zero
            int auxUserId = Convert.ToInt32(userId);
            if (auxUserId < 0) return js.Serialize("");

            dcp = new db_config_page();
            dcp.Open();

            db_config_users dcu = new db_config_users(dcp.Db, auxUserId);
            dcu.Open();

            // list user pages
            List<int> userPagesId = (from up in dcu.GetPages() select up.ID).ToList();

            // --------------------------------
            // list pages that user dont have
            List<JsonUserPages> noAvailableUserPages = userPagesId.Count == 0 ? (from ap in dcp.AllPages
                                                                                 select new JsonUserPages { Id = ap.ID, Title = ap.Title, Name = ap.Name }).ToList()
                                                                            : (from nup in dcp.AllPages
                                                                                where !userPagesId.Contains(nup.ID)
                                                                                select new JsonUserPages { Id = nup.ID, Title = nup.Title, Name = nup.Name }).ToList();

            return js.Serialize(noAvailableUserPages);
        }
        catch (Exception ex)
        {
            loging.Error("BackOffice User Webservice", "List All Pages ", ex.Message, _logRecord);
        }
        finally
        {
            if (dcp != null) dcp.Close();
        }

        return js.Serialize("");
    }
Esempio n. 14
0
    /************************ Configurations ************************/
    /// <summary>
    /// updating existing user data
    /// </summary>
    private static void SaveUser(string uId, string name, string pass, int admin, string desc, string uOptions, string aOptions)
    {
        try
        {
            int id = Convert.ToInt32(uId);

            db_config_users dcu = new db_config_users(id);
            dcu.Open(); // open connection

            Users user = dcu.Get(id);

            if (user.ID != id) return; // if id is diferent probabaly because user pressed save with no user selected

            user.Name = name;
            user.Pass = pass;
            user.AdMIn = admin;
            user.Description = desc;
            user.UserOptions = uOptions;
            user.AdMInOptions = aOptions;

            dcu.Commit();

            dcu.Close(); // close connection

            Generic.JavaScriptInjector("alert('User Saved'); window.location.reload();");
        }
        catch (Exception ex)
        {
            Generic.JavaScriptInjector("alert('" + ex.Message + "');");
        }
    }
Esempio n. 15
0
        /* Button login click event */
        void LoginButton_Click(object sender, EventArgs e)
        {
            System.Web.UI.Page page = (System.Web.UI.Page)HttpContext.Current.Handler;

            string user = ((TextBox)page.FindControl("tbUser")).Text;
            string pass = ((TextBox)page.FindControl("tbPass")).Text;

            DbConfig.db_config_users dcu = new DbConfig.db_config_users(user);
            dcu.Open();

            DbConfig.UserLoginData uld = dcu.IsUserAuthenticated(pass);

            if (uld != null)
            {
                DbConfig.db_config_sessions.SetUserAuthentication(uld);

                Generic.PageRefresh();
            }
            else
                Generic.JavaScriptInjector("loginFail", "alert('login failed')");
        }