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;
|
2022-04-05 11:40:45 +00:00
|
|
|
smsAvailable = null;
|
|
|
|
appAvailable = null;
|
2021-06-08 11:19:36 +00:00
|
|
|
backupCodes = [];
|
2021-05-20 03:37:56 +00:00
|
|
|
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;
|
2022-04-05 11:40:45 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
2021-06-08 11:19:36 +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);
|
|
|
|
};
|
|
|
|
|
2021-05-19 15:21:40 +00:00
|
|
|
loginWithCodeAndCookie = async (code) => {
|
2021-05-30 14:26:30 +00:00
|
|
|
return api.settings.validateTfaCode(code);
|
2021-05-19 15:21:40 +00:00
|
|
|
};
|
|
|
|
|
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 13:32:40 +00:00
|
|
|
|
2022-03-26 10:03:13 +00:00
|
|
|
unlinkApp = async (id) => {
|
|
|
|
return api.settings.unlinkTfaApp(id);
|
2021-05-17 13:32:40 +00:00
|
|
|
};
|
2021-05-05 11:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default TfaStore;
|