Require a user to login when they view a page created in a custom plugin

Hi

How do I require a user to login when they view a page?

I am looking for something simillar to  $sender->permission(array(some.permission))

Is there a method like $sender->somethingLikeRequireALogin() ?

Thanks

Comments

  • I know I can use the code below but there might be a built-in functionality in the framework that I am not aware

    $session = Gdn::session();

    if($session->IsValid()){

    // do something

    }

    else{

    // do something

    }

    thanks

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    If you look at the roles in the dashboard, you can see that guests do not have the permission to sign in. Hence $sender->permission('Garden.SignIn.Allow'); is what you are looking for


    rloyola
  • charrondevcharrondev Application Developer (PHP, JS) Montreal Vanilla Staff

    Something like this would do the trick if you actually want to redirect.

    if (!\Gdn::session()->isValid()) {
        redirectTo('/entry/signin?Target='.urlencode($request->pathAndQuery()));
        exit();
    }
    

    That's similar to what we do with the private communities feature:

    rloyola
  • Vanilla forums community is very helpful, Thanks!

Sign In or Register to comment.