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
6cc55921
Commit
6cc55921
authored
Mar 01, 2017
by
AuckeBos
Browse files
login fixed
parent
fef668c3
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/actions/login.js
View file @
6cc55921
...
...
@@ -2,16 +2,33 @@ import * as types from './actionTypes';
const
apiKey
=
'
AiYinaeng4juw1cae1eiLe2Adei2Ahbahda3AiRu
'
;
export
function
loginSuccess
(
username
)
{
export
function
loginSuccess
(
username
,
token
)
{
return
{
type
:
types
.
LOGINSUCCESS
,
loginState
:
'
loggedIn
'
,
username
,
token
,
};
}
export
function
loginProgress
()
{
return
{
type
:
types
.
LOGINPROGRESS
,
loginState
:
'
progress
'
,
};
}
export
function
loginFailure
()
{
return
{
type
:
types
.
LOGINFAILURE
,
loginState
:
'
failure
'
,
};
}
export
function
login
(
username
,
password
)
{
return
(
dispatch
)
=>
{
dispatch
(
loginProgress
());
data
=
{
const
data
=
{
method
:
'
POST
'
,
headers
:
{
Accept
:
'
application/json
'
,
...
...
@@ -29,27 +46,10 @@ export function login(username, password) {
.
then
(
(
responseJson
)
=>
{
if
(
responseJson
.
status
===
'
ok
'
)
{
console
.
log
(
responseJson
);
return
dispatch
(
loginSuccess
(
username
));
return
dispatch
(
loginSuccess
(
username
,
responseJson
.
token
));
}
return
dispatch
(
loginFailure
());
})
.
catch
((
error
)
=>
{
console
.
error
(
error
);
return
dispatch
(
loginFailure
());
});
};
}
export
function
loginProgress
()
{
return
{
type
:
types
.
LOGINPROGRESS
,
};
}
export
function
loginFailure
()
{
return
{
type
:
types
.
LOGINFAILURE
,
.
catch
(()
=>
dispatch
(
loginFailure
()));
};
}
app/components/Login.js
View file @
6cc55921
...
...
@@ -4,6 +4,17 @@ import { connect } from 'react-redux';
import
*
as
actions
from
'
../actions/login
'
;
const
loginResult
=
(
status
)
=>
{
switch
(
status
)
{
case
'
progress
'
:
return
'
Logging in
'
;
case
'
failure
'
:
return
'
Login failed
'
;
default
:
return
''
;
}
};
class
Login
extends
Component
{
constructor
(
props
)
{
super
(
props
);
...
...
@@ -14,12 +25,12 @@ class Login extends Component {
}
render
()
{
const
{
login
Error
,
login
,
loginProgress
,
loggedI
n
}
=
this
.
props
;
const
{
login
State
,
logi
n
}
=
this
.
props
;
return
(
<
View
>
<
TextInput
placeholder
=
"
Username
"
onChangeText
=
{
user
name
=>
this
.
setState
({
user
name
})}
onChangeText
=
{
name
=>
this
.
setState
({
name
})}
/
>
<
TextInput
placeholder
=
"
Password
"
...
...
@@ -27,15 +38,15 @@ class Login extends Component {
onChangeText
=
{
password
=>
this
.
setState
({
password
})}
/
>
<
Button
title
=
"
Log in
"
onPress
=
{()
=>
login
(
this
.
state
.
username
,
this
.
state
.
password
)}
/
>
<
Text
>
{
log
gedIn
?
'
Logged in
'
:
(
loginProgress
?
'
Logging in
'
:
(
loginError
?
'
Loggin failed
'
:
''
))
}
<
/Text
>
<
Text
>
{
log
inResult
(
loginState
)
}
<
/Text
>
<
/View
>
);
}
}
Login
.
propTypes
=
{
loginState
:
React
.
PropTypes
.
string
.
isRequired
,
login
:
React
.
PropTypes
.
func
.
isRequired
,
loginError
:
React
.
PropTypes
.
bool
.
isRequired
,
};
const
mapStateToProps
=
state
=>
state
.
login
;
...
...
app/reducers/login.js
View file @
6cc55921
import
*
as
types
from
'
../actions/actionTypes
'
;
const
initialState
=
{
log
gedIn
:
false
,
loginError
:
false
,
loginProgress
:
false
,
log
inState
:
''
,
token
:
''
,
username
:
''
,
};
export
default
function
login
(
state
=
initialState
,
action
=
{})
{
switch
(
action
.
type
)
{
case
types
.
LOGINSUCCESS
:
return
{
...
state
,
loginProgress
:
false
,
loginError
:
false
,
loggedIn
:
true
};
break
;
return
{
...
state
,
loginState
:
'
success
'
,
username
:
action
.
username
,
token
:
action
.
token
};
case
types
.
LOGINFAILURE
:
return
{
...
state
,
login
Progress
:
false
,
loginError
:
true
,
loggedIn
:
fa
lse
};
return
{
...
state
,
login
State
:
'
fa
ilure
'
};
case
types
.
LOGINPROGRESS
:
return
{
...
state
,
login
Progress
:
true
,
logginError
:
false
,
loggedIn
:
false
};
return
{
...
state
,
login
State
:
'
progress
'
};
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