This repository has been archived by the owner on Jun 15, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
322 additions
and
127 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import ModelManager from "./modelManager"; | ||
import Sync from "./syncManager"; | ||
import { SFPrivilegesManager, SFSingletonManager } from "standard-file-js"; | ||
import AuthenticationSourceAccountPassword from "@Screens/Authentication/Sources/AuthenticationSourceAccountPassword"; | ||
import AuthenticationSourceLocalPasscode from "@Screens/Authentication/Sources/AuthenticationSourceLocalPasscode"; | ||
import AuthenticationSourceFingerprint from "@Screens/Authentication/Sources/AuthenticationSourceFingerprint"; | ||
import KeysManager from "@Lib/keysManager" | ||
import Storage from "@SFJS/storageManager" | ||
import Auth from "@SFJS/authManager" | ||
|
||
export default class PrivilegesManager extends SFPrivilegesManager { | ||
|
||
static instance = null; | ||
|
||
static get() { | ||
if (this.instance == null) { | ||
let singletonManager = new SFSingletonManager(ModelManager.get(), Sync.get()); | ||
this.instance = new PrivilegesManager(ModelManager.get(), Sync.get(), singletonManager); | ||
} | ||
|
||
return this.instance; | ||
} | ||
|
||
constructor(modelManager, syncManager, singletonManager) { | ||
super(modelManager, syncManager, singletonManager); | ||
|
||
this.setDelegate({ | ||
isOffline: async () => { | ||
return Auth.get().offline(); | ||
}, | ||
hasLocalPasscode: async () => { | ||
return KeysManager.get().hasOfflinePasscode(); | ||
}, | ||
saveToStorage: async (key, value) => { | ||
return Storage.get().setItem(key, value); | ||
}, | ||
getFromStorage: async (key) => { | ||
return Storage.get().getItem(key); | ||
} | ||
}); | ||
} | ||
|
||
async presentPrivilegesModal(action, navigation, onSuccess, onCancel) { | ||
if(this.authenticationInProgress()) { | ||
onCancel && onCancel(); | ||
return; | ||
} | ||
|
||
let customSuccess = () => { | ||
onSuccess && onSuccess(); | ||
this.authInProgress = false; | ||
} | ||
|
||
let customCancel = () => { | ||
onCancel && onCancel(); | ||
this.authInProgress = false; | ||
} | ||
|
||
let sources = await this.sourcesForAction(action); | ||
|
||
navigation.navigate("Authenticate", { | ||
authenticationSources: sources, | ||
hasCancelOption: true, | ||
onSuccess: () => { | ||
customSuccess(); | ||
}, | ||
onCancel: () => { | ||
customCancel(); | ||
} | ||
}); | ||
|
||
this.authInProgress = true; | ||
} | ||
|
||
authenticationInProgress() { | ||
return this.authInProgress; | ||
} | ||
|
||
async sourcesForAction(action) { | ||
const sourcesForCredential = (credential) => { | ||
if(credential == SFPrivilegesManager.CredentialAccountPassword) { | ||
return [new AuthenticationSourceAccountPassword()]; | ||
} else if(credential == SFPrivilegesManager.CredentialLocalPasscode) { | ||
var hasPasscode = KeysManager.get().hasOfflinePasscode(); | ||
var hasFingerprint = KeysManager.get().hasFingerprint(); | ||
let sources = []; | ||
if(hasPasscode) {sources.push(new AuthenticationSourceLocalPasscode());} | ||
if(hasFingerprint) {sources.push(new AuthenticationSourceFingerprint());} | ||
return sources; | ||
} | ||
} | ||
|
||
let credentials = await this.netCredentialsForAction(action); | ||
let sources = []; | ||
for(var credential of credentials) { | ||
sources = sources.concat(sourcesForCredential(credential)); | ||
} | ||
|
||
return sources; | ||
} | ||
|
||
} |
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
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.