Welcome Guest, Not a member yet? Register   Sign In
Authorization Required
#1

[eluser]Unknown[/eluser]
Hi there.
Just succeeded to set up and started using DX_Auth.

I can log in as admin,user or some of registered users.

I gonna create pages that the authorization Required.(like my-page as any SNS)
so i have to check users are unter the authorization or not.
if they go these pages directly and not logged in, let them redirect to index.php/auth/login.

but i don't know how to do it.
now I can see all pages without the authorization.

any help appreciated.
#2

[eluser]Ben Edmunds[/eluser]
Not exactly sure about dx auth but most auth libraries have is_admin() and is_logged_in() type functions that you can check against and redirect the user if needed.
#3

[eluser]Trae R.[/eluser]
Here is an example from the DX_Auth documentation:
Code:
function hello()  
     {  
         // Check if user is logged in or not  
         if ($this->dx_auth->is_logged_in())  
         {  
             echo 'Hello world';  
         }  
         else  
         {  
             echo 'Not logged in';  
         }  
     }

Notice the conditional to see if the user is logged in or not.
You would add this to the controller method for the page you want to protect, and then add your redirect in place of the "echo 'Not logged in';" code. Make sure you have loaded the CodeIgniter url helper first to use the redirect() function.

In your case it would be something like this:
Code:
function hello()  
     {  
         // Check if user is logged in or not  
         if ($this->dx_auth->is_logged_in())  
         {  
             // Do Stuff
             // Load View of Protected Page  
         }  
         else  
         {  
             // User Not Logged In So Redirect to Login
             redirect('/index.php/auth/login');  
         }  
     }

More Information...
DX Auth Docs Here
CodeIgniter URL Helper (for redirect()) Here
#4

[eluser]Unknown[/eluser]
thanks two guys!

i gonna try them!

i appreciate your help!




Theme © iAndrew 2016 - Forum software by © MyBB