mirror of
https://github.com/ecency/ecency-mobile.git
synced 2024-12-22 21:01:31 +03:00
Changed setUserDataWithPinCode function with new structure
This commit is contained in:
parent
980ea94d0f
commit
b60aa8be4a
@ -9,6 +9,7 @@ import {
|
|||||||
getUserData,
|
getUserData,
|
||||||
setSCAccount,
|
setSCAccount,
|
||||||
getSCAccount,
|
getSCAccount,
|
||||||
|
setPinCode,
|
||||||
} from '../../realm/realm';
|
} from '../../realm/realm';
|
||||||
import { encryptKey, decryptKey } from '../../utils/crypto';
|
import { encryptKey, decryptKey } from '../../utils/crypto';
|
||||||
import steemConnect from './steemConnectAPI';
|
import steemConnect from './steemConnectAPI';
|
||||||
@ -128,30 +129,30 @@ export const loginWithSC2 = async (code) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const setUserDataWithPinCode = async (data) => {
|
export const setUserDataWithPinCode = async (data) => {
|
||||||
const result = getUserDataWithUsername(data.username);
|
try {
|
||||||
const userData = result[0];
|
const result = getUserDataWithUsername(data.username);
|
||||||
|
const userData = result[0];
|
||||||
|
|
||||||
const privateKeys = getPrivateKeys(userData.username, data.password);
|
const privateKeys = getPrivateKeys(userData.username, data.password);
|
||||||
|
|
||||||
const updatedUserData = {
|
const updatedUserData = {
|
||||||
username: userData.username,
|
username: userData.username,
|
||||||
authType: userData.authType,
|
authType: userData.authType,
|
||||||
accessToken:
|
accessToken:
|
||||||
userData.authType === 'steemConnect' ? encryptKey(data.accessToken, data.pinCode) : '',
|
userData.authType === 'steemConnect' ? encryptKey(data.accessToken, data.pinCode) : '',
|
||||||
masterKey: userData.authType === 'masterKey' ? encryptKey(data.password, data.pinCode) : '',
|
masterKey: userData.authType === 'masterKey' ? encryptKey(data.password, data.pinCode) : '',
|
||||||
postingKey: encryptKey(privateKeys.posting.toString(), data.pinCode),
|
postingKey: encryptKey(privateKeys.posting.toString(), data.pinCode),
|
||||||
activeKey: encryptKey(privateKeys.active.toString(), data.pinCode),
|
activeKey: encryptKey(privateKeys.active.toString(), data.pinCode),
|
||||||
memoKey: encryptKey(privateKeys.memo.toString(), data.pinCode),
|
memoKey: encryptKey(privateKeys.memo.toString(), data.pinCode),
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await updateUserData(updatedUserData);
|
await setPinCode(data.pinCode);
|
||||||
const authData = {
|
await updateUserData(updatedUserData);
|
||||||
isLoggedIn: true,
|
|
||||||
currentUsername: userData.username,
|
|
||||||
};
|
|
||||||
|
|
||||||
await setAuthStatus(authData);
|
return updatedUserData;
|
||||||
return response;
|
} catch (error) {
|
||||||
|
return Promise.reject(new Error('Unknown error, please contact to eSteem.'));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updatePinCode = async (data) => {
|
export const updatePinCode = async (data) => {
|
||||||
@ -209,9 +210,7 @@ export const verifyPinCode = async (data) => {
|
|||||||
const newSCAccountData = await getSCAccessToken(scAccount.refreshToken);
|
const newSCAccountData = await getSCAccessToken(scAccount.refreshToken);
|
||||||
await setSCAccount(newSCAccountData);
|
await setSCAccount(newSCAccountData);
|
||||||
accessToken = newSCAccountData.access_token;
|
accessToken = newSCAccountData.access_token;
|
||||||
await updateUserData(
|
await updateUserData({ ...userData, accessToken: encryptKey(accessToken, data.pinCode) });
|
||||||
{ ...userData, accessToken: encryptKey(accessToken, data.pinCode) },
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
await steemConnect.setAccessToken(accessToken);
|
await steemConnect.setAccessToken(accessToken);
|
||||||
account = await steemConnect.me();
|
account = await steemConnect.me();
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import Realm from 'realm';
|
import Realm from 'realm';
|
||||||
|
import sha256 from 'crypto-js/sha256';
|
||||||
|
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
const USER_SCHEMA = 'user';
|
const USER_SCHEMA = 'user';
|
||||||
@ -294,9 +295,10 @@ export const updateCurrentUsername = username => new Promise((resolve, reject) =
|
|||||||
export const setPinCode = pinCode => new Promise((resolve, reject) => {
|
export const setPinCode = pinCode => new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const auth = realm.objects(AUTH_SCHEMA);
|
const auth = realm.objects(AUTH_SCHEMA);
|
||||||
|
const pinHash = sha256(pinCode);
|
||||||
|
|
||||||
realm.write(() => {
|
realm.write(() => {
|
||||||
auth[0].pinCode = pinCode;
|
auth[0].pinCode = pinHash;
|
||||||
resolve(auth[0]);
|
resolve(auth[0]);
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user