Jump to content
  • 0

Why Use Api To User->Login Return This False


Question

Posted

$response = $api->get or $response = $api->post   all try.

Internal error: Failed to retrieve the default valuestdClass Object ( [error] => stdClass Object ( [message] => An unexpected error occured. [response] => Internal error: Failed to retrieve the default value ) )
<?php
session_start();
require_once "api/blesta_api.php";

$user = "wechat";
$key = "79aae**************cff42c66";
$url = "http://a.zy62.com/api/";
  
$api = new BlestaApi($url, $user, $key);
 
$data = array(
    'Session' =>session_id(),
    'vars' => array(
        'username' => "test",
        'password' => "test",
        'remember_me' => "true",
        'ip_address' => "120.202.21.195"
    )
);

$response = $api->get("Users", "login", $data);
//$response = $api->get("users", "get", array('user_id' => 1));
print_r($response->response());
print_r($response->errors());
//print_r($api->lastRequest());
?>

7 answers to this question

Recommended Posts

  • 0
Posted

What are you trying to do?

I believe the issue is that you are not passing a valid Session object. If you read the docs the login function takes two arguments, a Session Object and an array of user attributes.

The session object is defined here: http://source-docs.blesta.com/class-Session.html which is not the same as PHP's session class you are currently using (does not appear Blesta Session module implments PHP's SessionHandlerInterface). You might want to use the auth function if you want to verify if a user exists.

-Adam

  • 0
Posted
  On 7/29/2015 at 6:40 AM, Adam said:

What are you trying to do?

I believe the issue is that you are not passing a valid Session object. If you read the docs the login function takes two arguments, a Session Object and an array of user attributes.

The session object is defined here: http://source-docs.blesta.com/class-Session.html which is not the same as PHP's session class you are currently using (does not appear Blesta Session module implments PHP's SessionHandlerInterface). You might want to use the auth function if you want to verify if a user exists.

-Adam

 

 

Then can i use API to get session?

  • 0
Posted
  On 7/29/2015 at 8:08 AM, ty0716 said:

Then can i use API to get session?

What are you trying to do? ... For what purpose are you calling the login module for Blesta?

-Adam

  • 0
Posted
  On 7/29/2015 at 2:59 PM, Adam said:

What are you trying to do? ... For what purpose are you calling the login module for Blesta?

-Adam

 

Yes, i have anther site, and  i want to user login this site,then i can know this user's input whether correct.If true return client_id.

  • 0
Posted
  On 7/30/2015 at 6:34 AM, ty0716 said:

Yes, i have anther site, and  i want to user login this site,then i can know this user's input whether correct.If true return client_id.

You have two solutions (not in any particular order):

One solution is you can make two separate calls. First make a call to the function auth from the user model. If the function returns true, then you make another call to get the client id via the function getByUsername. getByUsername will return an object for that user, which would include the client id (among other properties that you might need).

Second solution is to pass in the correct Session Object to the login function you have above. You might want to include miniPHP's session object and pass that in. You could also create a class that has the same public methods as miniPHP's session class, but do nothing / return null (that might work).

A complete list of the functions and parameters for users can be found here: http://source-docs.blesta.com/class-Users.html More information on miniPHP's session class can be found here: http://source-docs.blesta.com/class-Session.html

-Adam

  • 0
Posted
  On 7/30/2015 at 6:52 AM, Adam said:

You have two solutions (not in any particular order):

One solution is you can make two separate calls. First make a call to the function auth from the user model. If the function returns true, then you make another call to get the client id via the function getByUsername. getByUsername will return an object for that user, which would include the client id (among other properties that you might need).

Second solution is to pass in the correct Session Object to the login function you have above. You might want to include miniPHP's session object and pass that in. You could also create a class that has the same public methods as miniPHP's session class, but do nothing / return null (that might work).

A complete list of the functions and parameters for users can be found here: http://source-docs.blesta.com/class-Users.html More information on miniPHP's session class can be found here: http://source-docs.blesta.com/class-Session.html

-Adam

 

Now i use first,ths!

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...