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

73 lines
1.7 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;
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;
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;
};
2021-05-30 14:26:30 +00:00
getTfaConfirmLink = async (res) => {
if (res) {
2021-05-19 00:48:13 +00:00
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) => {
2021-05-30 14:26:30 +00:00
return api.settings.validateTfaCode(code);
};
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
};
2021-05-17 14:32:12 +00:00
unlinkApp = async () => {
2021-05-17 20:28:52 +00:00
return api.settings.unlinkTfaApp();
};
2021-05-05 11:59:08 +00:00
}
export default TfaStore;