Exemplo n.º 1
0
     // Decoding the JSON
     $getContents = json_decode($input, true);
     // Getting the given client token
     $clientToken = !empty($getContents['clientToken']) ? $getContents['clientToken'] : null;
     // Getting the given access token
     $accessToken = !empty($getContents['accessToken']) ? $getContents['accessToken'] : null;
     // Sending a request to the database to get the user from the access token
     $req = Core\Queries::execute('SELECT * FROM openauth_users WHERE accessToken=:accessToken', ['accessToken' => $accessToken]);
     // If the user was found (the request response isn't empty)
     if (!empty($req)) {
         // If the given client token is the same as the one of the database
         if ($req->clientToken == $clientToken) {
             // Generating a new access token
             $newAccessToken = md5(uniqid(rand(), true));
             // Sending a request to the database to update the access token of the user
             Core\Queries::execute('UPDATE openauth_users SET accessToken=:accessToken WHERE clientToken=:clientToken', ['accessToken' => $newAccessToken, 'clientToken' => $clientToken]);
             // Creating an array of the new infos
             $jsonArray = array('accessToken' => $newAccessToken, 'clientToken' => $clientToken);
             // Printing it as a JSON
             echo json_encode($jsonArray);
         } else {
             // Printing the third error
             echo error(3);
         }
     } else {
         // Printing the fourth error
         echo error(4);
     }
 } else {
     // Printing the sixth error
     echo error(6);
Exemplo n.º 2
0
    // If no one is empty
    if (!empty($username) && !empty($password) && !empty($vpassword)) {
        // Sending a request to the database to get a user with the same name as the given name
        $req = Core\Queries::execute('SELECT * FROM openauth_users WHERE username=:username', ['username' => $username]);
        // If the request is null, or is empty (so the user doesn't already exist)
        if (is_null($req) || empty($req)) {
            // If the password and the validation password are the same
            if ($password == $vpassword) {
                // Generating a new GUID
                $guid = getGUID();
                // Generating a new UUID
                $uuid = md5(uniqid(rand(), true));
                // Hashing the given password
                $password = hash('sha256', $password);
                // Sending a request to the database to add the user
                Core\Queries::execute('INSERT INTO openauth_users (guid, uuid, username, password) VALUES (:guid, :uuid, :username, :password)', ['username' => $username, 'uuid' => $uuid, "password" => $password, 'guid' => $guid]);
                // Setting the 'You are now suscribed' message
                $notif = "Vous êtes bien inscrits !";
            } else {
                // Setting the 'Different passwords' message
                $notif = 'Les mots de passe sont different !';
            }
        } else {
            // Setting the 'User already exists' message
            $notif = 'Le pseudo est déjà utilise !';
        }
    } else {
        // Setting the 'One of the fields is missing' message
        $notif = 'Un ou plusieurs champs sont manquant !';
    }
}
Exemplo n.º 3
0
* along with OpenAuth.  If not, see <http://www.gnu.org/licenses/>.
*/
// If the request method is POST
if ($request['method'] == "POST") {
    // If the content-type is JSON
    if ($request['content-type'] == "application/json") {
        // Getting the input JSON
        $input = file_get_contents("php://input");
        // Decoding it
        $getContents = json_decode($input, true);
        // Getting the access token from it
        $accessToken = !empty($getContents['accessToken']) ? $getContents['accessToken'] : null;
        // If the given access token isn't null
        if (!is_null($accessToken)) {
            // Sending a request to the database to get the user from the given access token
            $req = Core\Queries::execute('SELECT * FROM openauth_users WHERE accessToken=:accessToken', ['accessToken' => $accessToken]);
            // If the request response is empty
            if (empty($req)) {
                // Printing the fourth error
                echo error(4);
            }
        } else {
            // Printing the fourth error
            echo error(4);
        }
    } else {
        // Printing the sixth error
        echo error(6);
    }
} else {
    // Printing the first error
Exemplo n.º 4
0
/**
 * Return the response without the agent
 *
 * @param $username
 *            The username of the user
 * @param $clientToken
 *            The client token
 */
function send_response($username, $clientToken)
{
    // Generating a random access token
    $accessToken = md5(uniqid(rand(), true));
    // If the client token is empty
    if (empty($clientToken)) {
        // Generating a new client token
        $newClientToken = getClientToken();
        // Sending a request to the database to save the new access and client tokens
        Core\Queries::execute("UPDATE members SET accessToken=:accessToken, clientToken=:clientToken WHERE username=:username", ['accessToken' => $accessToken, 'clientToken' => $newClientToken, 'username' => $username]);
        // Creating a response array
        $response = array('accessToken' => $accessToken, 'clientToken' => $newClientToken);
        // Generating a JSON of the response
        $result = json_encode($response);
        // Printing it
        echo $result;
    } else {
        // Sending a request to the database to update the access token
        Core\Queries::execute("UPDATE members SET accessToken=:accessToken WHERE username=:username", ['accessToken' => $accessToken, 'username' => $username]);
        // Creating a response array
        $response = array('accessToken' => $accessToken, 'clientToken' => $clientToken);
        // Generating a JSON of it
        $result = json_encode($response);
        // Printing it
        echo $result;
    }
}
Exemplo n.º 5
0
     // Getting the given username
     $username = !empty($getContents['username']) ? $getContents['username'] : null;
     // Getting the given password
     $password = !empty($getContents['password']) ? $getContents['password'] : null;
     // If they aren't null
     if (!is_null($username) & !is_null($password)) {
         // Sending a request to the database to get the user from his username and his password
         $req = Core\Queries::execute('SELECT * FROM openauth_users WHERE username=:username', ['username' => $username]);
         // If the user was found (the request response isn't empty)
         if (!empty($req)) {
             // Hashing the password
             $password = hash('sha256', $password);
             // If the password is the same as the one of the database
             if ($password == $req->password) {
                 // Sending a request to the database to delete the user's access token
                 Core\Queries::execute('UPDATE openauth_users SET accessToken=:accessToken WHERE username=:username', ['username' => $username, 'accessToken' => null]);
             } else {
                 // Returning the third error
                 echo error(3);
             }
         }
         // Else if the request is empty (the user wasn't found)
         echo error(3);
     } else {
         // Returning the third error
         echo error(3);
     }
 } else {
     // Returning the sixth error
     echo error(6);
 }
Exemplo n.º 6
0
     // Decoding the JSON
     $getContents = json_decode($input, true);
     // Getting the access token from the JSON
     $accessToken = !empty($getContents['accessToken']) ? $getContents['accessToken'] : null;
     // Getting the client token from the JSON
     $clientToken = !empty($getContents['clientToken']) ? $getContents['clientToken'] : null;
     // If they aren't null
     if (!is_null($accessToken) && !is_null($clientToken)) {
         // Sending a request to the database to get the user from the client token
         $req = Core\Queries::execute('SELECT * FROM openauth_users WHERE clientToken=:clientToken', ['clientToken' => $clientToken]);
         // If the client token exists in the database (so the response isn't empty)
         if (!empty($req)) {
             // If the given access token and the database access token are the same
             if ($accessToken == $req->accessToken) {
                 // Updating the access and the client token in the database
                 Core\Queries::execute("UPDATE openauth_users SET accessToken=:accessToken WHERE clientToken=:clientToken", ['clientToken' => $clientToken, 'accessToken' => '']);
             } else {
                 // Returning the fourth error
                 echo error(4);
             }
         } else {
             // Returning the fourth error
             echo error(4);
         }
     } else {
         echo error(4);
     }
 } else {
     // Returning the sixth error
     echo error(6);
 }