mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-18 14:22:42 +00:00
Add passwordless login for local installs
This commit is contained in:
@@ -36,6 +36,7 @@ const Homebrew = createClass({
|
|||||||
global.account = this.props.account;
|
global.account = this.props.account;
|
||||||
global.version = this.props.version;
|
global.version = this.props.version;
|
||||||
global.enable_v3 = this.props.enable_v3;
|
global.enable_v3 = this.props.enable_v3;
|
||||||
|
global.config = this.props.config;
|
||||||
},
|
},
|
||||||
render : function (){
|
render : function (){
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const createClass = require('create-react-class');
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
|
const jwt = require('jwt-simple');
|
||||||
|
|
||||||
const Account = createClass({
|
const Account = createClass({
|
||||||
displayName : 'AccountNavItem',
|
displayName : 'AccountNavItem',
|
||||||
@@ -25,7 +26,26 @@ const Account = createClass({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
localLogin : function(){
|
||||||
|
const username = prompt('Enter username:');
|
||||||
|
if(!username) {return;};
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
username : username,
|
||||||
|
issued : new Date()
|
||||||
|
};
|
||||||
|
const expiry = new Date;
|
||||||
|
expiry.setFullYear(expiry.getFullYear() + 1);
|
||||||
|
const token = jwt.encode(payload, global.config.secret);
|
||||||
|
|
||||||
|
document.cookie = `nc_session=${token};expires=${expiry};path=/;samesite=lax;${window.domain ? `domain=${window.domain}` : ''}`;
|
||||||
|
window.location.reload(true);
|
||||||
|
},
|
||||||
|
|
||||||
render : function(){
|
render : function(){
|
||||||
|
const localEnvironments = ['local', 'docker'];
|
||||||
|
|
||||||
|
// Logged in
|
||||||
if(global.account){
|
if(global.account){
|
||||||
return <Nav.dropdown>
|
return <Nav.dropdown>
|
||||||
<Nav.item
|
<Nav.item
|
||||||
@@ -53,6 +73,16 @@ const Account = createClass({
|
|||||||
</Nav.dropdown>;
|
</Nav.dropdown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Logged out
|
||||||
|
// LOCAL ONLY
|
||||||
|
if(localEnvironments.includes(global.config.environment)) {
|
||||||
|
return <Nav.item color='teal' icon='fas fa-sign-in-alt' onClick={this.localLogin}>
|
||||||
|
login
|
||||||
|
</Nav.item>;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Logged out
|
||||||
|
// Production site
|
||||||
return <Nav.item href={`https://www.naturalcrit.com/login?redirect=${this.state.url}`} color='teal' icon='fas fa-sign-in-alt'>
|
return <Nav.item href={`https://www.naturalcrit.com/login?redirect=${this.state.url}`} color='teal' icon='fas fa-sign-in-alt'>
|
||||||
login
|
login
|
||||||
</Nav.item>;
|
</Nav.item>;
|
||||||
|
|||||||
@@ -262,6 +262,10 @@ app.get('/print/:id', asyncHandler(async (req, res, next)=>{
|
|||||||
//Render the page
|
//Render the page
|
||||||
const templateFn = require('./../client/template.js');
|
const templateFn = require('./../client/template.js');
|
||||||
app.use((req, res)=>{
|
app.use((req, res)=>{
|
||||||
|
const configuration = {
|
||||||
|
environment : config.get('node_env'),
|
||||||
|
secret : config.get('secret')
|
||||||
|
};
|
||||||
const props = {
|
const props = {
|
||||||
version : require('./../package.json').version,
|
version : require('./../package.json').version,
|
||||||
url : req.originalUrl,
|
url : req.originalUrl,
|
||||||
@@ -269,7 +273,8 @@ app.use((req, res)=>{
|
|||||||
brews : req.brews,
|
brews : req.brews,
|
||||||
googleBrews : req.googleBrews,
|
googleBrews : req.googleBrews,
|
||||||
account : req.account,
|
account : req.account,
|
||||||
enable_v3 : config.get('enable_v3')
|
enable_v3 : config.get('enable_v3'),
|
||||||
|
config : configuration
|
||||||
};
|
};
|
||||||
const title = req.brew ? req.brew.title : '';
|
const title = req.brew ? req.brew.title : '';
|
||||||
templateFn('homebrew', title, props)
|
templateFn('homebrew', title, props)
|
||||||
|
|||||||
Reference in New Issue
Block a user