예제 #1
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $userKey = $request->input('_key');
     if ($userKey && !empty($userKey)) {
         $user = User::where('user_key', $userKey)->first();
         if (Auth::check()) {
             $prevuser = Auth::user();
             Auth::logout();
         }
         if ($user->exists()) {
             Auth::login($user);
             $response = $next($request);
             Auth::logout();
             if (isset($prevuser) && isset($prevuser->id)) {
                 Auth::login($prevuser);
             }
             return $response;
         } else {
             $response = $next($request);
         }
         if (isset($prevuser)) {
             Auth::login($prevuser);
         }
         return $response;
     }
     if ($request->is('api/v1/donate/ipn')) {
         return $next($request);
     }
     return parent::handle($request, $next);
 }
예제 #2
0
 public function IPNAction()
 {
     $listener = new ListenerBuilder();
     $listener = $listener->build();
     $listener->onVerified(function (MessageVerifiedEvent $event) {
         $ipnMessage = $event->getMessage();
         if ($ipnMessage->get('payment_status') != 'Completed') {
             return;
         }
         $original_amount = $ipnMessage->get('mc_gross');
         $amount_sub = $ipnMessage->get('mc_fee');
         $smallId = $ipnMessage->get('custom');
         $donationLog = new DonationLog();
         $donationLog->status = 'Completed';
         $donationLog->amount = $original_amount - $amount_sub;
         $donationLog->original_amount = $original_amount;
         if (is_numeric($smallId)) {
             $user = User::whereSmallId($smallId)->first();
             if (isset($user->id)) {
                 $user->donation += $original_amount;
                 $user->save();
                 $donationLog->small_id = $smallId;
                 Cache::forget("profile_{$smallId}");
             }
         }
         $donationLog->save();
     });
     $listener->listen();
 }
예제 #3
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->auth->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             $thisRoute = explode('.', $request->route()->getName());
             if ($thisRoute[0] == 'api') {
                 $userKey = $request->input('_key');
                 if ($userKey && !empty($userKey)) {
                     $user = User::where('user_key', $userKey)->first();
                     if (isset($user->id)) {
                         return $next($request);
                     }
                 }
                 return ['error' => 'forbidden'];
             }
             return redirect()->guest('auth/login');
         }
     }
     return $next($request);
 }
예제 #4
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.');
 }
예제 #5
0
 function __construct($userList)
 {
     if (!isset($userList->id)) {
         $this->error = "list_invalid";
         return;
     }
     if (Auth::check()) {
         $user = Auth::User();
         $userFriends = json_decode($user->friendslist);
         if ($user->id != $userList->user_id) {
             $listAuthor = User::whereId($userList->user_id)->first();
             if ($listAuthor->exists() && !empty($userFriends) && !in_array($listAuthor->small_id, $userFriends) && $userList->privacy == 2 || $userList->privacy == 3) {
                 $this->error = "list_no_permission";
                 return;
             }
         }
     } else {
         if ($userList->privacy == 2 || $userList->privacy == 3) {
             $this->error = "list_no_permission";
             return;
         }
     }
     $this->userList = $userList;
 }
예제 #6
0
 public function listList()
 {
     $return = ['my_list' => [], 'friends_list' => []];
     $user = Auth::user();
     $myLists = UserList::where('user_list.user_id', $user->id)->leftjoin('user_list_profile as ulp_1', 'ulp_1.user_list_id', '=', 'user_list.id')->groupBy('user_list.id')->orderBy('user_list.id', 'desc')->leftJoin('subscription', function ($join) {
         $join->on('subscription.user_list_id', '=', 'user_list.id')->whereNull('subscription.deleted_at');
     })->whereNull('ulp_1.deleted_at')->get(['user_list.id', 'user_list.title', 'user_list.privacy', 'user_list.created_at', \DB::raw('count(ulp_1.id) as users_in_list'), \DB::raw('count(distinct subscription.id) as sub_count')]);
     foreach ($myLists as $myList) {
         $return['my_list'][] = ['id' => $myList->id, 'title' => $myList->title, 'privacy' => $myList->privacy, 'created_at' => $myList->created_at->format("M j Y"), 'users_in_list' => $myList->users_in_list, 'sub_count' => $myList->sub_count];
     }
     if (isset($user->friendslist)) {
         $friendsList = json_decode($user->friendslist);
         $myfriendsLists = User::whereIn('users.small_id', $friendsList)->whereNotIn('user_list.privacy', [3])->whereNull('user_list_profile.deleted_at')->groupBy('user_list.id')->orderBy('user_list.id', 'desc')->leftjoin('user_list', 'user_list.user_id', '=', 'users.id')->leftjoin('user_list_profile', 'user_list.id', '=', 'user_list_profile.user_list_id')->leftjoin('profile', 'profile.small_id', '=', 'users.small_id')->leftJoin('subscription', function ($join) {
             $join->on('subscription.user_list_id', '=', 'user_list.id')->whereNull('subscription.deleted_at');
         })->having('users_in_list', '>', 0)->get(['profile.id as profile_id', 'profile.display_name', 'profile.avatar_thumb', 'profile.small_id', 'user_list.id as user_list_id', 'user_list.title', 'user_list.privacy', 'user_list.created_at', 'users.site_admin', 'users.donation', 'users.beta', \DB::raw('count(user_list_profile.created_at) as users_in_list'), \DB::raw('count(Distinct subscription.id) as sub_count')]);
         foreach ($myfriendsLists as $myfriendsList) {
             if (!isset($myfriendsList->profile_id) || empty($myfriendsList->profile_id)) {
                 continue;
             }
             $return['friends_list'][] = ['profile_id' => $myfriendsList->profile_id, 'display_name' => $myfriendsList->display_name, 'avatar_thumb' => $myfriendsList->avatar_thumb, 'steam_64_bit' => Steam::to64bit($myfriendsList->small_id), 'user_list_id' => $myfriendsList->user_list_id, 'title' => $myfriendsList->title, 'privacy' => $myfriendsList->privacy, 'created_at' => $myfriendsList->created_at->format("M j Y"), 'site_admin' => (int) $myfriendsList->site_admin ?: 0, 'donation' => (int) $myfriendsList->donation ?: 0, 'beta' => (int) $myfriendsList->beta ?: 0, 'users_in_list' => $myfriendsList->users_in_list, 'sub_count' => $myfriendsList->sub_count];
         }
     }
     return $return;
 }
예제 #7
0
 public function newUserKey(Request $request)
 {
     if ($request->input('_key')) {
         return ['error' => 'forbidden'];
     }
     $user = Auth::user();
     $users = User::whereNotNull('user_key')->get();
     while (true) {
         $userKey = str_random(32);
         $exist = $users->where('user_key', $userKey)->first();
         if (!isset($exist->id)) {
             $user->user_key = $userKey;
             $user->save();
             break;
         }
     }
     return [$user->user_key];
 }
예제 #8
0
 private function updateUsingAPI()
 {
     /* Time to follow that great guide to updating via API above */
     /* grab 'info' from web api and handle errors */
     $steamAPI = new SteamAPI('info');
     $steamAPI->setSmallId($this->smallId);
     $steamInfo = $steamAPI->run();
     if ($steamAPI->error()) {
         return ['error' => $steamAPI->errorMessage()];
     }
     if (!isset($steamInfo->response->players[0])) {
         return ['error' => 'profile_null'];
     }
     $steamInfo = $steamInfo->response->players[0];
     /* grab 'ban' from web api and handle errors */
     $steamAPI = new SteamAPI('ban');
     $steamAPI->setSmallId($this->smallId);
     $steamBan = $steamAPI->run();
     if ($steamAPI->error()) {
         return ['error' => $steamAPI->errorMessage()];
     }
     if (!isset($steamBan->players[0])) {
         return ['error' => 'profile_null'];
     }
     $steamBan = $steamBan->players[0];
     /* grab 'alias' from old web api but do not break on errors */
     $steamAPI = new SteamAPI('alias');
     $steamAPI->setSmallId($this->smallId);
     $steamAlias = $steamAPI->run();
     if ($steamAPI->error()) {
         $steamAlias = [];
     } else {
         usort($steamAlias, array('VacStatus\\Steam\\Steam', 'aliasSort'));
     }
     /* Successfully passed steam's not very reliable api servers */
     /* Lets hope we got the alias as well :))) */
     /* Lets start up with profile table */
     $profile = Profile::whereSmallId($this->smallId)->first();
     if (!isset($profile->id)) {
         $profile = new Profile();
         $profile->small_id = $this->smallId;
         if (isset($steamInfo->timecreated)) {
             $profile->profile_created = $steamInfo->timecreated;
         }
     } else {
         // Make sure to update if this was private and now suddenly public
         if (empty($profile->profile_created) && isset($steamInfo->timecreated)) {
             $profile->profile_created = $steamInfo->timecreated;
         }
     }
     $profile->display_name = $steamInfo->personaname;
     $profile->avatar = Steam::imgToHTTPS($steamInfo->avatarfull);
     $profile->avatar_thumb = Steam::imgToHTTPS($steamInfo->avatar);
     $profile->privacy = $steamInfo->communityvisibilitystate;
     $profile->alias = json_encode($steamAlias);
     if (!$profile->save()) {
         return ['error' => 'profile_save_error'];
     }
     /* Now to do profile_ban table */
     $profileBan = $profile->ProfileBan;
     // Dont update the profile_ban if there is nothing to update
     // This has to do with in the future when I check for new bans to notify/email
     $skipProfileBan = false;
     $newVacBanDate = new DateTime();
     $newVacBanDate->sub(new DateInterval("P{$steamBan->DaysSinceLastBan}D"));
     $combinedBan = (int) $steamBan->NumberOfVACBans + (int) $steamBan->NumberOfGameBans;
     if (!isset($profileBan->id)) {
         $profileBan = new ProfileBan();
         $profileBan->profile_id = $profile->id;
         $profileBan->unban = false;
     } else {
         $skipProfileBan = $profileBan->skipProfileBanUpdate($steamBan);
         if ($profileBan->vac != (int) $steamBan->NumberOfVACBans + (int) $steamBan->NumberOfGameBans && $profileBan->vac_banned_on->format('Y-m-d') !== $newVacBanDate->format('Y-m-d')) {
             $skipProfileBan = false;
             $profileBan->timestamps = false;
         }
         if ($profileBan->vac > $combinedBan) {
             $profileBan->timestamps = false;
             $profileBan->unban = true;
         }
     }
     $profileBan->vac = $combinedBan;
     $profileBan->community = $steamBan->CommunityBanned;
     $profileBan->trade = $steamBan->EconomyBan != 'none';
     $profileBan->vac_banned_on = $newVacBanDate->format('Y-m-d');
     if (!$skipProfileBan) {
         if (!$profile->ProfileBan()->save($profileBan)) {
             return ['error' => 'profile_ban_save_error'];
         }
     }
     /* Time to do profile_old_alias */
     /* Checks to make sure if there is already a same name before inserting new name */
     $profileOldAlias = $profile->ProfileOldAlias()->whereProfileId($profile->id)->orderBy('id', 'desc')->get();
     $currentTime = new DateTime();
     if ($profileOldAlias->count() == 0) {
         $profileOldAlias = new ProfileOldAlias();
         $profileOldAlias->profile_id = $profile->id;
         $profileOldAlias->seen = $currentTime->format('Y-m-d');
         $profileOldAlias->seen_alias = $profile->display_name;
         $profileOldAlias->save();
     } else {
         $match = false;
         $recent = 0;
         foreach ($profileOldAlias as $oldAlias) {
             if (!is_object($oldAlias)) {
                 continue;
             }
             if ($oldAlias->seen_alias == $profile->display_name) {
                 $match = true;
                 break;
             }
             $recent = $oldAlias->compareTime($recent);
         }
         if (!$match && $recent + Steam::$UPDATE_TIME < time()) {
             $currentTime = new DateTime();
             $newAlias = new ProfileOldAlias();
             $newAlias->profile_id = $profile->id;
             $newAlias->seen = $currentTime->format('Y-m-d');
             $newAlias->seen_alias = $profile->display_name;
             $profile->ProfileOldAlias()->save($newAlias);
         }
     }
     $profileOldAlias = $profile->ProfileOldAlias()->whereProfileId($profile->id)->orderBy('id', 'desc')->get();
     /* Finished inserting / updating into the DB! */
     /* Check to see if this user has an account in vacstatus */
     $user = User::where('small_id', $this->smallId)->first();
     /* getting the number of times checked and added */
     $gettingCount = UserListProfile::whereProfileId($profile->id)->orderBy('id', 'desc')->get();
     $profileTimesAdded = ['number' => $gettingCount->count(), 'time' => isset($gettingCount[0]) ? (new DateTime($gettingCount[0]->created_at))->format("M j Y") : null];
     $profileCheckCache = "profile_checked_";
     $currentProfileCheck = ['number' => 0, 'time' => date("M j Y", time())];
     if (Cache::has($profileCheckCache . $this->smallId)) {
         $currentProfileCheck = Cache::get($profileCheckCache . $this->smallId);
     }
     $newProfileCheck = ['number' => $currentProfileCheck['number'] + 1, 'time' => date("M j Y", time())];
     Cache::forever($profileCheckCache . $this->smallId, $newProfileCheck);
     /* Writing the return array for the single profile */
     $steam64BitId = Steam::to64Bit($profile->small_id);
     $oldAliasArray = [];
     foreach ($profileOldAlias as $k => $oldAlias) {
         if ($oldAlias === true) {
             $oldAliasArray[] = ["newname" => $profileOldAlias->seen_alias, "timechanged" => $profileOldAlias->seen->format("M j Y")];
             break;
         }
         $oldAliasArray[] = ["newname" => $oldAlias->seen_alias, "timechanged" => $oldAlias->seen->format("M j Y")];
     }
     $return = ['id' => $profile->id, 'display_name' => $steamInfo->personaname, 'avatar' => Steam::imgToHTTPS($steamInfo->avatarfull), 'avatar_thumb' => Steam::imgToHTTPS($steamInfo->avatar), 'small_id' => $this->smallId, 'steam_64_bit' => $steam64BitId, 'steam_32_bit' => Steam::to32Bit($steam64BitId), 'profile_created' => isset($profile->profile_created) ? date("M j Y", $profile->profile_created) : "Unknown", 'privacy' => $steamInfo->communityvisibilitystate, 'alias' => Steam::friendlyAlias($steamAlias), 'created_at' => $profile->created_at->format("M j Y"), 'vac' => $combinedBan, 'vac_banned_on' => $newVacBanDate->format("M j Y"), 'community' => $steamBan->CommunityBanned, 'trade' => $steamBan->EconomyBan != 'none', 'site_admin' => (int) isset($user->id) ? $user->site_admin : 0, 'donation' => (int) isset($user->id) ? $user->donation : 0, 'beta' => (int) isset($user->id) ? $user->beta : 0, 'profile_old_alias' => $oldAliasArray, 'times_checked' => $currentProfileCheck, 'times_added' => $profileTimesAdded];
     /* YAY nothing broke :D time to return the data (and update cache) */
     $this->updateCache($return);
     return $return;
 }
예제 #9
0
 public function user()
 {
     $users = User::paginate(50);
     return view('admin.pages.database.users', compact('users'));
 }