Skip to content

Commit

Permalink
* Autologin
Browse files Browse the repository at this point in the history
* Home page starts with an area, not a boring ol' singleton!
  • Loading branch information
Tom Boutell committed Sep 28, 2016
1 parent b2f0505 commit 0e927fd
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 10 deletions.
9 changes: 7 additions & 2 deletions app.js
Expand Up @@ -21,10 +21,15 @@ var apos = require('apostrophe')({
'apostrophe-blog-pages': {},
'apostrophe-blog-widgets': {},
'apostrophe-users': {},

// Apostrophe Sandbox (as-) specific modules
'as-helpers': {},
'as-two-column-block-widgets': {}
'as-two-column-block-widgets': {},

// REMOVE ME IMMEDIATELY if you are not running a public demo
// that should let EVERYBODY be INSTANTLY loggged in AS ADMIN!
// 'demo-autologin': {},

}

});
23 changes: 17 additions & 6 deletions lib/modules/apostrophe-pages/views/pages/home.html
Expand Up @@ -8,12 +8,23 @@
<div class="inner">
<div class="demo-pageheader">
<img class="demo-apos-lockup pageheader-logo" src="/images/demo_logo_apos_lockup.png" alt="Apostrophe">
{{ apos.singleton(data.page, 'homepageText', 'apostrophe-rich-text', {
toolbar: [ 'Styles', 'Bold', 'Italic', 'Blockquote', 'Link', 'Anchor', 'Unlink', 'BulletedList' ],
styles: [
{ name: 'Title', element: 'h3' },
{ name: 'Paragraph', element: 'p' }
]
{# This Area needs Slideshow, and Video Widgets! #}
{{ apos.area(data.page, 'homepageText', {
widgets: {
'apostrophe-rich-text': {
toolbar: [ 'Styles', 'Bold', 'Italic', 'Blockquote', 'Link', 'Anchor', 'Unlink', 'BulletedList' ],
styles: [
{ name: 'Title', element: 'h3' },
{ name: 'Paragraph', element: 'p' }
]
},
'apostrophe-images': {
minSize: [ 700, 350 ],
aspectRatio: [ 2, 1 ],
size: 'full'
},
'apostrophe-video': {}
}
}) }}
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions lib/modules/apostrophe-templates/views/layout.html
Expand Up @@ -18,6 +18,7 @@ <h5>{% block headerMessage %}
{%- if not data.user and not data.user._permissions.admin -%}
<h5 class="demo-login-button"><a href="/login"><span>&#xf090;</span>Login</a></h5>
{%- endif -%}
<p>CLICK ON TEXT BELOW TO EDIT IT. Also try the "+" signs that appear when you hover over the page.</p>
<p>Content in the demo can be edited in context by clicking on each content type. Feel free to mess anything up, this page will automatically refresh every hour restoring the original content. If anything seems strange, someone else using the demo site has likely made a change. <!-- Check out <a href="http://apostrophenow.org" target="blank">apostrophenow.org</a> for more information. --></p>
</div>
{{ nav.nav(data, {classes: 'hide-mobile'}) }}
Expand Down
33 changes: 33 additions & 0 deletions lib/modules/demo-autologin/index.js
@@ -0,0 +1,33 @@
module.exports = {
construct: function(self, options) {
console.error('\n*** DANGER! *** YOU HAVE THE demo-autologin MODULE ENABLED!\n');
console.error('If you are not us, or running a public demo to which EVERYBODY');
console.error('should be INSTANTLY logged in AS ADMIN, remove the demo-autologin');
console.error('module folder and remove it from app.js too.');
console.error('');
console.error('(By the way, next time use the apostrophe-cli to make a much cleaner,');
console.error('smaller new project. Forking this sandbox is the hard way!)\n');
self.pageBeforeSend = function(req, callback) {
if (!req.cookies.demo_autologin) {
return self.apos.users.find({ username: 'admin' }).permission(false).toObject(function(err, user) {
if (err) {
return callback(err);
}
if (!user) {
return callback(null);
}
req.login(user, function(err) {
if (err) {
return callback(err);
}
// Start a whole new request, but logged in. After this they
// have the cookie so they can log out and back in normally if they want
req.res.cookie('demo_autologin', 1);
return req.res.redirect('/');
});
});
}
return callback(null);
};
}
};
Empty file.
13 changes: 13 additions & 0 deletions lib/modules/demo-autologin/lib/utils.js
@@ -0,0 +1,13 @@
// Borrowed from passport-local

exports.lookup = function(obj, field) {
if (!obj) { return null; }
var chain = field.split(']').join('').split('[');
for (var i = 0, len = chain.length; i < len; i++) {
var prop = obj[chain[i]];
if (typeof(prop) === 'undefined') { return null; }
if (typeof(prop) !== 'object') { return prop; }
obj = prop;
}
return null;
};
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -14,9 +14,9 @@
"license": "MIT",
"dependencies": {
"apostrophe": "^2.0.0",
"moment": "^2.14.1",
"apostrophe-blog": "^2.0.0",
"html2plaintext": "^1.0.1",
"lodash": "^3.1.0"
"lodash": "^3.1.0",
"moment": "^2.14.1"
}
}

0 comments on commit 0e927fd

Please sign in to comment.