From ad6d3ed706a5f0e820f87b7b27c7b25c1d13d1df Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 17 Dec 2017 18:48:02 +0100 Subject: [PATCH] Added page for forbbiden access to signed out users. --- assets/css/pages/userPage/accessForbidden.css | 14 +++++++ assets/js/common/functionsSchema.js | 22 +++++++++++ assets/js/pages/userPage/accessForbidden.js | 38 ++++++++++++++++++ assets/js/pages/userPage/main.js | 37 ++++++++++++++++++ assets/js/user/userInfos.js | 19 +++++++++ corePage/config/dev.config.php | 39 +++++++++++-------- 6 files changed, 152 insertions(+), 17 deletions(-) create mode 100644 assets/css/pages/userPage/accessForbidden.css create mode 100644 assets/js/pages/userPage/accessForbidden.js diff --git a/assets/css/pages/userPage/accessForbidden.css b/assets/css/pages/userPage/accessForbidden.css new file mode 100644 index 00000000..5eec29b2 --- /dev/null +++ b/assets/css/pages/userPage/accessForbidden.css @@ -0,0 +1,14 @@ +/** + * Access To Page Forbidden stylesheet + * + * @author Pierre HUBERT + */ + +/** + * Callout special stylesheet + */ +.user_page_access_forbidden { + margin: auto; + margin-top: 30px; + max-width: 500px; +} \ No newline at end of file diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index e6982a7a..c2fdbcd6 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -390,6 +390,11 @@ var ComunicWeb = { */ getNames: function(usersID, afterNames){}, + /** + * Get advanced informations about a user + */ + getAdvancedInfos: function(userID, callback){}, + /** * Get the user ID specified by its folder name */ @@ -667,8 +672,25 @@ var ComunicWeb = { */ openUserPage: function(id, params, target){}, + /** + * Display a user page + */ + displayUserPage: function(infos, params, target){}, + }, + /** + * Page with access forbidden + */ + accessForbidden: { + + /** + * Display the page for user with forbidden access + */ + display: function(id, params, target){} + + } + }, /** diff --git a/assets/js/pages/userPage/accessForbidden.js b/assets/js/pages/userPage/accessForbidden.js new file mode 100644 index 00000000..8c1c277e --- /dev/null +++ b/assets/js/pages/userPage/accessForbidden.js @@ -0,0 +1,38 @@ +/** + * Display informations about pages we are not allowed to show + * + * Handles request + * + * @author Pierre HUBERT + */ + +ComunicWeb.pages.userPage.accessForbidden = { + + /** + * Display the page for user with forbidden access + * + * @param {Integer} userID The ID of the target user + * @param {Object} params Additional parametres + * @param {HTMLElement} target The target element on the screen + */ + display: function(id, params, target){ + + //Check if user is signed in or not + if(!signed_in()){ + + //Inform user that he must sign in to continue + elem = ComunicWeb.common.messages.createCalloutElem( + "Sign in required", + "Please sign in to get access to this page.", + "danger" + ); + + elem.className += " user_page_access_forbidden"; + + target.appendChild(elem); + + } + + }, + +} \ No newline at end of file diff --git a/assets/js/pages/userPage/main.js b/assets/js/pages/userPage/main.js index 577a4380..0056886f 100644 --- a/assets/js/pages/userPage/main.js +++ b/assets/js/pages/userPage/main.js @@ -83,7 +83,44 @@ ComunicWeb.pages.userPage.main = { //Log action log("Open user page : " + id); + //Fetch informations about the user + ComunicWeb.user.userInfos.getAdvancedInfos(id, function(response){ + + //Check for errors + if(response.error){ + + //Check if the page was not found + if(response.error.code == 404){ + ComunicWeb.common.error.pageNotFound(params, target); + } + + //Check if we are not allowed to get the informations + if(response.error.code == 401){ + //Display access forbidden page + ComunicWeb.pages.userPage.accessForbidden.display(id, params, target); + } + + } + else { + //Display user page + ComunicWeb.pages.userPage.main.displayUserPage(response, params, target); + } + + + }); }, + /** + * Display a user page + * + * @param {Object} infos Informations about the user to display + * @param {Object} params Parametres required to open the page + * @param {HTMLElement} target Target of the user page + */ + displayUserPage: function(infos, params, target){ + console.log("Display user page based on the informations we got"); + console.log(infos); + } + } \ No newline at end of file diff --git a/assets/js/user/userInfos.js b/assets/js/user/userInfos.js index 97735e7f..cdd6a33b 100644 --- a/assets/js/user/userInfos.js +++ b/assets/js/user/userInfos.js @@ -201,6 +201,25 @@ ComunicWeb.user.userInfos = { }); }, + /** + * Get advanced informations about a user + * + * @param {Integer} userID The ID of the user to fetch + * @param {Function} callback What to do once we got the information + */ + getAdvancedInfos: function(userID, callback){ + + //Prepare an API request + var apiURI = "user/getAdvancedUserInfos"; + var params = { + userID: userID + }; + + //Perform the request + ComunicWeb.common.api.makeAPIrequest(apiURI, params, true, callback); + + }, + /** * Get the user ID specified by its folder name * diff --git a/corePage/config/dev.config.php b/corePage/config/dev.config.php index 1a999551..fa49a18f 100644 --- a/corePage/config/dev.config.php +++ b/corePage/config/dev.config.php @@ -32,25 +32,29 @@ $config['CSSfiles'] = array( "%PATH_ASSETS%css/common/network/networkError.css", //Components stylesheets - //Menubar stylesheet - "%PATH_ASSETS%css/components/menuBar.css", - - //Searchform stylesheet - "%PATH_ASSETS%css/components/searchForm.css", - - //Friendbar stylesheet - "%PATH_ASSETS%css/components/friends/friendsBar.css", - - //Conversations stylesheet - "%PATH_ASSETS%css/components/conversations/manager.css", - "%PATH_ASSETS%css/components/conversations/windows.css", - "%PATH_ASSETS%css/components/conversations/list.css", - - //User selector stylesheet - "%PATH_ASSETS%css/components/userSelect/userSelect.css", + //Menubar stylesheet + "%PATH_ASSETS%css/components/menuBar.css", + + //Searchform stylesheet + "%PATH_ASSETS%css/components/searchForm.css", + + //Friendbar stylesheet + "%PATH_ASSETS%css/components/friends/friendsBar.css", + + //Conversations stylesheet + "%PATH_ASSETS%css/components/conversations/manager.css", + "%PATH_ASSETS%css/components/conversations/windows.css", + "%PATH_ASSETS%css/components/conversations/list.css", + + //User selector stylesheet + "%PATH_ASSETS%css/components/userSelect/userSelect.css", - //Emojies + //Emojies "%PATH_ASSETS%css/components/emoji/parser.css", + + //Pages stylesheets + //User Page + "%PATH_ASSETS%css/pages/userPage/accessForbidden.css", ); //3rd party JS files to include (at the end of the page) @@ -170,6 +174,7 @@ $config['JSfiles'] = array( //User page "%PATH_ASSETS%js/pages/userPage/main.js", + "%PATH_ASSETS%js/pages/userPage/accessForbidden.js", //Login page "%PATH_ASSETS%js/pages/login.js",