0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-12 21:52:42 +00:00

Added in a logout to the user page

This commit is contained in:
Scott Tolksdorf
2017-01-09 17:32:46 -05:00
parent 0d0f0d8eb0
commit baaa82ed34
6 changed files with 74 additions and 15 deletions

View File

@@ -3,11 +3,12 @@ const _ = require('lodash');
const cx = require('classnames');
const CreateRouter = require('pico-router').createRouter;
const Actions = require('homebrewery/brew.actions.js');
const BrewActions = require('homebrewery/brew.actions.js');
const AccountActions = require('homebrewery/account.actions.js');
const HomePage = require('./pages/homePage/homePage.jsx');
const EditPage = require('./pages/editPage/editPage.jsx');
//const UserPage = require('./pages/userPage/userPage.jsx');
const UserPage = require('./pages/userPage/userPage.jsx');
const SharePage = require('./pages/sharePage/sharePage.jsx');
const NewPage = require('./pages/newPage/newPage.jsx');
//const ErrorPage = require('./pages/errorPage/errorPage.jsx');
@@ -39,19 +40,25 @@ const Homebrew = React.createClass({
//console.log(mapObject(['version', 'brew', 'account'], this.props));
Actions.init(mapObject(['version', 'brew', 'account'], this.props));
BrewActions.init({
version : this.props.version,
brew : this.props.brew
});
AccountActions.init({
user : this.props.user,
loginPath : this.props.loginPath
});
Router = CreateRouter({
'/edit/:id' : <EditPage />,
'/share/:id' : <SharePage />,
/*
'/user/:username' : (args) => {
return <UserPage
username={args.username}
brews={this.props.brews}
/>
},*/
},
'/print/:id' : (args, query) => {
return <PrintPage brew={this.props.brew} query={query}/>;
},

View File

@@ -1,19 +1,23 @@
const React = require('react');
const Nav = require('naturalcrit/nav/nav.jsx');
const Store = require('homebrewery/account.store.js');
const Actions = require('homebrewery/account.actions.js');
module.exports = function(props){
if(global.account){
return <Nav.item href={`/user/${global.account.username}`} color='yellow' icon='fa-user'>
{global.account.username}
const user = Store.getUser();
if(user && user == props.userPage){
return <Nav.item onClick={Actions.logout} color='yellow' icon='fa-user-times'>
logout
</Nav.item>
}
let url = '';
/*
if(typeof window !== 'undefined'){
url = window.location.href
if(user){
return <Nav.item href={`/user/${user}`} color='yellow' icon='fa-user'>
{user}
</Nav.item>
}
*/
return <Nav.item href={`http://naturalcrit.com/login?redirect=${url}`} color='teal' icon='fa-sign-in'>
return <Nav.item onClick={Actions.login} color='teal' icon='fa-sign-in'>
login
</Nav.item>
};

View File

@@ -57,7 +57,7 @@ const UserPage = React.createClass({
<Navbar>
<Nav.section>
<RecentNavItem.both />
<Account />
<Account userPage={this.props.username} />
</Nav.section>
</Navbar>

View File

@@ -109,6 +109,7 @@ const BrewData = {
//defaults with page and count
//returns a non-text version of brews
//assume sanatized ?
return Promise.resolve([]);
},

View File

@@ -0,0 +1,20 @@
const Store = require('./account.store.js');
const Actions = {
init : (initState) => {
Store.init(initState);
},
login : ()=>{
console.log('login');
//redirect to the login path and add the redirect
},
logout : ()=>{
document.cookie = 'nc_session=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;domain=.naturalcrit.com';
//Remove local dev cookies too
document.cookie = 'nc_session=;expires=Thu, 01 Jan 1970 00:00:01 GMT;path=/;';
window.location ='/';
}
};
module.exports = Actions;

View File

@@ -0,0 +1,27 @@
const _ = require('lodash');
const flux = require('pico-flux');
let State = {
loginPath : '',
user : undefined,
};
const Store = {}; //Maybe Flux it later?
Store.init = (state)=>{
State = _.merge({}, State, state);
};
Store.getLoginPath = ()=>{
let path = State.loginPath;
if(typeof window !== 'undefined'){
console.log('yo here');
}
return path;
};
Store.getUser = ()=>{
return State.user;
};
module.exports = Store;