Guest User

Untitled

a guest
Feb 10th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import axios from "axios";
  2.  
  3. import router from "../../router";
  4.  
  5. const state = {
  6. authenticated: false,
  7. auth: {},
  8. loggedin_siteid: null,
  9. login_inprogress: false
  10. };
  11. const getters = {
  12. authenticated: state => {
  13. return state.authenticated;
  14. }
  15. };
  16.  
  17. const mutations = {
  18. initializeAuth(state, auth_obj) {
  19. state.auth = auth_obj;
  20. state.authenticated = true;
  21. router.push({ name: "main" });
  22. },
  23. updateLoggedInSite(state, siteid) {
  24. state.siteid = siteid;
  25. },
  26. loginStart(state) {
  27. state.login_inprogress = true;
  28. },
  29. loginFinish(state) {
  30. state.login_inprogress = false;
  31. }
  32. };
  33.  
  34. const actions = {
  35. authenticate({ commit }, login_obj) {
  36. commit("loginStart");
  37. axios
  38. .get("/authenticate", {
  39. params: {
  40. username: login_obj.username,
  41. password: login_obj.password,
  42. siteid: login_obj.siteid,
  43. flex: "true"
  44. }
  45. })
  46. .then(({ data: { response: response } }) => {
  47. commit("loginFinish");
  48. const errors = response.errors;
  49. if (errors) {
  50. console.log(errors);
  51. } else {
  52. commit("initializeAuth", response.results[0]);
  53. commit("updateLoggedInSite", login_obj.siteid);
  54. }
  55. });
  56. }
  57. };
  58.  
  59. export default {
  60. state,
  61. mutations,
  62. actions,
  63. getters
  64. };
Add Comment
Please, Sign In to add comment