Adding authentication to multi-page discos

2 views
Skip to first unread message

Steve

unread,
Dec 10, 2010, 1:30:58 PM12/10/10
to Reason Discussion
How can I add authentication to multi-page discos? I have a group
created in the admin interface that I'd like to use using the
reason_unique_name_exists('some_group) call.

Would this process be the same to add authentication to any custom
module?

Cheers and happy holidays,
Steve

Nathan White

unread,
Dec 10, 2010, 8:48:10 PM12/10/10
to reason-d...@googlegroups.com
Hi Steve - to authenticate against a Reason group you can use the function reason_user_is_in_group in function_libraries/user_functions.php.

Do something like this:

$username = reason_require_authentication(); // this will force login
$group = id_of('unique_name_of_reason_group');
$has_access = (reason_user_is_in_group($username, $group));

Prior to Reason 4 beta 8 you can use the group helper to do the same thing like this:

$username = reason_require_authentication(); // this will force login
$group = id_of('unique_name_of_reason_group');
$gh = new group_helper();
$gh->set_group_by_id($group);
$has_access = $gh->has_authorization($username);

The above should work fine pretty much anywhere. Hope this helps.

Nate


--
You received this message because you are subscribed to the Google Groups "Reason Discussion" group.
To post to this group, send email to reason-d...@googlegroups.com.
To unsubscribe from this group, send email to reason-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/reason-discussion?hl=en.


Steve

unread,
Dec 14, 2010, 3:28:52 PM12/14/10
to Reason Discussion
Thanks, Nate. Follow up question.

Where can I put this code to allow the friendlier landing (i.e. the
end-user can see the page, but the form has access control). I've
tried putting it in the run() and init() methods in the disco
controller as well as in the pre_show_form() and constructor of the
first disco page.

Thanks,
Steve
> > reason-discuss...@googlegroups.com<reason-discussion%2Bunsubscr­i...@googlegroups.com>
> > .

Mark Heiman

unread,
Dec 14, 2010, 3:37:21 PM12/14/10
to reason-d...@googlegroups.com
The best place to put your authentication is probably in the module that's instantiating the disco controller -- just put in some logic so that if they're not authenticated, it displays a message, and if they are, it runs the controller. For most applications, you shouldn't have to extend the controller itself.

Mark

> To unsubscribe from this group, send email to reason-discuss...@googlegroups.com.

Matt Ryan

unread,
Dec 14, 2010, 3:42:48 PM12/14/10
to reason-d...@googlegroups.com
The key thing is to not use reason_require_authentication() if you
want the page to, ahem, not require authentication.

Use reason_check_authentication() if you want your code to have a "not
logged in" mode where it does something other than simply bounce the
user to a login form. This function will return false if the user is
not logged in, or a username if they are.

Matt

Reply all
Reply to author
Forward
0 new messages