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
fef668c3
Commit
fef668c3
authored
Feb 22, 2017
by
AuckeBos
Browse files
Login checks working at login screen
parent
790a6cf0
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/actions/login.js
View file @
fef668c3
import
*
as
types
from
'
./actionTypes
'
;
const
apiKey
=
'
AiYinaeng4juw1cae1eiLe2Adei2Ahbahda3AiRu
'
;
export
function
loginSuccess
(
username
)
{
return
{
type
:
types
.
LOGINSUCCESS
,
...
...
@@ -9,23 +11,31 @@ export function loginSuccess(username) {
export
function
login
(
username
,
password
)
{
return
(
dispatch
)
=>
{
dispatch
(
loginProgress
());
return
fetch
(
'
https://thalia.nu/api/login
'
,
{
data
=
{
method
:
'
POST
'
,
})
headers
:
{
Accept
:
'
application/json
'
,
'
Content-Type
'
:
'
application/json
'
,
},
body
:
JSON
.
stringify
({
apikey
:
apiKey
,
username
,
password
,
}),
};
return
fetch
(
'
http://localhost:8000/api/login
'
,
data
)
.
then
(
response
=>
response
.
json
())
.
then
(
(
responseJson
)
=>
{
console
.
log
(
responseJson
);
if
(
password
===
'
42
'
){
if
(
responseJson
.
status
===
'
ok
'
)
{
console
.
log
(
responseJson
);
return
dispatch
(
loginSuccess
(
username
))
}
else
{
return
dispatch
(
loginFailure
());
return
dispatch
(
loginSuccess
(
username
));
}
return
dispatch
(
loginFailure
());
})
.
catch
(
error
=>
{
.
catch
(
(
error
)
=>
{
console
.
error
(
error
);
return
dispatch
(
loginFailure
());
});
...
...
@@ -38,8 +48,8 @@ export function loginProgress() {
};
}
export
function
loginFailure
(){
return
{
export
function
loginFailure
()
{
return
{
type
:
types
.
LOGINFAILURE
,
};
}
app/components/Login.js
View file @
fef668c3
...
...
@@ -14,7 +14,7 @@ class Login extends Component {
}
render
()
{
const
{
loginError
,
login
}
=
this
.
props
;
const
{
loginError
,
login
,
loginProgress
,
loggedIn
}
=
this
.
props
;
return
(
<
View
>
<
TextInput
...
...
@@ -27,7 +27,7 @@ class Login extends Component {
onChangeText
=
{
password
=>
this
.
setState
({
password
})}
/
>
<
Button
title
=
"
Log in
"
onPress
=
{()
=>
login
(
this
.
state
.
username
,
this
.
state
.
password
)}
/
>
<
Text
>
{
loginError
?
'
Login fa
al
'
:
''
}
<
/Text
>
<
Text
>
{
loggedIn
?
'
Logged in
'
:
(
loginProgress
?
'
Logging in
'
:
(
loginError
?
'
Log
g
in fa
iled
'
:
''
))
}
<
/Text
>
<
/View
>
);
}
...
...
app/reducers/login.js
View file @
fef668c3
...
...
@@ -3,15 +3,18 @@ import * as types from '../actions/actionTypes';
const
initialState
=
{
loggedIn
:
false
,
loginError
:
false
,
loginProgress
:
false
,
};
export
default
function
login
(
state
=
initialState
,
action
=
{})
{
switch
(
action
.
type
)
{
case
types
.
LOGIN
:
if
(
action
.
success
)
{
return
{
...
state
,
loginError
:
false
,
loggedIn
:
true
};
}
return
{
...
state
,
loginError
:
true
};
case
types
.
LOGINSUCCESS
:
return
{
...
state
,
loginProgress
:
false
,
loginError
:
false
,
loggedIn
:
true
};
break
;
case
types
.
LOGINFAILURE
:
return
{
...
state
,
loginProgress
:
false
,
loginError
:
true
,
loggedIn
:
false
};
case
types
.
LOGINPROGRESS
:
return
{
...
state
,
loginProgress
:
true
,
logginError
:
false
,
loggedIn
:
false
};
default
:
return
{
...
state
};
}
...
...
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