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;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
makeAutoObservable(this);
|
|
|
|
}
|
|
|
|
|
2021-05-07 11:22:21 +00:00
|
|
|
getTfaSettings = async () => {
|
|
|
|
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-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
|
|
|
};
|
|
|
|
|
|
|
|
getTfaConfirmLink = async (res, type) => {
|
2021-05-05 11:59:08 +00:00
|
|
|
if (res && type !== "none") {
|
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);
|
|
|
|
};
|
|
|
|
|
2021-05-19 15:21:40 +00:00
|
|
|
loginWithCodeAndCookie = async (code) => {
|
|
|
|
return api.settings.loginWithTfaCodeAndCookie(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 13:32:40 +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-17 13:32:40 +00:00
|
|
|
};
|
2021-05-05 11:59:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default TfaStore;
|