mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-13 02:14:39 +00:00
Added in a logout to the user page
This commit is contained in:
@@ -3,11 +3,12 @@ const _ = require('lodash');
|
|||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
|
|
||||||
const CreateRouter = require('pico-router').createRouter;
|
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 HomePage = require('./pages/homePage/homePage.jsx');
|
||||||
const EditPage = require('./pages/editPage/editPage.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 SharePage = require('./pages/sharePage/sharePage.jsx');
|
||||||
const NewPage = require('./pages/newPage/newPage.jsx');
|
const NewPage = require('./pages/newPage/newPage.jsx');
|
||||||
//const ErrorPage = require('./pages/errorPage/errorPage.jsx');
|
//const ErrorPage = require('./pages/errorPage/errorPage.jsx');
|
||||||
@@ -39,19 +40,25 @@ const Homebrew = React.createClass({
|
|||||||
|
|
||||||
//console.log(mapObject(['version', 'brew', 'account'], this.props));
|
//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({
|
Router = CreateRouter({
|
||||||
'/edit/:id' : <EditPage />,
|
'/edit/:id' : <EditPage />,
|
||||||
'/share/:id' : <SharePage />,
|
'/share/:id' : <SharePage />,
|
||||||
/*
|
|
||||||
'/user/:username' : (args) => {
|
'/user/:username' : (args) => {
|
||||||
return <UserPage
|
return <UserPage
|
||||||
username={args.username}
|
username={args.username}
|
||||||
brews={this.props.brews}
|
brews={this.props.brews}
|
||||||
/>
|
/>
|
||||||
},*/
|
},
|
||||||
'/print/:id' : (args, query) => {
|
'/print/:id' : (args, query) => {
|
||||||
return <PrintPage brew={this.props.brew} query={query}/>;
|
return <PrintPage brew={this.props.brew} query={query}/>;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,19 +1,23 @@
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
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){
|
module.exports = function(props){
|
||||||
if(global.account){
|
const user = Store.getUser();
|
||||||
return <Nav.item href={`/user/${global.account.username}`} color='yellow' icon='fa-user'>
|
if(user && user == props.userPage){
|
||||||
{global.account.username}
|
return <Nav.item onClick={Actions.logout} color='yellow' icon='fa-user-times'>
|
||||||
|
logout
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
}
|
}
|
||||||
let url = '';
|
if(user){
|
||||||
/*
|
return <Nav.item href={`/user/${user}`} color='yellow' icon='fa-user'>
|
||||||
if(typeof window !== 'undefined'){
|
{user}
|
||||||
url = window.location.href
|
</Nav.item>
|
||||||
}
|
}
|
||||||
*/
|
return <Nav.item onClick={Actions.login} color='teal' icon='fa-sign-in'>
|
||||||
return <Nav.item href={`http://naturalcrit.com/login?redirect=${url}`} color='teal' icon='fa-sign-in'>
|
|
||||||
login
|
login
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
};
|
};
|
||||||
@@ -57,7 +57,7 @@ const UserPage = React.createClass({
|
|||||||
<Navbar>
|
<Navbar>
|
||||||
<Nav.section>
|
<Nav.section>
|
||||||
<RecentNavItem.both />
|
<RecentNavItem.both />
|
||||||
<Account />
|
<Account userPage={this.props.username} />
|
||||||
</Nav.section>
|
</Nav.section>
|
||||||
</Navbar>
|
</Navbar>
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,7 @@ const BrewData = {
|
|||||||
//defaults with page and count
|
//defaults with page and count
|
||||||
//returns a non-text version of brews
|
//returns a non-text version of brews
|
||||||
//assume sanatized ?
|
//assume sanatized ?
|
||||||
|
return Promise.resolve([]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
20
shared/homebrewery/account.actions.js
Normal file
20
shared/homebrewery/account.actions.js
Normal 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;
|
||||||
27
shared/homebrewery/account.store.js
Normal file
27
shared/homebrewery/account.store.js
Normal 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;
|
||||||
Reference in New Issue
Block a user