@@ -68,13 +68,24 @@ public function __construct($username = NULL, $password = NULL, $auth_token = NU
68
68
$ this ->auth_token = FALSE ;
69
69
$ this ->username = FALSE ;
70
70
71
- if (!empty ($ password )) {
72
- $ this ->login ($ username , $ password );
73
- }
74
- elseif (!empty ($ auth_token )) {
71
+ if (!empty ($ auth_token )) {
75
72
$ this ->auth_token = $ auth_token ;
76
73
$ this ->cache = new SnapchatCache ();
77
74
$ this ->username = $ username ;
75
+
76
+ //Retrieve updates like if we performed an actual log in.
77
+ $ updates = $ this ->getUpdates (true );
78
+ //Checks if login was ok.
79
+ if ($ updates === false )
80
+ {
81
+ //Login with this auth token failed. Set our state to not logged in.
82
+ $ this ->auth_token = FALSE ;
83
+ $ this ->username = FALSE ;
84
+ }
85
+ }
86
+ //Only log in if auth token wasn't set.
87
+ elseif (!empty ($ password )) {
88
+ $ this ->login ($ username , $ password );
78
89
}
79
90
}
80
91
@@ -119,6 +130,29 @@ public function login($username, $password) {
119
130
return FALSE ;
120
131
}
121
132
}
133
+ /**
134
+ * Gets the auth token for external storage in between requests.
135
+ *
136
+ * @return mixed
137
+ * The auth token if succesfull, FALSE otherwise.
138
+ */
139
+ public function getAuthToken ()
140
+ {
141
+ return $ this ->auth_token ; //Is either a string or FALSE
142
+ }
143
+
144
+ /**
145
+ * Checks if we are logged in
146
+ *
147
+ * @return bool
148
+ * True if logged in, false otherwise
149
+ */
150
+ public function isLoggedIn ()
151
+ {
152
+ //If either one evaluates to false, inner statement is true and return becomes false.
153
+ //Could probably be && but I just stole this from elsewhere in this code.
154
+ return !(!$ this ->auth_token || !$ this ->username );
155
+ }
122
156
123
157
/**
124
158
* Logs out the current user.
0 commit comments