-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from snuhcs-course/frontend/refactor-login
Login / Register 정리
- Loading branch information
Showing
21 changed files
with
357 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 1 addition & 7 deletions
8
frontend/app/src/main/java/com/example/frontend/model/AuthResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
package com.example.frontend.model | ||
|
||
import com.google.android.gms.maps.model.LatLng | ||
|
||
data class AuthResponse( | ||
val token: String, | ||
val userName: String, | ||
val userCurrentLocation: LatLng?, | ||
val userMail: String, | ||
val userProfile: Int | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.example.frontend.repository | ||
|
||
import android.content.Context | ||
import com.example.frontend.utilities.EncryptedSharedPreferenceKVStore | ||
import com.example.frontend.utilities.KVStore | ||
import com.example.frontend.utilities.SharedPreferenceKVStore | ||
|
||
|
@@ -24,6 +25,10 @@ class UserContextRepository( | |
return store.getString(AUTH_TOKEN) ?: "" | ||
} | ||
|
||
fun saveAuthToken(token: String) { | ||
store.putString(AUTH_TOKEN, token) | ||
} | ||
|
||
fun saveSelectedPredefinedImage(imageId: Int?) { | ||
if (imageId != null && imageId != KVStore.DEFAULT_INT) { | ||
store.putInt(SELECTED_PREDEFINED_IMAGE, imageId) | ||
|
@@ -35,13 +40,28 @@ class UserContextRepository( | |
return if (imageId != KVStore.DEFAULT_INT) imageId else null | ||
} | ||
|
||
fun saveUserMail(userMail: String) { | ||
store.putString(USER_MAIL, userMail) | ||
} | ||
|
||
fun saveIsLoggedIn(isLoggedIn: Boolean) { | ||
store.putBoolean(IS_LOGGED_IN, isLoggedIn) | ||
} | ||
|
||
fun getIsLoggedIn(): Boolean { | ||
return store.getBoolean(IS_LOGGED_IN) ?: false | ||
} | ||
|
||
companion object { | ||
/* | ||
* Returns UserContextRepository instance backed by SharedPreferenceKVStore. | ||
*/ | ||
fun ofContext(context: Context): UserContextRepository { | ||
val sharedPreferencesKVStore = SharedPreferenceKVStore(context) | ||
return UserContextRepository(sharedPreferencesKVStore) | ||
fun ofContext(context: Context, secure: Boolean = false): UserContextRepository { | ||
val store = if (secure) | ||
EncryptedSharedPreferenceKVStore(context) | ||
else | ||
SharedPreferenceKVStore(context) | ||
return UserContextRepository(store) | ||
} | ||
|
||
private const val USERNAME = "USERNAME" | ||
|
@@ -50,5 +70,6 @@ class UserContextRepository( | |
const val DEFAULT_USER_MAIL = "[email protected]" | ||
private const val AUTH_TOKEN = "AUTH_TOKEN" | ||
private const val SELECTED_PREDEFINED_IMAGE = "SELECTED_PREDEFINED_IMAGE" | ||
private const val IS_LOGGED_IN = "IS_LOGGED_IN" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.