Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/constants/localAuthentication.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export const AUTO_LOCK = 'kAutoLock';
export const AUTO_LOCK_TIME = 'kAutoLockTime';
export const PASSCODE_KEY = 'kPasscode';
export const LOCKED_OUT_TIMER_KEY = 'kLockedOutTimer';
export const ATTEMPTS_KEY = 'kAttempts';
export const UNLOCK_FACE_ID = 'unlockFaceId';
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated

export const LOCAL_AUTHENTICATE_EMITTER = 'LOCAL_AUTHENTICATE';
export const CHANGE_PASSCODE_EMITTER = 'CHANGE_PASSCODE';
Expand Down
41 changes: 38 additions & 3 deletions app/utils/localAuthentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import UserPreferences from '../lib/userPreferences';
import store from '../lib/createStore';
import database from '../lib/database';
import {
ATTEMPTS_KEY,
CHANGE_PASSCODE_EMITTER,
LOCAL_AUTHENTICATE_EMITTER,
LOCKED_OUT_TIMER_KEY,
PASSCODE_KEY
ATTEMPTS_KEY,
PASSCODE_KEY,
CHANGE_PASSCODE_EMITTER,
UNLOCK_FACE_ID,
AUTO_LOCK,
AUTO_LOCK_TIME
} from '../constants/localAuthentication';
import I18n from '../i18n';
import { setLocalAuthenticated } from '../actions/login';
Expand Down Expand Up @@ -96,13 +99,45 @@ export const checkHasPasscode = async ({ force = true, serverRecord }) => {
return Promise.resolve();
};

export const saveStatusLocalAuthentication = async ({ autoLock, autoLockTime, biometry, server }) => {
await UserPreferences.setBoolAsync(AUTO_LOCK + server, autoLock);
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
await UserPreferences.setStringAsync(AUTO_LOCK_TIME + server, autoLockTime.toString());
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
await UserPreferences.setBoolAsync(UNLOCK_FACE_ID + server, biometry);
};

export const checkAutoLockAndTime = async server => {
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
const storedAutoLock = await UserPreferences.getBoolAsync(AUTO_LOCK + server);
const storedAutoLockTime = await UserPreferences.getStringAsync(AUTO_LOCK_TIME + server);
const storedBiometry = await UserPreferences.getBoolAsync(UNLOCK_FACE_ID + server);

return {
storedAutoLock,
storedAutoLockTime: Number.parseInt(storedAutoLockTime, 10),
storedBiometry
};
};

export const localAuthenticate = async server => {
const serversDB = database.servers;
const serversCollection = serversDB.get('servers');
const { Force_Screen_Lock, Force_Screen_Lock_After } = store.getState().settings;

let serverRecord;
try {
serverRecord = await serversCollection.find(server);

const { storedAutoLock, storedAutoLockTime, storedBiometry } = await checkAutoLockAndTime(server);
await serversDB.action(async () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get what we're trying to do here.
Aren't we migrating to MMKV?

@reinaldonetof reinaldonetof Oct 27, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to do that because when we are starting the app the getSettings is called and the serverInfoUpdate uses the data from the watermelonDB. When I proposed these changes I didn't change the getSettings, but what do you think about it?

await serverRecord.update(record => {
if (serverRecord.autoLock !== storedAutoLock && !Force_Screen_Lock) {
record.autoLock = storedAutoLock;
}
if (!Force_Screen_Lock || Force_Screen_Lock_After === 0) {
record.autoLockTime = storedAutoLockTime;
}
record.biometry = storedBiometry;
});
});
Comment thread
reinaldonetof marked this conversation as resolved.
Outdated
} catch (error) {
return Promise.reject();
}
Expand Down
14 changes: 13 additions & 1 deletion app/views/ScreenLockConfigView.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import { SWITCH_TRACK_COLOR, themes } from '../constants/colors';
import StatusBar from '../containers/StatusBar';
import * as List from '../containers/List';
import database from '../lib/database';
import { changePasscode, checkHasPasscode, supportedBiometryLabel } from '../utils/localAuthentication';
import {
supportedBiometryLabel,
changePasscode,
checkHasPasscode,
saveStatusLocalAuthentication
} from '../utils/localAuthentication';
import { DEFAULT_AUTO_LOCK } from '../constants/localAuthentication';
import SafeAreaView from '../containers/SafeAreaView';
import { events, logEvent } from '../utils/log';
Expand Down Expand Up @@ -102,7 +107,14 @@ class ScreenLockConfigView extends React.Component {

save = async () => {
logEvent(events.SLC_SAVE_SCREEN_LOCK);
const { server } = this.props;
const { autoLock, autoLockTime, biometry } = this.state;
await saveStatusLocalAuthentication({
autoLock,
autoLockTime,
biometry,
server
});
const serversDB = database.servers;
await serversDB.action(async () => {
await this.serverRecord?.update(record => {
Expand Down