Exemplo n.º 1
0
 public function login()
 {
     if (Auth::check() || Auth::viaRemember()) {
         return redirect()->intended('/list')->with('success', 'You have Successfully logged in!');
     }
     $steamuser = SteamAuth::Auth();
     $steam64BitId = str_replace("http://steamcommunity.com/openid/id/", "", $steamuser['steamid']);
     $steamAPI = new SteamAPI('info');
     $steamAPI->setSteamId($steam64BitId);
     $userSteamInfo = $steamAPI->run();
     if (isset($userSteamInfo->type) && $userSteamInfo->type == 'error' || !isset($userSteamInfo->response->players[0])) {
         return redirect()->intended('/')->with('error', 'There was an error trying to communicate with Steam Server.');
     }
     $userSteamInfo = $userSteamInfo->response->players[0];
     $steamAPI = new SteamAPI('friends');
     $steamAPI->setSteamId($steam64BitId);
     $userSteamFriends = $steamAPI->run();
     $simpleFriends = [];
     if (isset($userSteamFriends->friendslist)) {
         $userSteamFriends = $userSteamFriends->friendslist->friends;
         foreach ($userSteamFriends as $userSteamFriend) {
             $simpleFriends[] = Steam::toSmallId($userSteamFriend->steamid);
         }
     }
     $smallId = Steam::toSmallId($steam64BitId);
     // Try to grab user or create new one
     $user = User::firstOrCreate(['small_id' => $smallId]);
     $user->display_name = $userSteamInfo->personaname;
     $user->friendslist = json_encode($simpleFriends);
     $singleProfile = new SingleProfile($smallId);
     $singleProfile->getProfile();
     if (!$user->save()) {
         return redirect()->intended('/')->with('error', 'There was an error adding user to database');
     }
     Auth::login($user, true);
     return redirect()->intended('/list')->with('success', 'You have Successfully logged in.');
 }
Exemplo n.º 2
0
 public static function findUser($data)
 {
     $data = strtolower(trim($data));
     if (empty($data)) {
         return ['error' => 'Invalid or empty input'];
     }
     if (strlen($data) > 100) {
         return ['error' => 'Field too long'];
     }
     if (substr($data, 0, 6) == 'steam_') {
         $tmp = explode(':', $data);
         if (count($tmp) == 3 && is_numeric($tmp[1]) && is_numeric($tmp[2])) {
             $steam3Id = bcadd($tmp[2] * 2 + $tmp[1], '76561197960265728');
             return ['success' => $steam3Id];
         }
         return ['error' => 'Invalid Steam ID'];
     } else {
         if (substr($data, 0, 2) == 'u:') {
             $tmp = explode(':', $data);
             if (count($tmp) == 3 && is_numeric($tmp[2])) {
                 $steam3Id = bcadd($tmp[2], '76561197960265728');
                 return ['success' => $steam3Id];
             }
             return ['error' => 'Invalid Steam ID'];
         } else {
             if ($p = strrpos($data, '/')) {
                 $tmp = array_values(array_filter(explode('/', $data)));
                 $a = null;
                 foreach ($tmp as $key => $item) {
                     if (!isset($tmp[$key + 1]) || empty($tmp[$key + 1])) {
                         return ['error' => 'Invalid input'];
                     }
                     if ($item == 'profiles') {
                         $a = $tmp[$key + 1];
                         break;
                     } else {
                         if ($item == 'id') {
                             $data = $tmp[$key + 1];
                             break;
                         }
                     }
                 }
                 if (is_numeric($a) && preg_match('/7656119/', $a)) {
                     return ['success' => $a];
                 } else {
                     $steamAPI = new SteamAPI('vanityUrl');
                     $steamVanityUrl = $steamAPI->setSteamId($data)->run();
                     if (isset($steamVanityUrl->type) && $steamVanityUrl->type == 'error' || !isset($steamVanityUrl->response->steamid) && $steamVanityUrl->response->success == 42) {
                         return ['error' => 'Invalid input'];
                     }
                     $steamid64 = (string) $steamVanityUrl->response->steamid;
                     if (!preg_match('/7656119/', $steamid64)) {
                         return ['error' => 'Invalid link'];
                     } else {
                         return ['success' => $steamid64];
                     }
                 }
             } else {
                 if (is_numeric($data) && preg_match('/7656119/', $data)) {
                     return ['success' => $data];
                 } else {
                     $steamAPI = new SteamAPI('vanityUrl');
                     $steamVanityUrl = $steamAPI->setSteamId($data)->run();
                     if (isset($steamVanityUrl->type) && $steamVanityUrl->type == 'error' || !isset($steamVanityUrl->response->steamid) && $steamVanityUrl->response->success == 42) {
                         return ['error' => 'Invalid input'];
                     }
                     $steamid64 = (string) $steamVanityUrl->response->steamid;
                     if (!preg_match('/7656119/', $steamid64)) {
                         return ['error' => 'Invalid input'];
                     } else {
                         return ['success' => $steamid64];
                     }
                 }
             }
         }
     }
 }