<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

require("../../../wp-load.php");
require_once("utilities.php");

if (count($_POST) > 0) {

    if ( isValidRemoteHost($_SERVER["REMOTE_ADDR"]) ) {

        require_once("utilities.php");
        $blowfish = new Blowfish(array("key" => get_option("kconnect_currentkey")));

        $uid = $blowfish->decrypt(base64_decode($_POST["uid"]));
        $hash = $blowfish->decrypt(base64_decode($_POST["hash"]));

        if (is_numeric($uid)) {

            $user = get_userdata( $uid );
            $user->avatar = get_avatar( $uid );

            preg_match("/src='[^']*/", $user->avatar, $src);

            if (count($src) != 0) {

                 $src = substr(array_shift($src), 5,-1);
                 $user->avatar = $src;
            }

            $data = array(
                "satId" => get_option("kconnect_sid"),
                "id" => $user->ID,
                "login" => $user->user_login,
                "email" => $user->user_email ,
                "date" => $user->user_registered
            );

            $token = $data["login"].$data["email"].$data["date"];

            if (checkToken($token, $hash)) {

                echo "ok_".base64_encode($blowfish->encrypt(serialize($user)));

            } else {

                echo "nop!!";
            }
        }


    } else {

        echo "Not allowed remote IP";
    }
}
