Jump to content
  • 0

Why Use Api To User->Login Return This False


ty0716

Question

$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());
?>
Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

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!

Link to comment
Share on other sites

  • 0

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

Link to comment
Share on other sites

  • 0

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?

Link to comment
Share on other sites

  • 0

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...