Created
May 12, 2020 15:12
-
-
Save DjangoLC/2a9a0406fd1c322ee3e1f36da3ec3c51 to your computer and use it in GitHub Desktop.
Repository que hace la validacion para iniciar sesion con usuario o contrasenia o biometrics en caso de tener uno activo
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
package com.example.data.repository | |
import com.example.data.UserPreferences | |
import com.example.data.auth.Auth | |
import com.example.data.auth.AuthValidator | |
import com.example.data.source.LocalDataSource | |
class UserRepository( | |
private val auth: Auth, | |
private val authValidator: AuthValidator, | |
private val preferences: UserPreferences, | |
private val localDataSource: LocalDataSource | |
) { | |
suspend fun login(user: String, pass: String): Boolean { | |
var login = false | |
if (preferences.getBoolean(UserPreferences.HAS_FINGERPRINT_ENABLE)) { | |
login = auth.authWithFingerPrint() | |
} | |
if (preferences.getBoolean(UserPreferences.HAS_FACE_ID_ENABLE)) { | |
login = auth.authWithFaceID() | |
} | |
if (!login) { | |
login = localDataSource.login(user, pass) | |
} | |
return login | |
} | |
fun enableFingerPrint(value: Boolean) { | |
preferences.saveBoolean(UserPreferences.HAS_FINGERPRINT_ENABLE, value) | |
} | |
suspend fun authWithFingerPrint(): Boolean { | |
return auth.authWithFingerPrint() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment