Welcome Guest, Not a member yet? Register   Sign In
Merge userauth and blog tutorial?
#1

[eluser]Dave Nuttall[/eluser]
I have an instance of userauth mini-app on WAMP with CI 1.6.

I can login, create users, etc.

I followed the basic CI tutorial/video for the blog and have that working also.

I now want to require that a valid login exist and that the user is in my "bloggers" group.

According to the way I understand the docs, I should add something to the blog controller's function Blog(), but so far I've failed to get the blog to refuse due to not being logged in.

My Blog function is as follows:
Code:
function Blog()
            {
                  parent::Controller();
                If (!$this->userauth->check('', TRUE)) redirect(user/auth_error);
                // $this->load->scaffolding("entries");
                $this->load->helper('url');
                $this->load->helper('form');

            }

Any help via posting or PM would be greatly appreciated!
Thanks.
Dave Nuttall
#2

[eluser]tomcode[/eluser]
Hi Dave,

Stumbled over Your post accidently. Please use http://ellislab.com/forums/viewthread/45880/P390/ for Your next post.

You need to create a role in ua_config:
Code:
// this is an example of defining a role of "bloggers"
$config['ua_role_bloggers_allow']    = '@bloggers @admin';
$config['ua_role_bloggers_deny']     = '';

Then in Your constructor (to set the role for all methods):
Code:
function Blog()
{
    $this->authorize->roleCheck('bloggers', $this->uri->uri_string());
}

or to restrict just one method:
Code:
function my_method()
{
    $this->authorize->set_allow('@bloggers');
    if (!$this->userauth->check('', TRUE))
    {
        echo 'no';
        // redirect('user/auth_error');
    }
    else echo 'yes';
}
#3

[eluser]Dave Nuttall[/eluser]
The restricted method doesn't seem to acknowledge the ua_config defined role.

For example, I set my ua_config bloggers role to be @bloggers @admin and then used the restriction suggestion on the comments_insert method.

It disallowed "admin" until I made $this->authorize->set_allow('@bloggers @admin');

Is that the expected outcome or perhaps I still have something messed up?

I really like where this is going for me!

Thanks.
Dave
#4

[eluser]tomcode[/eluser]
Frankly, I get always confused with these role / group definitions. I have already the plan to use different names for the roles and groups to see how this works out. I am suspecting that there is a twist anywhere in the code, or maybe I just don't understand what's going on. Sorry to not be able to tell You more for the monment.
#5

[eluser]Dave Nuttall[/eluser]
No problem.

To my way of thinking, it may be OK just the way the code sits. I intend to continue experimenting because a friend wants me to temporarily "unretire" while I help him build a small, closed site. I've experimented with FreakAuth-light and could see using it, although I think in the end we will use "userauth".

Let me know if you want a snapshot of the blog thingy so you can add that as example after someone follows the standard video tutorial.

Dave
#6

[eluser]tomcode[/eluser]
Well, if it works...

snapshot : Right now not, in two, three weeks, yes. But, post in the .userauth thread, I'm subscribed now (!), otherwise I'm not too often on the forum.




Theme © iAndrew 2016 - Forum software by © MyBB