The following warnings occurred: | ||||||||||||
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.2.25 (Linux)
|
Private Pages (Twig) - Printable Version +- UserSpice (https://userspice.com/forums) +-- Forum: Miscellaneous (https://userspice.com/forums/forumdisplay.php?fid=28) +--- Forum: Documentation (https://userspice.com/forums/forumdisplay.php?fid=30) +--- Thread: Private Pages (Twig) (/showthread.php?tid=814) |
Private Pages (Twig) - whatwilldo - 10-28-2017 I'm sorry if this has been asked before, but I've been poking around the web for the last two days and can't seem to find quite what I'm looking for. (Also, I'm new here, so I think I'm allotted some leeway?) I'm use Slim 3/Twig, but I don't think either of those is the problem (could be wrong). I'm able to load up every page just fine, having set UserSpice aside to load without Twig rendering (basically, got my templates in one directory and UserSpice user pages in another). I can get all of the appropriate pages to show up in the Admin panel (having edited the z_us_root.php array), and I can add or remove permissions/private viewing just fine to any of the pages. The problem is that I can't seem to figure out exactly how to require the init.php file or the securePage function in my controller so that it will properly check for login status/status and redirect as appropriate. For example, when a user tries to access example.com/privatepage without being logged in. I do apologize if this is a silly question. I feel like the answer is so simple and I'm overthinking it. Thank you in advance. Private Pages (Twig) - Brandin - 10-28-2017 Hi whatwilldo, How're you? Welcome! Call the init using a require once and your securePage. Try this: <?php require_once '../users/init.php';?> <?php if (!securePage($_SERVER['PHP_SELF'])){die();} ?> The ../ gets you out of your current directory and to the init file...there are other ways you can do this but that is the best way I have find currently...let me know what else you need. Also note: I know nothing about Slim and Twig so what I'm saying very well could be wrong! B. Private Pages (Twig) - whatwilldo - 10-28-2017 Thanks for the quick reply, Brandin! If I put that directly on the page (privatepage.php might be the page in my example), and I type in the path to access it directly, all of the UserSpice code works as it's intended. But I have something like this set-up on my index page: Code: require_once 'users/init.php'; <pre> Code: $app->get('/privatepage', function ($request, $response, $args) { Because it will render privatepage.php using Twig, I can't put the PHP code you provided in directly (or at least I don't know HOW to with the Twig syntax, which might also be the problem). So, I was trying to execute it prior to the return, but I can't seem to figure out how to get that to work (or if it's possible) so that: If user logged in, return ...->render, etc. but If not logged in, redirect to log in. Private Pages (Twig) - Brandin - 10-28-2017 Code for logged in after calling init: if($user->isLoggedIn()) { //whatever } if(!$user->isLoggedIn()) { //whatever not logged in } Let me know if that helps! B. Private Pages (Twig) - whatwilldo - 10-28-2017 Brandin, you're amazing. Thank you! The answer was that simple. For anyone else that might be running into the same problem as I, I just threw all that code after the get->... function (my mistake was having it all split up in the first place). That also meant moving my user->... statements. Thanks for being so responsive. Sometimes we just need to hear our thoughts out loud to see what exactly is going on. Private Pages (Twig) - Brandin - 10-28-2017 Let us know if you need anything else Glad to hear it is working. |