something
This commit is contained in:
parent
076b789eb4
commit
97da765a09
32
example.php
32
example.php
|
|
@ -1,3 +1,35 @@
|
||||||
<?php
|
<?php
|
||||||
// Tadah Federation API example file.
|
// Tadah Federation API example file.
|
||||||
include './tadah_federation.php';
|
include './tadah_federation.php';
|
||||||
|
|
||||||
|
|
||||||
|
// Detect if any POST data was received, if so log in to Tadah.
|
||||||
|
if(isset($_POST)){
|
||||||
|
if(isset($_POST['email']) && isset($_POST['password'])){
|
||||||
|
$email = $_POST['email'];
|
||||||
|
$password = $_POST['password'];
|
||||||
|
$login = new tadah_federation();
|
||||||
|
$login_result = $login->Login($email, $password);
|
||||||
|
echo "LOGIN RESULT: ".$login_result."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detect if any GET data was received, if so log in to Tadah.
|
||||||
|
if(isset($_GET)){
|
||||||
|
if(isset($_GET['email']) && isset($_GET['password'])){
|
||||||
|
$email = $_GET['email'];
|
||||||
|
$password = $_GET['password'];
|
||||||
|
$login = new tadah_federation();
|
||||||
|
$login_result = $login->Login($email, $password);
|
||||||
|
echo "LOGIN RESULT: ".$login_result."\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Below is an example Form for logging into a Tadah account and returns User info.
|
||||||
|
?>
|
||||||
|
<h1>Tadah Federation API Example - Login</h1>
|
||||||
|
<form action="" method="post">
|
||||||
|
<input type="text" name="email" placeholder="Tadah Email">
|
||||||
|
<input type="password" name="password" placeholder="Password">
|
||||||
|
<input type="submit" value="Login">
|
||||||
|
</form>
|
||||||
|
|
|
||||||
|
|
@ -16,3 +16,12 @@ Before processing user credentials, the API will fetch a CSRF token by `GET`'ing
|
||||||
Then is `POST`'ed user credentials along with the CSRF token.
|
Then is `POST`'ed user credentials along with the CSRF token.
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
Login(username, password) - logs into Tadah and returns the user's info as an `Array`.
|
||||||
|
|
||||||
|
# Example
|
||||||
|
```
|
||||||
|
<?php
|
||||||
|
require('tadah_federation.php');
|
||||||
|
$login = new tadah_federation();
|
||||||
|
$login_result = $login->Login("yourTadahEmail@tadah.rocks", "TadahAccountPassword");
|
||||||
|
echo "LOGIN RESULT: ".$login_result;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,83 @@
|
||||||
<?php
|
<?php
|
||||||
// Tadah User Federation PHP API (Unofficial)
|
// Tadah User Federation PHP API (Unofficial)
|
||||||
// Created by PlaceholderLabs
|
// Created by PlaceholderLabs
|
||||||
|
// This is a hacky mess, but it works. (not really right now)
|
||||||
|
|
||||||
|
|
||||||
class tadah_federation
|
class tadah_federation
|
||||||
{
|
{
|
||||||
function GetCSRF(){
|
// Login() - Logs into a Tadah account.
|
||||||
// Perform a GET request to https://tadah.rocks/login then
|
// Takes 2 strings (Email and Password) and returns an array of information about the account.
|
||||||
|
// REQUIRES A CSRF TOKEN! FOR SOME GOD DAMN REASON WE CAN'T STORE COOKIES AND GENERATE CSRF TOKENS WITHOUT LOGGING IN REAL-TIME!
|
||||||
|
function Login($email, $password){
|
||||||
|
/////////////// start of CSRF token fetching /////////////
|
||||||
|
// Prepare to perform a GET request to https://tadah.rocks/login then fetch _token in the HTML form
|
||||||
|
$ch = curl_init();
|
||||||
|
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_URL, "https://tadah.rocks/login");
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
// custom user agent so Tadah staff/server doesn't block us or IP poison us
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, 'cURL/TadahFederation v1 - github.com/PlaceholderLabs/TadahFederation');
|
||||||
|
|
||||||
|
|
||||||
|
// fetch the site's HTML
|
||||||
|
$csrf_html = curl_exec($ch);
|
||||||
|
|
||||||
|
// find the CSRF token in the HTML
|
||||||
|
// TODO: prepare this for Tadah rewrite if login HTML changes!
|
||||||
|
$pattern = '/<input type="hidden" name="_token" value="(.*?)"/';
|
||||||
|
preg_match($pattern, $csrf_html, $matches);
|
||||||
|
|
||||||
|
|
||||||
|
/////////////// end of CSRF token fetching ///////////////
|
||||||
|
|
||||||
|
/////////////// start of login request ///////////////
|
||||||
|
// prepare to perform a POST request to https://tadah.rocks/login
|
||||||
|
echo $email."\n";
|
||||||
|
echo $password."\n";
|
||||||
|
echo $matches[1]."\n";
|
||||||
|
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_URL, 'https://tadah.rocks/login');
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
// POST the data
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 1);
|
||||||
|
|
||||||
|
|
||||||
|
// include the CSRF token
|
||||||
|
//curl_setopt($ch, CURLOPT_POSTFIELDS, '_token=r8YHSt4LDyVUmNXgFeHrMzRiDJpLaH8IdGvYBM7R'.'&email='.$email.'&password='.$password);
|
||||||
|
curl_setopt_array($ch, array(
|
||||||
|
CURLOPT_POSTFIELDS => array(
|
||||||
|
'_token' => $matches[1],
|
||||||
|
'email' => $email,
|
||||||
|
'password' => $password
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
// custom user agent so Tadah staff/server doesn't block us or IP poison us
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, 'cURL/TadahFederation v1 - github.com/PlaceholderLabs/TadahFederation');
|
||||||
|
|
||||||
|
$login_result = curl_exec($ch);
|
||||||
|
/////////////// end of login request ///////////////
|
||||||
|
|
||||||
|
|
||||||
|
/////////////// start of account info fetching ///////////////
|
||||||
|
// Attempt to visit the dashboard, now that we're logged in (this should tell us info like our username, and if we're banned)
|
||||||
|
curl_setopt($ch, CURLOPT_URL, 'https://tadah.rocks/my/dashboard');
|
||||||
|
|
||||||
|
// disable POST, we're not sending any data anymore
|
||||||
|
curl_setopt($ch, CURLOPT_POST, 0);
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
|
|
||||||
|
// fetch the site's HTML
|
||||||
|
$result = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
/////////////// end of account info fetching ///////////////
|
||||||
|
|
||||||
|
|
||||||
|
// return results
|
||||||
|
return $login_result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue