DocSpace-client/packages/common/store/TfaStore.js

75 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-05-05 11:59:08 +00:00
import { makeAutoObservable } from "mobx";
import api from "../api";
2021-05-12 09:10:08 +00:00
import history from "../history";
2021-05-05 11:59:08 +00:00
class TfaStore {
tfaSettings = null;
smsAvailable = null;
appAvailable = null;
backupCodes = [];
tfaAndroidAppUrl =
"https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2";
tfaIosAppUrl = "https://apps.apple.com/app/google-authenticator/id388497605";
tfaWinAppUrl =
"https://www.microsoft.com/ru-ru/p/authenticator/9wzdncrfj3rj?rtc=1&activetab=pivot:overviewtab";
2021-05-05 11:59:08 +00:00
constructor() {
makeAutoObservable(this);
}
2021-05-30 14:26:30 +00:00
getTfaType = async () => {
2021-05-07 11:22:21 +00:00
const res = await api.settings.getTfaSettings();
const sms = res[0].enabled;
const app = res[1].enabled;
2021-05-07 11:32:00 +00:00
const type = sms ? "sms" : app ? "app" : "none";
this.tfaSettings = type;
this.smsAvailable = res[0].avaliable;
this.appAvailable = res[1].avaliable;
2021-05-07 11:32:00 +00:00
return type;
2021-05-07 11:22:21 +00:00
};
2021-05-30 14:26:30 +00:00
getTfaSettings = async () => {
return await api.settings.getTfaSettings();
};
2021-05-05 11:59:08 +00:00
setTfaSettings = async (type) => {
2021-05-19 00:48:13 +00:00
return await api.settings.setTfaSettings(type);
2021-05-07 11:32:00 +00:00
};
setBackupCodes = (codes) => {
this.backupCodes = codes;
};
2022-04-14 09:41:24 +00:00
getTfaConfirmLink = async () => {
return await api.settings.getTfaConfirmLink();
2021-05-05 11:59:08 +00:00
};
2021-05-14 12:58:50 +00:00
getSecretKeyAndQR = async (confirmKey) => {
return api.settings.getTfaSecretKeyAndQR(confirmKey);
};
2021-05-17 14:32:12 +00:00
loginWithCode = async (userName, passwordHash, code) => {
return api.user.loginWithTfaCode(userName, passwordHash, code);
};
loginWithCodeAndCookie = async (code, confirmKey = null) => {
return api.settings.validateTfaCode(code, confirmKey);
};
2021-05-05 11:59:08 +00:00
getBackupCodes = async () => {
2021-05-19 22:44:03 +00:00
return api.settings.getTfaBackupCodes();
};
getNewBackupCodes = async () => {
2021-05-17 14:32:12 +00:00
return api.settings.getTfaNewBackupCodes();
2021-05-05 11:59:08 +00:00
};
2022-03-26 10:03:13 +00:00
unlinkApp = async (id) => {
return api.settings.unlinkTfaApp(id);
};
2021-05-05 11:59:08 +00:00
}
export default TfaStore;