Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
warehouse-management
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ascend
warehouse-management
Commits
c66ccc1a
Commit
c66ccc1a
authored
May 08, 2021
by
Darrick Yong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add session connection to frontend
parent
3c12209b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
24 deletions
+23
-24
session_actions.js
frontend/src/actions/session_actions.js
+14
-12
session_api_util.jsx
frontend/src/util/session_api_util.jsx
+4
-8
SessionController.java
...finalproject/warehouse/controllers/SessionController.java
+2
-2
SessionService.java
...ascendfinalproject/warehouse/services/SessionService.java
+3
-2
No files found.
frontend/src/actions/session_actions.js
View file @
c66ccc1a
import
*
as
SessionAPIUtil
from
"../util/session_api_util"
;
export
const
LOGIN_USER
=
'LOGIN_USER'
;
export
const
LOGOUT_USER
=
'LOGOUT_USER'
;
export
const
LOGIN_USER
=
"LOGIN_USER"
;
export
const
LOGOUT_USER
=
"LOGOUT_USER"
;
const
receiveLogin
=
(
user
)
=>
({
type
:
LOGIN_USER
,
user
,
})
})
;
const
receiveLogout
=
()
=>
({
type
:
LOGOUT_USER
,
})
})
;
export
const
login
=
payload
=>
dispatch
=>
{
SessionAPIUtil
.
createSession
(
payload
)
.
then
(
res
=>
{
dispatch
(
receiveLogin
(
res
))
})
}
export
const
login
=
(
payload
)
=>
(
dispatch
)
=>
{
SessionAPIUtil
.
createSession
(
payload
).
then
((
res
)
=>
{
const
{
status
,
data
}
=
res
;
if
(
status
<
299
)
{
dispatch
(
receiveLogin
(
data
));
}
});
};
export
const
logout
=
()
=>
dispatch
=>
{
export
const
logout
=
()
=>
(
dispatch
)
=>
{
dispatch
(
receiveLogout
());
}
}
;
frontend/src/util/session_api_util.jsx
View file @
c66ccc1a
// import axios from 'axios'
;
import
axios
from
"axios"
;
export
const
createSession
=
(
payload
)
=>
{
const
{
token
,
user
}
=
payload
;
// call axios with token
return
new
Promise
((
resolve
,
reject
)
=>
{
resolve
(
user
);
})
return
axios
.
post
(
"http://localhost:8080/api/auth"
,
payload
)
.
catch
((
err
)
=>
err
.
response
);
};
src/main/java/com/ascendfinalproject/warehouse/controllers/
Authenticat
ionController.java
→
src/main/java/com/ascendfinalproject/warehouse/controllers/
Sess
ionController.java
View file @
c66ccc1a
...
...
@@ -7,8 +7,8 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.web.bind.annotation.*
;
@RestController
@RequestMapping
(
value
=
""
)
public
class
Authenticat
ionController
{
@RequestMapping
(
value
=
"
/api
"
)
public
class
Sess
ionController
{
@Autowired
SessionService
sessionService
;
...
...
src/main/java/com/ascendfinalproject/warehouse/services/SessionService.java
View file @
c66ccc1a
...
...
@@ -7,6 +7,7 @@ import org.springframework.stereotype.Service;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.Scanner
;
@Service
public
class
SessionService
{
...
...
@@ -29,8 +30,8 @@ public class SessionService {
.
body
(
session
);
}
return
ResponseEntity
.
status
(
HttpStatus
.
BAD_REQUEST
)
.
body
(
null
);
.
status
(
HttpStatus
.
UNAUTHORIZED
)
.
body
(
session
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment