logo

pleroma-fe

My custom branche(s) on git.pleroma.social/pleroma/pleroma-fe git clone https://anongit.hacktivis.me/git/pleroma-fe.git/

auth_flow.js (1894B)


  1. const PASSWORD_STRATEGY = 'password'
  2. const TOKEN_STRATEGY = 'token'
  3. // MFA strategies
  4. const TOTP_STRATEGY = 'totp'
  5. const RECOVERY_STRATEGY = 'recovery'
  6. // initial state
  7. const state = {
  8. settings: {},
  9. strategy: PASSWORD_STRATEGY,
  10. initStrategy: PASSWORD_STRATEGY // default strategy from config
  11. }
  12. const resetState = (state) => {
  13. state.strategy = state.initStrategy
  14. state.settings = {}
  15. }
  16. // getters
  17. const getters = {
  18. settings: (state, getters) => {
  19. return state.settings
  20. },
  21. requiredPassword: (state, getters, rootState) => {
  22. return state.strategy === PASSWORD_STRATEGY
  23. },
  24. requiredToken: (state, getters, rootState) => {
  25. return state.strategy === TOKEN_STRATEGY
  26. },
  27. requiredTOTP: (state, getters, rootState) => {
  28. return state.strategy === TOTP_STRATEGY
  29. },
  30. requiredRecovery: (state, getters, rootState) => {
  31. return state.strategy === RECOVERY_STRATEGY
  32. }
  33. }
  34. // mutations
  35. const mutations = {
  36. setInitialStrategy (state, strategy) {
  37. if (strategy) {
  38. state.initStrategy = strategy
  39. state.strategy = strategy
  40. }
  41. },
  42. requirePassword (state) {
  43. state.strategy = PASSWORD_STRATEGY
  44. },
  45. requireToken (state) {
  46. state.strategy = TOKEN_STRATEGY
  47. },
  48. requireMFA (state, { settings }) {
  49. state.settings = settings
  50. state.strategy = TOTP_STRATEGY // default strategy of MFA
  51. },
  52. requireRecovery (state) {
  53. state.strategy = RECOVERY_STRATEGY
  54. },
  55. requireTOTP (state) {
  56. state.strategy = TOTP_STRATEGY
  57. },
  58. abortMFA (state) {
  59. resetState(state)
  60. }
  61. }
  62. // actions
  63. const actions = {
  64. // eslint-disable-next-line camelcase
  65. async login ({ state, dispatch, commit }, { access_token }) {
  66. commit('setToken', access_token, { root: true })
  67. await dispatch('loginUser', access_token, { root: true })
  68. resetState(state)
  69. }
  70. }
  71. export default {
  72. namespaced: true,
  73. state,
  74. getters,
  75. mutations,
  76. actions
  77. }