Jump to content
alan

isLoggedin() and isSuperuser() doing nothing (as if commented out) in a PW3 site - did I miss something?

Recommended Posts

Sorry folks if this is obvious to most and I missed something in the docs or here in the forum, but, I have cheerfully used code such as:

if($user->isLoggedin()) {
  echo " loggedIn";
} else {
  echo " notLoggedIn";
}

in PW 2.x sites.

Now on a v3 site I am finding even the most basic test to see if the viewer is logged in or `isSuperuser()` is not giving an error but simply doing nothing - not evaluating.

For example, the top of a typical template reads:

<?php namespace ProcessWire;

			if($user->isLoggedin()) {
				echo " loggedIn";
			} else {
				echo " notLoggedIn";
			}

I have `debug` turned on.

Is there something obvious I have missed, perhaps a step required for v3 that's not required for v2 to allow access to $user data?

Thanks for any pointers.

Share this post


Link to post
Share on other sites

Nothing different from PW2 to 3 really. This code is even in the default install themes and working normally.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks @Soma for confirming that.

I'm confused in that case as I have a site where this test is failing.

I'll go back and re-re-check to see if I am missing something else.., thanks again for the sanity check 👍

Share this post


Link to post
Share on other sites

Thanks @Mustafa-Online - I was pretty certain it was good, now the worse bit, working out what else I have here that's causing this ;)

  • Like 1

Share this post


Link to post
Share on other sites

Check $user with var_dump if it has the expected user. My guess is that you overwrite $user somewhere. Where do you have this code?

  • Like 2

Share this post


Link to post
Share on other sites

Thanks @tpr, I wondered if I had too and so previously had done a `print_r($user)` and got a dump that looked convincingly like an array of user info, so I assumed I had not overwritten it. But I now see I get the same dumped output whether logged in or not... So that seems to suggest it's not null, is an array but looks like maybe it's an array of stuff that is not the $user object!

Thanks for the pointer, I will go back and look harder at that now and report back here, cheers!

Share this post


Link to post
Share on other sites

:-[ Oh nos... I was convinced I had ruled out any chance it could be session data, browser cache, etc, for example opening the same URL in a browser I don't use for dev. But I think it was somehow polluted session from using the CodeKit url `http://myMacName.local:5757/` rather than the LAMP url that I tell CodeKit is where my site is running in one tab, and the LAMP (non-CodeKit) url in another tab.

tl;dr: $user may not behave as expected when previewing on a CodeKit URL, or if you do and another tab is open at the non-CodeKit URL.

Takeaway, check this first and/or if I insist on keeping both Admin and end-user view open, at different URLs, use two different browsers.

Share this post


Link to post
Share on other sites
2 hours ago, alan said:

I wondered if I had too and so previously had done a `print_r($user)` and got a dump that looked convincingly like an array of user info

 

Sorry if it seems like I am promoting Tracy here, but if you were using her, you could just do this in the Console panel and you'd instantly see if $user is an object and what the name of that user is. 

59ea34e926131_ScreenShot2017-10-20at10_38_31AM.png.e392b8063aa383e3962d26fdfffa0253.png

  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites

@adrian not at all! I love being reminded of Tracy.

Off to go look it up again. I am embarrassed to say I looked briefly when you released Tracy and I think I saw some dependancy of mine that meant a slight question and I never went further.

I am very impressed to see that you can do per your screenshot, clearly I am a total newb' in some respects, when it comes to debugging, I will turn on, er, `debug` and that's about as far as I get, then it's adding `echo` here and there to see stuff.

tl;dr I am eXCITEd to go look at your module!

Thanks! 👍

  • Like 1

Share this post


Link to post
Share on other sites
7 minutes ago, adrian said:

Sorry if it seems like I am promoting Tracy here

Developing a website or whatever without Tracy is for masochists! Sorry I can't resist! :lol:

  • Like 5

Share this post


Link to post
Share on other sites

o_O
s t u n n e d
to see what I have been missing by not using Tracy.

THANK you again @adrian for the post and for Tracy! ^_^

  • Like 2

Share this post


Link to post
Share on other sites
51 minutes ago, adrian said:

Sorry if it seems like I am promoting Tracy here, but if you were using her

Never considered Tracy as a she :). But yeah, its a girl's name isn't it.

I'm gonna call Tracy a `she` from now on.

  • Like 5
  • Haha 1

Share this post


Link to post
Share on other sites

Been meaning to do it for awhile, this reminded me. Gonna go and install her now.

  • Like 1

Share this post


Link to post
Share on other sites

One of those times that even though I'm pretty pleased with my progress, a quick scroll in there tells me I've only just got over a few small rocks at the bottom of the massive PHP mountain.

59ea4d861f15e_ScreenShot2017-10-20at20_19_51.thumb.png.71d180eba0f693917d168e9b9638c908.png

Do you leave this on when a site goes live or uninstall it?

Share this post


Link to post
Share on other sites

Actually @alan - I should note that in some instances using the Console panel for this purpose may not achieve what you are looking for. If your template had overridden $user somewhere you might be better off doing bd($user) or bd($user->name) just before that isLoggedin() check so you know you are getting the value that is being used right there in your code.

You can do this in your code editor, or you can even do it in the Template Editor panel and use the "Test" button - that way no changes are even made to your template files, so no need to remove debug statements when you're done. Have a read here: https://processwire.com/blog/posts/introducing-tracy-debugger/#template-editor-panel

  • Like 1

Share this post


Link to post
Share on other sites

 

7 minutes ago, SamC said:

One of those times that even though I'm pretty pleased with my progress, a quick scroll in there tells me I've only just got over a few small rocks at the bottom of the massive PHP mountain.

Firstly, sorry about the number of settings in Tracy - that isn't a sign of your lack of PHP knowledge, but rather a sign of my indecisiveness :)

 

7 minutes ago, SamC said:

Do you leave this on when a site goes live or uninstall it?

Really this is up to you. I leave it running - it's not accessible to regular users anyway. In production mode it can send you emails when it logs errors. But if you want you can uncheck the "Enable Tracy" option so there is no load at all from it, although it's not noticeable in production mode anyway.

  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By SwimToWin
      I have a website that allows users to create their personal "website" (a page with sub-pages).
      Users shall be able to:
      Log in (frontend and/or admin), Edit "their" page(s) - I am using the "Page Edit Per User"-module (https://modules.processwire.com/modules/page-edit-per-user/) to grant access to the relevant pages Create child pages - possible? Users shall not be able to see other pages in the admin interface - "Admin Restrict Page Tree" may do the trick (https://modules.processwire.com/modules/admin-restrict-page-tree/)? Frontend editing shall be possible - I am considering "Fredi" (https://modules.processwire.com/modules/fredi/) for this. The challenge is that it takes a lot of modules and configuration.
      Is there a way to set this up that doesn't require a lot of configuration for each new user?
    • By Peter Knight
      I have a demo site which I moved to a new VPS for client testing
      We noticed that leaving a page open and then revisiting the site can result in a 25 second(ish) to load time and will then throw a 500 Error.
      The hosting guys had a look and confirmed that the server is fine but the issue could be related to authentication or sessions.
      We are running Page Protector and ProCache so I wondered if there were any known bugs here and any recommended actions.
      My actual PW log doesn't show anything but the server log has plenty of these
       
      2018-12-06 08:14:00 Error xxx.141.1x.101 500 POST /who-we-are/ HTTP/1.0     1.58 K Apache access 2018-12-06 08:14:45 Warning xxx.141.1x.131   mod_fcgid: read data timeout in 45 seconds, referer: http://demo.abc.not/who-we-are/       Apache error 2018-12-06 08:14:45 Error xxx.141.1x.131   End of script output before headers: index.php, referer: http://demo.abc.not/who-we-are/       Apache error 2018-12-06 09:03:18 Error xxx.141.1x.131   2614#0: *667 recv() failed (104: Connection reset by peer) while reading response header from upstream       nginx error Thanks
      P
    • By Marcel
      Hey all,
      I want to customize the mywebsite/processwire/profile page. It's almost all good but I want to get rid of the sections 'Admin Theme' and 'Language' so that the user can just set a new password. (see image)
      Do I have to modify the admin template or how can I do that? Because when I go tree>Admin>Profile there are no fields to add or remove.
      Or where can I find the php file?
      I would appreciate your help.

    • By ridgedale
      Reference: PW 3.0.111 and uikit3 based site using the Regular-Master profile.
      Despite my searches of the forum I'm somewhat confused about how to create new child pages on the frontend when a user clicks on a button on the parent page. I also have an equivalent button that is intended for uploading a .csv file to automatically create multiple new pages. This basically relates to a club (parent) and members (child) template configuration. Hopefully this explanation makes sense.
      A button should be able to launch the code needed to initiate the script required to create a new page using something like:
      <a href="/path/page.php">New +</a> <a href="/path/page.php">New ++</a> Does the code to create the new page or new pages need to be run from the template file for the child or the parent?
      A new individual member page will need to be editable manually at the point of page creation as well as subsequently, whereas multiple new pages will need to be editable after they have created and populated with data, again, as well as subsequently.
      I would very grateful for any advice or pointers as to how to achieve this.
       
    • By ridgedale
      Reference: PW 3.0.111 and uikit3 based site using the Regular-Master profile.
      I was wondering if there is a way to restrict user navigation to specific pages.
      Login (home.php - not to be displayed)
          |__  About (not to be displayed)
          |__  Clubs (not to be displayed)
          |            |__ Club (to be displayed)
          |                       |__  Club Members (to be displayed)
          |__ League (not to be displayed)
          |            |__Season (not to be displayed)
          |                       |__  Match (not to be displayed)
          |__  News (blog.php -  to be displayed)
          |
      etc, etc
      Based on the above the navigation needs to appear simply as:
      ---------------------------------------------------------------------------
                           Club    Club Members    News    
      ---------------------------------------------------------------------------
      Any thoughts appreciated.
×
×
  • Create New...