HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

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

  • Options

    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

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    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

  • Options
    charrondevcharrondev Developer Lead (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:

  • Options

    Vanilla forums community is very helpful, Thanks!

Sign In or Register to comment.