Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
scratch-www
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
scratch-www
Commits
32b7d5a4
Commit
32b7d5a4
authored
Mar 22, 2016
by
Ray Schamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Retrieve token from session cookie
parent
96bc1b1a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
5 deletions
+57
-5
src/redux/actions.js
src/redux/actions.js
+39
-3
src/redux/reducer.js
src/redux/reducer.js
+18
-2
No files found.
src/redux/actions.js
View file @
32b7d5a4
var
keyMirror
=
require
(
'
keymirror
'
);
var
keyMirror
=
require
(
'
keymirror
'
);
var
api
=
require
(
'
../mixins/api.jsx
'
).
api
;
var
api
=
require
(
'
../mixins/api.jsx
'
).
api
;
var
jar
=
require
(
'
../lib/jar.js
'
);
var
Types
=
keyMirror
({
var
Types
=
keyMirror
({
REFRESH_SESSION
:
null
,
SET_SESSION
:
null
,
SET_SESSION
:
null
,
SET_SESSION_ERROR
:
null
SET_SESSION_ERROR
:
null
,
SET_TOKEN
:
null
,
SET_TOKEN_ERROR
:
null
,
USE_TOKEN
:
null
});
});
var
Actions
=
{
var
Actions
=
{
...
@@ -36,12 +39,45 @@ var Actions = {
...
@@ -36,12 +39,45 @@ var Actions = {
if
(
body
.
banned
)
{
if
(
body
.
banned
)
{
return
window
.
location
=
url
;
return
window
.
location
=
url
;
}
else
{
}
else
{
return
dispatch
(
Actions
.
setSession
(
body
));
dispatch
(
Actions
.
getToken
());
dispatch
(
Actions
.
setSession
(
body
));
return
;
}
}
}
}
});
});
};
};
},
},
getToken
:
function
()
{
return
function
(
dispatch
)
{
jar
.
get
(
'
scratchsessionsid
'
,
function
(
err
,
value
)
{
if
(
err
)
return
dispatch
(
Actions
.
setTokenError
(
err
));
jar
.
unsign
(
value
,
function
(
err
,
contents
)
{
if
(
err
)
return
dispatch
(
Actions
.
setTokenError
(
err
));
try
{
var
sessionData
=
JSON
.
parse
(
contents
);
}
catch
(
err
)
{
return
dispatch
(
Actions
.
setTokenError
(
err
));
}
return
dispatch
(
Actions
.
setToken
(
sessionData
.
token
));
});
});
}
},
setToken
:
function
(
token
)
{
return
{
type
:
Types
.
SET_TOKEN
,
token
:
token
};
},
setTokenError
:
function
(
error
)
{
return
{
type
:
Types
.
SET_SESSION_ERROR
,
error
:
error
};
}
};
};
module
.
exports
=
Actions
;
module
.
exports
=
Actions
;
src/redux/reducer.js
View file @
32b7d5a4
...
@@ -5,7 +5,6 @@ var actionTypes = require('./actions.js').types;
...
@@ -5,7 +5,6 @@ var actionTypes = require('./actions.js').types;
var
sessionReducer
=
function
(
state
,
action
)
{
var
sessionReducer
=
function
(
state
,
action
)
{
// Reducer for handling changes to session state
// Reducer for handling changes to session state
if
(
typeof
state
===
'
undefined
'
)
{
if
(
typeof
state
===
'
undefined
'
)
{
state
=
{};
state
=
{};
}
}
...
@@ -20,8 +19,25 @@ var sessionReducer = function (state, action) {
...
@@ -20,8 +19,25 @@ var sessionReducer = function (state, action) {
}
}
};
};
var
tokenReducer
=
function
(
state
,
action
)
{
// Reducer for updating the api token
if
(
typeof
state
===
'
undefined
'
)
{
state
=
''
;
}
switch
(
action
.
type
)
{
case
actionTypes
.
SET_TOKEN
:
return
action
.
token
;
case
actionTypes
.
SET_TOKEN_ERROR
:
// TODO: do something with the error
return
state
;
default
:
return
state
;
}
};
var
appReducer
=
combineReducers
({
var
appReducer
=
combineReducers
({
session
:
sessionReducer
session
:
sessionReducer
,
token
:
tokenReducer
});
});
module
.
exports
=
appReducer
;
module
.
exports
=
appReducer
;
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