aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-03 13:22:06 -0700
committerAllan Wang <me@allanwang.ca>2017-06-03 13:22:06 -0700
commit35185958b077880465696d686bd797895cd3ebd4 (patch)
tree431967b2b00d00c71b06fa7a7814e05524961ead /app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
parent5796566137995c8d244720f87ba85bce0e0d2f00 (diff)
downloadfrost-35185958b077880465696d686bd797895cd3ebd4.tar.gz
frost-35185958b077880465696d686bd797895cd3ebd4.tar.bz2
frost-35185958b077880465696d686bd797895cd3ebd4.zip
setup login activity
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt40
1 files changed, 10 insertions, 30 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
index 7829998f..038eb1a6 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbCookie.kt
@@ -32,57 +32,37 @@ object FbCookie {
}
}
- private val userMatcher: Regex by lazy { Regex("c_user=([0-9]*);") }
-
- fun hasLoggedIn(url: String, cookie: String?):Boolean {
- if (cookie == null || !url.contains("facebook") || !cookie.contains(userMatcher)) return false
- L.d("Checking cookie for $url\n\t$cookie")
- val id = userMatcher.find(cookie)?.groups?.get(1)?.value
- if (id != null) {
- try {
- save(id.toLong(), -1)
- return true
- } catch (e: NumberFormatException) {
- //todo send report that id has changed
- }
- }
- return false
- }
-
- fun save(id: Long, sender: Int) {
+ fun save(id: Long) {
L.d("New cookie found for $id")
Prefs.userId = id
CookieManager.getInstance().flush()
val cookie = CookieModel(Prefs.userId, "", webCookie)
- EventBus.getDefault().post(FbAccountEvent(cookie, sender, FbAccountEvent.FLAG_NEW))
saveFbCookie(cookie)
}
- //TODO reset when new account is added; reset and clear when account is logged out
- fun reset(loggedOut: Boolean = false, sender: Int) {
+ fun reset() {
Prefs.userId = Prefs.userIdDefault
with(CookieManager.getInstance()) {
removeAllCookies(null)
flush()
}
- EventBus.getDefault().post(FbAccountEvent(CookieModel(), sender, if (loggedOut) FbAccountEvent.FLAG_LOGOUT else FbAccountEvent.FLAG_RESET))
}
- fun switchUser(id: Long, sender: Int) = switchUser(loadFbCookie(id), sender)
+ fun switchUser(id: Long) = switchUser(loadFbCookie(id))
- fun switchUser(name: String, sender: Int) = switchUser(loadFbCookie(name), sender)
+ fun switchUser(name: String) = switchUser(loadFbCookie(name))
- fun switchUser(cookie: CookieModel?, sender: Int) {
+ fun switchUser(cookie: CookieModel?) {
if (cookie == null) return
Prefs.userId = cookie.id
dbCookie = cookie.cookie
webCookie = dbCookie
- EventBus.getDefault().post(FbAccountEvent(cookie, sender, FbAccountEvent.FLAG_SWITCH))
+ //TODO add webview refresh event
}
- fun logout(sender: Int) {
- L.d("Logging out user ${Prefs.userId}")
- removeCookie(Prefs.userId)
- reset(true, sender)
+ fun logout(id:Long) {
+ L.d("Logging out user $id")
+ removeCookie(id)
+ reset()
}
} \ No newline at end of file