Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
ThaliApp
Commits
790a6cf0
Commit
790a6cf0
authored
Feb 22, 2017
by
AuckeBos
Browse files
Async connection with response working
parent
1ae6260c
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/actions/actionTypes.js
View file @
790a6cf0
export
const
LOGIN
=
'
LOGIN
'
;
export
const
NAVIGATE
=
'
NAVIGATE
'
;
export
const
BACK
=
'
BACK
'
;
export
const
LOGINPROGRESS
=
'
LOGINPROGRESS
'
;
export
const
LOGINSUCCESS
=
'
LOGINSUCCESS
'
;
export
const
LOGINFAILURE
=
'
LOGINFAILURE
'
;
app/actions/login.js
View file @
790a6cf0
import
*
as
types
from
'
./actionTypes
'
;
export
function
login
old
(
username
,
password
)
{
export
function
login
Success
(
username
)
{
return
{
type
:
types
.
LOGIN
,
success
:
password
===
'
42
'
,
type
:
types
.
LOGINSUCCESS
,
};
}
export
function
login
(
username
,
password
)
{
return
(
dispatch
)
=>
{
dispatch
(
loginProgress
());
return
fetch
(
'
https://thalia.nu/api/login
'
,
{
method
:
'
POST
'
,
})
...
...
@@ -17,8 +17,29 @@ export function login(username, password) {
.
then
(
(
responseJson
)
=>
{
console
.
log
(
responseJson
);
return
dispatch
(
loginold
(
username
,
password
));
if
(
password
===
'
42
'
){
console
.
log
(
responseJson
);
return
dispatch
(
loginSuccess
(
username
))
}
else
{
return
dispatch
(
loginFailure
());
}
})
.
catch
(
error
=>
console
.
error
(
error
));
.
catch
(
error
=>
{
console
.
error
(
error
);
return
dispatch
(
loginFailure
());
});
};
}
export
function
loginProgress
()
{
return
{
type
:
types
.
LOGINPROGRESS
,
};
}
export
function
loginFailure
(){
return
{
type
:
types
.
LOGINFAILURE
,
};
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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