Skip to content

Commit 6b282b6

Browse files
Created userVerified() method to authenticate user
1 parent 6058b71 commit 6b282b6

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

src/snapchat.php

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function login($username, $password) {
128128
*/
129129
public function logout() {
130130
// Make sure we're logged in and have a valid access token.
131-
if (!$this->auth_token || !$this->username) {
131+
if (!userVerified()) {
132132
return FALSE;
133133
}
134134

@@ -217,6 +217,17 @@ public function register($username, $password, $email, $birthday) {
217217
return $result;
218218
}
219219

220+
/**
221+
* Checks if the user is logged in and has a valid auth token.
222+
*
223+
* @return TRUE if the user is verified, FALSE otherwise
224+
*/
225+
public function userVerified()
226+
{
227+
return ($this->auth_token && $this->username);
228+
}
229+
230+
220231
/**
221232
* Retrieves general user, friend, and snap updates.
222233
*
@@ -227,7 +238,7 @@ public function register($username, $password, $email, $birthday) {
227238
* @return mixed
228239
* The data returned by the service or FALSE on failure.
229240
*/
230-
public function getUpdates($force = FALSE) {
241+
public function getUpdates($force = FALSE) {
231242
if (!$force) {
232243
$result = $this->cache->get('updates');
233244
if ($result) {
@@ -236,7 +247,7 @@ public function getUpdates($force = FALSE) {
236247
}
237248

238249
// Make sure we're logged in and have a valid access token.
239-
if (!$this->auth_token || !$this->username) {
250+
if (!userVerified()) {
240251
return FALSE;
241252
}
242253

@@ -319,7 +330,7 @@ function getFriendStories($force = FALSE) {
319330
}
320331

321332
// Make sure we're logged in and have a valid access token.
322-
if (!$this->auth_token || !$this->username) {
333+
if (!userVerified()) {
323334
return FALSE;
324335
}
325336

@@ -372,7 +383,7 @@ public function findFriends($numbers, $country = 'US') {
372383
$batches = array_chunk(array_flip($numbers), 30, TRUE);
373384

374385
// Make sure we're logged in and have a valid access token.
375-
if (!$this->auth_token || !$this->username) {
386+
if (!userVerified()) {
376387
return FALSE;
377388
}
378389

@@ -444,7 +455,7 @@ public function getAddedFriends() {
444455
*/
445456
public function addFriend($username) {
446457
// Make sure we're logged in and have a valid access token.
447-
if (!$this->auth_token || !$this->username) {
458+
if (!userVerified()) {
448459
return FALSE;
449460
}
450461

@@ -482,7 +493,7 @@ public function addFriend($username) {
482493
*/
483494
public function addFriends($usernames) {
484495
// Make sure we're logged in and have a valid access token.
485-
if (!$this->auth_token || !$this->username) {
496+
if (!userVerified()) {
486497
return FALSE;
487498
}
488499

@@ -530,7 +541,7 @@ public function addFriends($usernames) {
530541
*/
531542
public function deleteFriend($username) {
532543
// Make sure we're logged in and have a valid access token.
533-
if (!$this->auth_token || !$this->username) {
544+
if (!userVerified()) {
534545
return FALSE;
535546
}
536547

@@ -565,7 +576,7 @@ public function deleteFriend($username) {
565576
*/
566577
public function setDisplayName($username, $display) {
567578
// Make sure we're logged in and have a valid access token.
568-
if (!$this->auth_token || !$this->username) {
579+
if (!userVerified()) {
569580
return FALSE;
570581
}
571582

@@ -599,7 +610,7 @@ public function setDisplayName($username, $display) {
599610
*/
600611
public function block($username) {
601612
// Make sure we're logged in and have a valid access token.
602-
if (!$this->auth_token || !$this->username) {
613+
if (!userVerified()) {
603614
return FALSE;
604615
}
605616

@@ -632,7 +643,7 @@ public function block($username) {
632643
*/
633644
public function unblock($username) {
634645
// Make sure we're logged in and have a valid access token.
635-
if (!$this->auth_token || !$this->username) {
646+
if (!userVerified()) {
636647
return FALSE;
637648
}
638649

@@ -666,7 +677,7 @@ public function unblock($username) {
666677
*/
667678
public function getMedia($id) {
668679
// Make sure we're logged in and have a valid access token.
669-
if (!$this->auth_token || !$this->username) {
680+
if (!userVerified()) {
670681
return FALSE;
671682
}
672683

@@ -712,7 +723,7 @@ public function getMedia($id) {
712723
*/
713724
public function sendEvents($events, $snap_info = array()) {
714725
// Make sure we're logged in and have a valid access token.
715-
if (!$this->auth_token || !$this->username) {
726+
if (!userVerified()) {
716727
return FALSE;
717728
}
718729

@@ -837,7 +848,7 @@ public function markSnapShot($id, $time = 1) {
837848
*/
838849
public function upload($type, $data) {
839850
// Make sure we're logged in and have a valid access token.
840-
if (!$this->auth_token || !$this->username) {
851+
if (!userVerified()) {
841852
return FALSE;
842853
}
843854

@@ -887,7 +898,7 @@ public function upload($type, $data) {
887898
*/
888899
public function send($media_id, $recipients, $time = 3) {
889900
// Make sure we're logged in and have a valid access token.
890-
if (!$this->auth_token || !$this->username) {
901+
if (!userVerified()) {
891902
return FALSE;
892903
}
893904

@@ -925,7 +936,7 @@ public function send($media_id, $recipients, $time = 3) {
925936
*/
926937
public function setStory($media_id, $media_type, $time = 3) {
927938
// Make sure we're logged in and have a valid access token.
928-
if (!$this->auth_token || !$this->username) {
939+
if (!userVerified()) {
929940
return FALSE;
930941
}
931942

@@ -964,7 +975,7 @@ public function setStory($media_id, $media_type, $time = 3) {
964975
*/
965976
public function getStory($media_id, $key, $iv) {
966977
// Make sure we're logged in and have a valid access token.
967-
if (!$this->auth_token || !$this->username) {
978+
if (!userVerified()) {
968979
return FALSE;
969980
}
970981

@@ -993,7 +1004,7 @@ public function getStory($media_id, $key, $iv) {
9931004
*/
9941005
public function getStoryThumb($media_id, $key, $iv) {
9951006
// Make sure we're logged in and have a valid access token.
996-
if (!$this->auth_token || !$this->username) {
1007+
if (!userVerified()) {
9971008
return FALSE;
9981009
}
9991010

@@ -1020,7 +1031,7 @@ public function getStoryThumb($media_id, $key, $iv) {
10201031
*/
10211032
public function markStoryViewed($id, $screenshot_count = 0) {
10221033
// Make sure we're logged in and have a valid access token.
1023-
if (!$this->auth_token || !$this->username) {
1034+
if (!userVerified()) {
10241035
return FALSE;
10251036
}
10261037

@@ -1059,7 +1070,7 @@ public function markStoryViewed($id, $screenshot_count = 0) {
10591070
*/
10601071
public function getBests($friends) {
10611072
// Make sure we're logged in and have a valid access token.
1062-
if (!$this->auth_token || !$this->username) {
1073+
if (!userVerified()) {
10631074
return FALSE;
10641075
}
10651076

@@ -1097,7 +1108,7 @@ public function getBests($friends) {
10971108
*/
10981109
public function clearFeed() {
10991110
// Make sure we're logged in and have a valid access token.
1100-
if (!$this->auth_token || !$this->username) {
1111+
if (!userVerified()) {
11011112
return FALSE;
11021113
}
11031114

@@ -1128,7 +1139,7 @@ public function clearFeed() {
11281139
*/
11291140
public function updatePrivacy($setting) {
11301141
// Make sure we're logged in and have a valid access token.
1131-
if (!$this->auth_token || !$this->username) {
1142+
if (!userVerified()) {
11321143
return FALSE;
11331144
}
11341145

@@ -1161,7 +1172,7 @@ public function updatePrivacy($setting) {
11611172
*/
11621173
public function updateEmail($email) {
11631174
// Make sure we're logged in and have a valid access token.
1164-
if (!$this->auth_token || !$this->username) {
1175+
if (!userVerified()) {
11651176
return FALSE;
11661177
}
11671178

0 commit comments

Comments
 (0)