Welcome Guest, Not a member yet? Register   Sign In
Zendamf Authentication
#1

[eluser]Unknown[/eluser]
Hi,

I posted this on stack overflow and have not had much of a response so I thought I would try it here:


I am trying to get zendamf working with my codeigniter installation. I want to ensure that the user has logged on before allowing them to make any requests to any of the services. I have the following piece of code in my construct for the Testservice.php file.

Code:
function __construct()
    {
        parent::__construct();



            if(isset($this->session->userdata['user_id']))
            {
                log_message('error','not logged in');
                return 'Not Logged in';
                exit;
            }
            else
            {
                log_message('error','logged in');
            }
        }
And this for my test function

Code:
public function getMessage()
{
        return 'getmessage';
    }

When i make a call to the service I get the string 'getmessage' returned irrespective of being logged in or not. I can see the log messages been written for the login check but it I want it to send me the text specifed in the return for each of the conditions.

Any ideas

Thanks in advance

JaChNo
#2

[eluser]ranjudsokomora[/eluser]
JaChNo,
I believe you are getting that because your if statement returns false.

Trying changing it to
Code:
IF ($this->session->userdata['user_id']!==FALSE) {
}
#3

[eluser]Unknown[/eluser]
well spotted it seems you have found my deliberate mistake. here is the correct code. i still get the issue.
Code:
if(isset($this->session->userdata['user_id']))
            {

                log_message('error','logged in');
                return'logged in';
                exit;
            }
            else
            {
                log_message('error','not logged in');
                return 'Not Logged in';
                exit;
            }


it seems that once it hits the exit it carries on to the function? but i thought that exit should then make it stop running anything else.
#4

[eluser]ranjudsokomora[/eluser]
JaChNo,
The reason this is not exiting the script is because you have return statements. The return will exit the function, not the script. Try this.

Code:
IF ($this->session->userdata['user_id']===FALSE) {
    log_message('error','logged in');
    // return 'logged in'; #Removed because this will exit the function
    exit;
}
ELSE {
    log_message('error','not logged in');
    // return 'Not Logged in'; #Removed because this will exit the function
    exit;

}




Theme © iAndrew 2016 - Forum software by © MyBB