Browse Source

[wip] connection to login api

Skylsmoi 6 years ago
parent
commit
81080790aa
4 changed files with 25 additions and 22 deletions
  1. 18 16
      src/action-creator.async.js
  2. 2 2
      src/container/Login.jsx
  3. 2 2
      src/container/Tracim.jsx
  4. 3 2
      src/helper.js

+ 18 - 16
src/action-creator.async.js View File

70
 
70
 
71
 export const getLangList = () => async dispatch => {
71
 export const getLangList = () => async dispatch => {
72
   const fetchGetLangList = await fetchWrapper({
72
   const fetchGetLangList = await fetchWrapper({
73
-    url: `${FETCH_CONFIG.apiUrl}/lang`,
73
+    url: `${FETCH_CONFIG.mockApiUrl}/lang`,
74
     param: {...FETCH_CONFIG.header, method: 'GET'},
74
     param: {...FETCH_CONFIG.header, method: 'GET'},
75
     actionName: LANG,
75
     actionName: LANG,
76
     dispatch
76
     dispatch
80
 
80
 
81
 export const getTimezone = () => async dispatch => {
81
 export const getTimezone = () => async dispatch => {
82
   const fetchGetTimezone = await fetchWrapper({
82
   const fetchGetTimezone = await fetchWrapper({
83
-    url: `${FETCH_CONFIG.apiUrl}/timezone`,
83
+    url: `${FETCH_CONFIG.mockApiUrl}/timezone`,
84
     param: {...FETCH_CONFIG.header, method: 'GET'},
84
     param: {...FETCH_CONFIG.header, method: 'GET'},
85
     actionName: TIMEZONE,
85
     actionName: TIMEZONE,
86
     dispatch
86
     dispatch
88
   if (fetchGetTimezone.status === 200) dispatch(setTimezone(fetchGetTimezone.json))
88
   if (fetchGetTimezone.status === 200) dispatch(setTimezone(fetchGetTimezone.json))
89
 }
89
 }
90
 
90
 
91
-export const userLogin = (login, password, rememberMe) => async dispatch => {
91
+export const postUserLogin = (login, password, rememberMe) => async dispatch => {
92
   const fetchUserLogin = await fetchWrapper({
92
   const fetchUserLogin = await fetchWrapper({
93
-    url: `${FETCH_CONFIG.apiUrl}/user/login`,
93
+    url: `${FETCH_CONFIG.apiUrl}/sessions/login`,
94
     param: {
94
     param: {
95
-      ...FETCH_CONFIG.header,
95
+      headers: {...FETCH_CONFIG.headers},
96
       method: 'POST',
96
       method: 'POST',
97
       body: JSON.stringify({
97
       body: JSON.stringify({
98
-        login,
99
-        password,
100
-        remember_me: rememberMe
98
+        email: login,
99
+        password: password
100
+        // remember_me: rememberMe
101
       })
101
       })
102
     },
102
     },
103
     actionName: USER_LOGIN,
103
     actionName: USER_LOGIN,
106
   if (fetchUserLogin.status === 200) dispatch(setUserConnected(fetchUserLogin.json))
106
   if (fetchUserLogin.status === 200) dispatch(setUserConnected(fetchUserLogin.json))
107
 }
107
 }
108
 
108
 
109
-export const getIsUserConnected = () => async dispatch => {
109
+export const getUserIsConnected = () => async dispatch => {
110
   const fetchUserLogged = await fetchWrapper({
110
   const fetchUserLogged = await fetchWrapper({
111
-    url: `${FETCH_CONFIG.apiUrl}/user/is_logged_in`,
111
+    url: `${FETCH_CONFIG.apiUrl}/sessions/whoami`,
112
     param: {...FETCH_CONFIG.header, method: 'GET'},
112
     param: {...FETCH_CONFIG.header, method: 'GET'},
113
     actionName: USER_CONNECTED,
113
     actionName: USER_CONNECTED,
114
     dispatch
114
     dispatch
115
   })
115
   })
116
   if (fetchUserLogged.status === 200) dispatch(setUserConnected(fetchUserLogged.json))
116
   if (fetchUserLogged.status === 200) dispatch(setUserConnected(fetchUserLogged.json))
117
+  else if (fetchUserLogged.status === 401) dispatch(setUserConnected({logged: false}))
118
+  else dispatch(setUserConnected({logged: undefined}))
117
 }
119
 }
118
 
120
 
119
 export const getUserRole = user => async dispatch => {
121
 export const getUserRole = user => async dispatch => {
120
   const fetchGetUserRole = await fetchWrapper({
122
   const fetchGetUserRole = await fetchWrapper({
121
-    url: `${FETCH_CONFIG.apiUrl}/user/${user.id}/roles`,
123
+    url: `${FETCH_CONFIG.mockApiUrl}/user/${user.id}/roles`,
122
     param: {...FETCH_CONFIG.header, method: 'GET'},
124
     param: {...FETCH_CONFIG.header, method: 'GET'},
123
     actionName: USER_ROLE,
125
     actionName: USER_ROLE,
124
     dispatch
126
     dispatch
128
 
130
 
129
 export const updateUserLang = newLang => async dispatch => { // unused
131
 export const updateUserLang = newLang => async dispatch => { // unused
130
   const fetchUpdateUserLang = await fetchWrapper({
132
   const fetchUpdateUserLang = await fetchWrapper({
131
-    url: `${FETCH_CONFIG.apiUrl}/user`,
133
+    url: `${FETCH_CONFIG.mockApiUrl}/user`,
132
     param: {...FETCH_CONFIG.header, method: 'PATCH', body: JSON.stringify({lang: newLang})},
134
     param: {...FETCH_CONFIG.header, method: 'PATCH', body: JSON.stringify({lang: newLang})},
133
     actionName: USER_DATA,
135
     actionName: USER_DATA,
134
     dispatch
136
     dispatch
148
 
150
 
149
 export const getWorkspaceList = (userId, workspaceIdToOpen) => async dispatch => {
151
 export const getWorkspaceList = (userId, workspaceIdToOpen) => async dispatch => {
150
   const fetchGetWorkspaceList = await fetchWrapper({
152
   const fetchGetWorkspaceList = await fetchWrapper({
151
-    url: `${FETCH_CONFIG.apiUrl}/user/${userId}/workspace`,
153
+    url: `${FETCH_CONFIG.mockApiUrl}/user/${userId}/workspace`,
152
     param: {...FETCH_CONFIG.header, method: 'GET'},
154
     param: {...FETCH_CONFIG.header, method: 'GET'},
153
     actionName: WORKSPACE_LIST,
155
     actionName: WORKSPACE_LIST,
154
     dispatch
156
     dispatch
161
 
163
 
162
 export const getWorkspaceContent = (workspaceId, filterStr) => async dispatch => {
164
 export const getWorkspaceContent = (workspaceId, filterStr) => async dispatch => {
163
   const fetchGetWorkspaceContent = await fetchWrapper({
165
   const fetchGetWorkspaceContent = await fetchWrapper({
164
-    url: `${FETCH_CONFIG.apiUrl}/workspace/${workspaceId}`,
166
+    url: `${FETCH_CONFIG.mockApiUrl}/workspace/${workspaceId}`,
165
     param: {...FETCH_CONFIG.header, method: 'GET'},
167
     param: {...FETCH_CONFIG.header, method: 'GET'},
166
     actionName: WORKSPACE,
168
     actionName: WORKSPACE,
167
     dispatch
169
     dispatch
171
 
173
 
172
 export const getFolderContent = (workspaceId, folderId) => async dispatch => {
174
 export const getFolderContent = (workspaceId, folderId) => async dispatch => {
173
   const fetchGetFolderContent = await fetchWrapper({
175
   const fetchGetFolderContent = await fetchWrapper({
174
-    url: `${FETCH_CONFIG.apiUrl}/workspace/${workspaceId}/folder/${folderId}`,
176
+    url: `${FETCH_CONFIG.mockApiUrl}/workspace/${workspaceId}/folder/${folderId}`,
175
     param: {...FETCH_CONFIG.header, method: 'GET'},
177
     param: {...FETCH_CONFIG.header, method: 'GET'},
176
     actionName: `${WORKSPACE}/${FOLDER}`,
178
     actionName: `${WORKSPACE}/${FOLDER}`,
177
     dispatch
179
     dispatch
181
 
183
 
182
 export const getAppList = () => async dispatch => {
184
 export const getAppList = () => async dispatch => {
183
   const fetchGetAppList = await fetchWrapper({
185
   const fetchGetAppList = await fetchWrapper({
184
-    url: `${FETCH_CONFIG.apiUrl}/app/config`,
186
+    url: `${FETCH_CONFIG.mockApiUrl}/app/config`,
185
     param: {...FETCH_CONFIG.header, method: 'GET'},
187
     param: {...FETCH_CONFIG.header, method: 'GET'},
186
     actionName: APP_LIST,
188
     actionName: APP_LIST,
187
     dispatch
189
     dispatch

+ 2 - 2
src/container/Login.jsx View File

3
 import { Redirect } from 'react-router'
3
 import { Redirect } from 'react-router'
4
 import LoginLogo from '../component/Login/LoginLogo.jsx'
4
 import LoginLogo from '../component/Login/LoginLogo.jsx'
5
 import LoginLogoImg from '../img/logoTracimWhite.svg'
5
 import LoginLogoImg from '../img/logoTracimWhite.svg'
6
-import { userLogin } from '../action-creator.async.js'
6
+import { postUserLogin } from '../action-creator.async.js'
7
 import Card from '../component/common/Card/Card.jsx'
7
 import Card from '../component/common/Card/Card.jsx'
8
 import CardHeader from '../component/common/Card/CardHeader.jsx'
8
 import CardHeader from '../component/common/Card/CardHeader.jsx'
9
 import CardBody from '../component/common/Card/CardBody.jsx'
9
 import CardBody from '../component/common/Card/CardBody.jsx'
30
     const { history, dispatch } = this.props
30
     const { history, dispatch } = this.props
31
     const { inputLogin, inputPassword, inputRememberMe } = this.state
31
     const { inputLogin, inputPassword, inputRememberMe } = this.state
32
 
32
 
33
-    await dispatch(userLogin(inputLogin, inputPassword, inputRememberMe))
33
+    await dispatch(postUserLogin(inputLogin, inputPassword, inputRememberMe))
34
     history.push('/')
34
     history.push('/')
35
   }
35
   }
36
 
36
 

+ 2 - 2
src/container/Tracim.jsx View File

15
 import { PAGE_NAME } from '../helper.js'
15
 import { PAGE_NAME } from '../helper.js'
16
 import {
16
 import {
17
   getLangList,
17
   getLangList,
18
-  getIsUserConnected
18
+  getUserIsConnected
19
 } from '../action-creator.async.js'
19
 } from '../action-creator.async.js'
20
 
20
 
21
 class Tracim extends React.Component {
21
 class Tracim extends React.Component {
22
   componentDidMount () {
22
   componentDidMount () {
23
-    this.props.dispatch(getIsUserConnected())
23
+    this.props.dispatch(getUserIsConnected())
24
     this.props.dispatch(getLangList())
24
     this.props.dispatch(getLangList())
25
   }
25
   }
26
 
26
 

+ 3 - 2
src/helper.js View File

1
 export const FETCH_CONFIG = {
1
 export const FETCH_CONFIG = {
2
-  header: {
2
+  headers: {
3
     'Accept': 'application/json',
3
     'Accept': 'application/json',
4
     'Content-Type': 'application/json'
4
     'Content-Type': 'application/json'
5
   },
5
   },
6
-  apiUrl: 'http://localhost:3001'
6
+  apiUrl: 'http://localhost:6543/api/v2',
7
+  mockApiUrl: 'http://localhost:3001'
7
 }
8
 }
8
 
9
 
9
 export const PAGE_NAME = {
10
 export const PAGE_NAME = {