Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter deepak.ghayal

    (@deepakghayal)

    I just simple edit below function with few lines of code and it works like charm.
    public function validate_auth_cookie() {

    global $json_api;

    if (!$json_api->query->cookie) {

    $json_api->error(“You must include a ‘cookie’ authentication cookie. Use the create_auth_cookie method.”);

    }

    $valid = wp_validate_auth_cookie($json_api->query->cookie, ‘logged_in’) ? true : false;

    $userid = wp_validate_auth_cookie($json_api->query->cookie, ‘logged_in’);

    // print_r($userid);
    // print_r(get_userdata( $userid ));
    $data = get_userdata( $userid );
    $username = $data->user_login;
    // print_r($username );
    // require(‘../wp-blog-header.php’);
    $user_login = $username;
    $user = get_userdatabylogin($user_login);
    // print_r($user);
    $user_id = $user->ID;
    $dsf=wp_set_current_user($user_id, $user_login);
    // print_r($dsf);
    $sdf=wp_set_auth_cookie($user_id);
    // print_r($sdf);
    $datas=do_action(‘wp_login’, $user_login);
    // print_r($datas);
    // exit;
    wp_redirect( get_site_url(), 301 ); //exit;
    // exit;

    if($userid) {
    $creds = array();
    // $creds[‘user_login’] = ‘add’;// $json_api->query->username;
    // $creds[‘user_password’] = ‘add’; // $json_api->query->password;
    $creds[‘remember’] = true;
    $user = wp_signon( $creds, false );
    if ( is_wp_error($user) )
    echo $user->get_error_message();

    wp_redirect( get_site_url(), 301 ); exit;
    }
    else

    {
    return array(“valid” => $valid);
    }
    }

    Thanks Ali Qureshi your plugin works great…

    Plugin Author Ali Qureshi

    (@parorrey)

    glad it worked for you. Thanks.

    Hi,

    Through this User API is it possible to validate the user who has logged in from some other sites database and when they come to wordpress (which has separate databse) it should show as logged in user. I dont want user to login again in wordpress to write the blogs. Please suggest.

    Plugin Author Ali Qureshi

    (@parorrey)

    It’s not designed for this task. It is basically REST API, authenticating user with the cookie value and using it for RESTful calls.

    You need SSO (single Sign on) solution. See these plugins >> https://www.ads-software.com/plugins/tags/single-sign-on

    hi
    Thanks For the code..!!
    but still one question..
    how to call login api??? i added above code in my project
    and whats the parameter to pass
    please give to demo

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Login to website’ is closed to new replies.