|
|
@@ -14,58 +14,66 @@ function authRegister($username,$password,$defaults,$email){
|
|
|
}
|
|
|
}
|
|
|
function checkPlexUser($username){
|
|
|
- if(!empty($GLOBALS['plexToken'])){
|
|
|
- $url = 'https://plex.tv/pms/friends/all';
|
|
|
- $headers = array(
|
|
|
- 'X-Plex-Token' => $GLOBALS['plexToken'],
|
|
|
- );
|
|
|
- $response = Requests::get($url, $headers);
|
|
|
- if($response->success){
|
|
|
- libxml_use_internal_errors(true);
|
|
|
- $userXML = simplexml_load_string($response->body);
|
|
|
- if (is_array($userXML) || is_object($userXML)) {
|
|
|
- $usernameLower = strtolower($username);
|
|
|
- foreach($userXML AS $child) {
|
|
|
- if(isset($child['username']) && strtolower($child['username']) == $usernameLower || isset($child['email']) && strtolower($child['email']) == $usernameLower) {
|
|
|
- return true;
|
|
|
+ try{
|
|
|
+ if(!empty($GLOBALS['plexToken'])){
|
|
|
+ $url = 'https://plex.tv/pms/friends/all';
|
|
|
+ $headers = array(
|
|
|
+ 'X-Plex-Token' => $GLOBALS['plexToken'],
|
|
|
+ );
|
|
|
+ $response = Requests::get($url, $headers);
|
|
|
+ if($response->success){
|
|
|
+ libxml_use_internal_errors(true);
|
|
|
+ $userXML = simplexml_load_string($response->body);
|
|
|
+ if (is_array($userXML) || is_object($userXML)) {
|
|
|
+ $usernameLower = strtolower($username);
|
|
|
+ foreach($userXML AS $child) {
|
|
|
+ if(isset($child['username']) && strtolower($child['username']) == $usernameLower || isset($child['email']) && strtolower($child['email']) == $usernameLower) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- return false;
|
|
|
+ return false;
|
|
|
+ }catch( Requests_Exception $e ) {
|
|
|
+ writeLog('success', 'Plex User Check Function - Error: '.$e->getMessage(), $username);
|
|
|
+ };
|
|
|
}
|
|
|
function plugin_auth_plex($username, $password) {
|
|
|
- $usernameLower = strtolower($username);
|
|
|
- if(checkPlexUser($username)){
|
|
|
- //Login User
|
|
|
- $url = 'https://plex.tv/users/sign_in.json';
|
|
|
- $headers = array(
|
|
|
- 'Accept'=> 'application/json',
|
|
|
- 'Content-Type' => 'application/x-www-form-urlencoded',
|
|
|
- 'X-Plex-Product' => 'Organizr',
|
|
|
- 'X-Plex-Version' => '2.0',
|
|
|
- 'X-Plex-Client-Identifier' => '01010101-10101010',
|
|
|
- );
|
|
|
- $data = array(
|
|
|
- 'user[login]' => $username,
|
|
|
- 'user[password]' => $password,
|
|
|
- );
|
|
|
- $response = Requests::post($url, $headers, $data);
|
|
|
- if($response->success){
|
|
|
- $json = json_decode($response->body, true);
|
|
|
- if ((is_array($json) && isset($json['user']) && isset($json['user']['username'])) && strtolower($json['user']['username']) == $usernameLower || strtolower($json['user']['email']) == $usernameLower) {
|
|
|
- //writeLog("success", $json['user']['username']." was logged into organizr using plex credentials");
|
|
|
- return array(
|
|
|
- 'username' => $json['user']['username'],
|
|
|
- 'email' => $json['user']['email'],
|
|
|
- 'image' => $json['user']['thumb'],
|
|
|
- 'token' => $json['user']['authToken']
|
|
|
- );
|
|
|
+ try{
|
|
|
+ $usernameLower = strtolower($username);
|
|
|
+ if(checkPlexUser($username)){
|
|
|
+ //Login User
|
|
|
+ $url = 'https://plex.tv/users/sign_in.json';
|
|
|
+ $headers = array(
|
|
|
+ 'Accept'=> 'application/json',
|
|
|
+ 'Content-Type' => 'application/x-www-form-urlencoded',
|
|
|
+ 'X-Plex-Product' => 'Organizr',
|
|
|
+ 'X-Plex-Version' => '2.0',
|
|
|
+ 'X-Plex-Client-Identifier' => '01010101-10101010',
|
|
|
+ );
|
|
|
+ $data = array(
|
|
|
+ 'user[login]' => $username,
|
|
|
+ 'user[password]' => $password,
|
|
|
+ );
|
|
|
+ $response = Requests::post($url, $headers, $data);
|
|
|
+ if($response->success){
|
|
|
+ $json = json_decode($response->body, true);
|
|
|
+ if ((is_array($json) && isset($json['user']) && isset($json['user']['username'])) && strtolower($json['user']['username']) == $usernameLower || strtolower($json['user']['email']) == $usernameLower) {
|
|
|
+ //writeLog("success", $json['user']['username']." was logged into organizr using plex credentials");
|
|
|
+ return array(
|
|
|
+ 'username' => $json['user']['username'],
|
|
|
+ 'email' => $json['user']['email'],
|
|
|
+ 'image' => $json['user']['thumb'],
|
|
|
+ 'token' => $json['user']['authToken']
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- return false;
|
|
|
+ return false;
|
|
|
+ }catch( Requests_Exception $e ) {
|
|
|
+ writeLog('success', 'Plex Auth Function - Error: '.$e->getMessage(), $username);
|
|
|
+ };
|
|
|
}
|
|
|
if (function_exists('ldap_connect')){
|
|
|
// Pass credentials to LDAP backend
|