fix login

This commit is contained in:
ammarahm-ed
2020-12-10 13:06:59 +05:00
parent f8b1c61fe5
commit fd641ae5cf
11 changed files with 229275 additions and 44 deletions

View File

@@ -0,0 +1,215 @@
// Initialize some variables before react-native code would access them
var onmessage=null, self=global;
// Cache Node's original require as __debug__.require
global.__debug__={require: require};
// Prevent leaking process.versions from debugger process to
// worker because pure React Native doesn't do that and some packages as js-md5 rely on this behavior
Object.defineProperty(process, "versions", {
value: undefined
});
// TODO: Replace by url.fileURLToPath method when Node 10 LTS become deprecated
function fileUrlToPath(url) {
if (process.platform === 'win32') {
return url.toString().replace('file:///', '');
} else {
return url.toString().replace('file://', '');
}
}
function getNativeModules() {
var NativeModules;
try {
// This approach is for old RN versions
NativeModules = global.require('NativeModules');
} catch (err) {
// ignore error and try another way for more recent RN versions
try {
var nativeModuleId;
var modules = global.__r.getModules();
var ids = Object.keys(modules);
for (var i = 0; i < ids.length; i++) {
if (modules[ids[i]].verboseName) {
var packagePath = new String(modules[ids[i]].verboseName);
if (packagePath.indexOf('react-native/Libraries/BatchedBridge/NativeModules.js') > 0) {
nativeModuleId = parseInt(ids[i], 10);
break;
}
}
}
if (nativeModuleId) {
NativeModules = global.__r(nativeModuleId);
}
}
catch (err) {
// suppress errors
}
}
return NativeModules;
}
// Originally, this was made for iOS only
var vscodeHandlers = {
'vscode_reloadApp': function () {
var NativeModules = getNativeModules();
if (NativeModules && NativeModules.DevMenu) {
NativeModules.DevMenu.reload();
}
},
'vscode_showDevMenu': function () {
var NativeModules = getNativeModules();
if (NativeModules && NativeModules.DevMenu) {
NativeModules.DevMenu.show();
}
}
};
process.on("message", function (message) {
if (message.data && vscodeHandlers[message.data.method]) {
vscodeHandlers[message.data.method]();
} else if(onmessage) {
onmessage(message);
}
});
var postMessage = function(message){
process.send(message);
};
if (!self.postMessage) {
self.postMessage = postMessage;
}
var importScripts = (function(){
var fs=require('fs'), vm=require('vm');
return function(scriptUrl){
scriptUrl = fileUrlToPath(scriptUrl);
var scriptCode = fs.readFileSync(scriptUrl, 'utf8');
// Add a 'debugger;' statement to stop code execution
// to wait for the sourcemaps to be processed by the debug adapter
vm.runInThisContext('debugger;' + scriptCode, {filename: scriptUrl});
};
})();
// Worker is ran as nodejs process, so console.trace() writes to stderr and it leads to error in native app
// To avoid this console.trace() is overridden to print stacktrace via console.log()
// Please, see Node JS implementation: https://github.com/nodejs/node/blob/master/lib/internal/console/constructor.js
console.trace = (function() {
return function() {
try {
var err = {
name: 'Trace',
message: require('util').format.apply(null, arguments)
};
// Node uses 10, but usually it's not enough for RN app trace
Error.stackTraceLimit = 30;
Error.captureStackTrace(err, console.trace);
console.log(err.stack);
} catch (e) {
console.error(e);
}
};
})();
// As worker is ran in node, it breaks broadcast-channels package approach of identifying if its ran in node:
// https://github.com/pubkey/broadcast-channel/blob/master/src/util.js#L64
// To avoid it if process.toString() is called if will return empty string instead of [object process].
var nativeObjectToString = Object.prototype.toString;
Object.prototype.toString = function() {
if (this === process) {
return '';
} else {
return nativeObjectToString.call(this);
}
};
"use strict";
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
/* global __fbBatchedBridge, self, importScripts, postMessage, onmessage: true */
/* eslint no-unused-vars: 0 */
onmessage = function () {
var visibilityState;
var showVisibilityWarning = function () {
var hasWarned = false;
return function () {
// Wait until `YellowBox` gets initialized before displaying the warning.
if (hasWarned || console.warn.toString().includes('[native code]')) {
return;
}
hasWarned = true;
console.warn('Remote debugger is in a background tab which may cause apps to ' + 'perform slowly. Fix this by foregrounding the tab (or opening it in ' + 'a separate window).');
};
}();
var messageHandlers = {
executeApplicationScript: function (message, sendReply) {
for (var key in message.inject) {
self[key] = JSON.parse(message.inject[key]);
}
var error;
try {
importScripts(message.url);
} catch (err) {
error = err.message;
}
sendReply(null
/* result */
, error);
},
setDebuggerVisibility: function (message) {
visibilityState = message.visibilityState;
}
};
return function (message) {
if (visibilityState === 'hidden') {
showVisibilityWarning();
}
var object = message.data;
var sendReply = function (result, error) {
postMessage({
replyID: object.id,
result: result,
error: error
});
};
var handler = messageHandlers[object.method];
if (handler) {
// Special cased handlers
handler(object, sendReply);
} else {
// Other methods get called on the bridge
var returnValue = [[], [], [], 0];
var error;
try {
if (typeof __fbBatchedBridge === 'object') {
returnValue = __fbBatchedBridge[object.method].apply(null, object.arguments);
} else {
error = 'Failed to call function, __fbBatchedBridge is undefined';
}
} catch (err) {
error = err.message;
} finally {
sendReply(JSON.stringify(returnValue), error);
}
}
};
}();
//# sourceMappingURL=debuggerWorker.js.map
// Notify debugger that we're done with loading
// and started listening for IPC messages
postMessage({workerLoaded:true});

228981
apps/mobile/.vscode/.react/index.bundle vendored Normal file

File diff suppressed because one or more lines are too long

1
apps/mobile/.vscode/.react/index.map vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -5,6 +5,7 @@
"version": "0.2.0",
"configurations": [
{
"name": "Debug Android",
"cwd": "${workspaceFolder}",

View File

@@ -1,33 +1,34 @@
import * as NetInfo from '@react-native-community/netinfo';
import { CHECK_IDS, EV } from 'notes-core/common';
import React, { useEffect, useState } from 'react';
import {CHECK_IDS, EV} from 'notes-core/common';
import React, {useEffect, useState} from 'react';
import {
Appearance,
AppState,
Linking,
NativeModules,
Platform,
StatusBar
StatusBar,
} from 'react-native';
import * as RNIap from 'react-native-iap';
import { enabled } from 'react-native-privacy-snapshot';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import {enabled} from 'react-native-privacy-snapshot';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import SplashScreen from 'react-native-splash-screen';
import { useTracked } from './src/provider';
import { Actions } from './src/provider/Actions';
import {useTracked} from './src/provider';
import {Actions} from './src/provider/Actions';
import { DDS } from './src/services/DeviceDetection';
import {
eSendEvent,
eSubscribeEvent,
eUnSubscribeEvent,
ToastEvent
ToastEvent,
} from './src/services/EventManager';
import IntentService from './src/services/IntentService';
import { setLoginMessage } from './src/services/Message';
import {clearMessage, setLoginMessage} from './src/services/Message';
import Navigation from './src/services/Navigation';
import PremiumService from './src/services/PremiumService';
import { editing } from './src/utils';
import { COLOR_SCHEME } from './src/utils/Colors';
import { db } from './src/utils/DB';
import {editing} from './src/utils';
import {COLOR_SCHEME} from './src/utils/Colors';
import {db} from './src/utils/DB';
import {
eClosePremiumDialog,
eDispatchAction,
@@ -35,12 +36,12 @@ import {
eOpenPendingDialog,
eOpenPremiumDialog,
eShowGetPremium,
eStartSyncer
eStartSyncer,
} from './src/utils/Events';
import { MMKV } from './src/utils/mmkv';
import { tabBarRef } from './src/utils/Refs';
import { sleep } from './src/utils/TimeUtils';
import { getNote } from './src/views/Editor/Functions';
import {MMKV} from './src/utils/mmkv';
import {tabBarRef} from './src/utils/Refs';
import {sleep} from './src/utils/TimeUtils';
import {getNote} from './src/views/Editor/Functions';
const {ReceiveSharingIntent} = NativeModules;
let AppRootView = require('./initializer.root').RootView;
@@ -298,6 +299,7 @@ const App = () => {
sleep(500).then(() => (appInit = true));
db.notes.init().then(() => {
dispatch({type: Actions.NOTES});
console.log(db.notes.all);
dispatch({type: Actions.LOADING, loading: false});
SettingsService.setAppLoaded();
});
@@ -318,6 +320,7 @@ const App = () => {
await db.sync();
dispatch({type: Actions.ALL});
await startSyncer();
clearMessage(dispatch);
} else {
setLoginMessage(dispatch);
}
@@ -330,6 +333,14 @@ const App = () => {
useEffect(() => {
SettingsService = require('./src/services/SettingsService').default;
SettingsService.init();
dispatch({
type: Actions.DEVICE_MODE,
state: DDS.isLargeTablet()
? 'tablet'
: DDS.isSmallTab
? 'smallTablet'
: 'mobile',
});
db.init().finally(runAfterInit);
}, []);
@@ -384,32 +395,32 @@ const App = () => {
}, 500);
};
const onSubscriptionError = (error) => {
console.log(error.message, 'Error');
//ToastEvent.show(error.message);
};
const onSubscriptionError = (error) => {
console.log(error.message, 'Error');
//ToastEvent.show(error.message);
};
const processReceipt = (receipt) => {
if (receipt) {
if (Platform.OS === 'ios') {
fetch('http://192.168.10.5:8100/webhooks/assn', {
method: 'POST',
body: JSON.stringify({
receipt_data: subscription.transactionReceipt,
}),
headers: {
'Content-Type': 'application/json',
},
})
.then((r) => {
console.log(r.status, 'STATUS');
const processReceipt = (receipt) => {
if (receipt) {
if (Platform.OS === 'ios') {
fetch('http://192.168.10.5:8100/webhooks/assn', {
method: 'POST',
body: JSON.stringify({
receipt_data: subscription.transactionReceipt,
}),
headers: {
'Content-Type': 'application/json',
},
})
.catch((e) => {
console.log(e, 'ERROR');
});
.then((r) => {
console.log(r.status, 'STATUS');
})
.catch((e) => {
console.log(e, 'ERROR');
});
}
}
}
}
};
return (
<SafeAreaProvider>

View File

@@ -15,6 +15,7 @@ import {
eUnSubscribeEvent,
ToastEvent,
} from '../../services/EventManager';
import {clearMessage} from '../../services/Message';
import {
validateEmail,
validatePass,
@@ -112,7 +113,7 @@ const LoginDialog = () => {
setStatus('Logging in');
try {
await db.user.login(username.toLowerCase(), password);
await db.user.login(username.toLowerCase(), password, true);
} catch (e) {
ToastEvent.show(e.message, 'error', 'local');
setLoggingIn(false);
@@ -128,9 +129,11 @@ const LoginDialog = () => {
eSendEvent(eStartSyncer);
dispatch({type: Actions.ALL});
eSendEvent(refreshNotesPage);
clearMessage(dispatch);
close();
ToastEvent.show(`Logged in as ${username}`, 'success', 'local');
} catch (e) {
console.warn(e);
ToastEvent.show(e.message, 'error', 'local');
} finally {
setLoggingIn(false);
@@ -192,6 +195,7 @@ const LoginDialog = () => {
setStatus('Setting up crenditials');
dispatch({type: Actions.USER, user: user});
eSendEvent(eStartSyncer);
clearMessage(dispatch);
close();
await sleep(500);
eSendEvent(eOpenRecoveryKeyDialog, true);

View File

@@ -90,7 +90,7 @@ export default class NoteItem extends React.Component {
width: '92%',
paddingRight: 5,
}}>
{item.notebooks && item.notebooks.length > 0 && (
{item.notebooks && item.notebooks.length === 0 && (
<View
style={{
flexDirection: 'row',

View File

@@ -13,4 +13,15 @@ export function setLoginMessage(dispatch) {
data:{},
icon:'account-outline'
}});
}
export function clearMessage(dispatch) {
dispatch({type:Actions.MESSAGE_BOARD_STATE,state:{
visible:false,
message:'',
actionText:"",
onPress: null,
data:{},
icon:'account-outline'
}});
}

View File

@@ -56,8 +56,12 @@ function encrypt(password, data) {
return Sodium.encrypt(password, data).then((result) => result);
}
function decrypt(password, data) {
return Sodium.decrypt(password, data).then((result) => result);
return Sodium.decrypt(password,data).then((result) => {
console.log(result);
return result;
});
}
let CRYPT_CONFIG = Platform.select({
@@ -84,7 +88,7 @@ async function deriveCryptoKey(name, data) {
credentials.key,
CRYPT_CONFIG,
);
console.log(credentials.key)
return credentials.key;
} catch (e) {
console.log(e);

View File

@@ -25,6 +25,7 @@ export const Notebook = ({route, navigation}) => {
useEffect(() => {
onLoad();
}, [route.params]);
useEffect(() => {

View File

@@ -32,6 +32,7 @@ import {
openVault,
ToastEvent,
} from '../../services/EventManager';
import { setLoginMessage } from '../../services/Message';
import Navigation from '../../services/Navigation';
import PremiumService from '../../services/PremiumService';
import SettingsService from '../../services/SettingsService';
@@ -283,6 +284,7 @@ const SettingsUserSection = () => {
dispatch({type: Actions.USER, user: null});
dispatch({type: Actions.CLEAR_ALL});
dispatch({type: Actions.SYNCING, syncing: false});
setLoginMessage(dispatch)
}}
/>
</DialogContainer>