aboutsummaryrefslogtreecommitdiff
path: root/src/modules/auth_flow.js
diff options
context:
space:
mode:
authorShpuld Shpludson <shp@cock.li>2020-01-15 16:35:13 +0000
committerShpuld Shpludson <shp@cock.li>2020-01-15 16:35:13 +0000
commit3ab128e73924ce34d190ff609cb9b081cdffe402 (patch)
treebba013a7d61688b90c1f59a8f9fa6c3323b72a05 /src/modules/auth_flow.js
parent7c26435e66fd7e142ea4b88fbe51eede32eeb5ce (diff)
parent7397636914a9d3e7fd30373034c25175273ab808 (diff)
Merge branch 'develop' into 'master'
`master` refresh with `develop` See merge request pleroma/pleroma-fe!1028
Diffstat (limited to 'src/modules/auth_flow.js')
-rw-r--r--src/modules/auth_flow.js84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/modules/auth_flow.js b/src/modules/auth_flow.js
new file mode 100644
index 00000000..956d40e8
--- /dev/null
+++ b/src/modules/auth_flow.js
@@ -0,0 +1,84 @@
+const PASSWORD_STRATEGY = 'password'
+const TOKEN_STRATEGY = 'token'
+
+// MFA strategies
+const TOTP_STRATEGY = 'totp'
+const RECOVERY_STRATEGY = 'recovery'
+
+// initial state
+const state = {
+ settings: {},
+ strategy: PASSWORD_STRATEGY,
+ initStrategy: PASSWORD_STRATEGY // default strategy from config
+}
+
+const resetState = (state) => {
+ state.strategy = state.initStrategy
+ state.settings = {}
+}
+
+// getters
+const getters = {
+ settings: (state, getters) => {
+ return state.settings
+ },
+ requiredPassword: (state, getters, rootState) => {
+ return state.strategy === PASSWORD_STRATEGY
+ },
+ requiredToken: (state, getters, rootState) => {
+ return state.strategy === TOKEN_STRATEGY
+ },
+ requiredTOTP: (state, getters, rootState) => {
+ return state.strategy === TOTP_STRATEGY
+ },
+ requiredRecovery: (state, getters, rootState) => {
+ return state.strategy === RECOVERY_STRATEGY
+ }
+}
+
+// mutations
+const mutations = {
+ setInitialStrategy (state, strategy) {
+ if (strategy) {
+ state.initStrategy = strategy
+ state.strategy = strategy
+ }
+ },
+ requirePassword (state) {
+ state.strategy = PASSWORD_STRATEGY
+ },
+ requireToken (state) {
+ state.strategy = TOKEN_STRATEGY
+ },
+ requireMFA (state, { settings }) {
+ state.settings = settings
+ state.strategy = TOTP_STRATEGY // default strategy of MFA
+ },
+ requireRecovery (state) {
+ state.strategy = RECOVERY_STRATEGY
+ },
+ requireTOTP (state) {
+ state.strategy = TOTP_STRATEGY
+ },
+ abortMFA (state) {
+ resetState(state)
+ }
+}
+
+// actions
+const actions = {
+ // eslint-disable-next-line camelcase
+ async login ({ state, dispatch, commit }, { access_token }) {
+ commit('setToken', access_token, { root: true })
+ await dispatch('loginUser', access_token, { root: true })
+ resetState(state)
+ }
+}
+
+export default {
+ namespaced: true,
+ state,
+ getters,
+ mutations,
+ actions
+}