Skip to content

Commit

Permalink
[view] Switch to req.session scope #95 #100
Browse files Browse the repository at this point in the history
 * No longer using `req.user` scope ( issues )
 * Performs search and replace on a few files
 * Fixes edge cases on user signups
 * Updates UI and Copy on a few pages
  • Loading branch information
Marak committed Sep 9, 2015
1 parent 9fc6464 commit a06cbf3
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 71 deletions.
16 changes: 16 additions & 0 deletions lib/resources/user.js
Expand Up @@ -14,6 +14,8 @@ user.property('stripeID', 'string');

user.property('domains', ["string"]);

user.property('hostingCredits', 'number');

user.property('emailBlasts', ["string"]);

// updates metrics for total hook count after creating
Expand All @@ -22,6 +24,20 @@ user.after('create', function(data, next){
next(null, data);
});

user.before('create', function (_user, next) {
if(typeof _user.name === "string") {
_user.name = _user.name.toLowerCase();
}
next(null, _user);
});

user.before('update', function (_user, next) {
if(typeof _user.name === "string") {
_user.name = _user.name.toLowerCase();
}
next(null, _user);
});

// ctime and mtime time stamps
user.timestamps();

Expand Down
6 changes: 3 additions & 3 deletions view/billing.js
Expand Up @@ -98,7 +98,7 @@ module['exports'] = function view (opts, callback) {
}

billing.create({
owner: req.user.username,
owner: req.session.user,
stripeID: customer.id,
amount: params.amount,
plan: _plan
Expand All @@ -111,7 +111,7 @@ module['exports'] = function view (opts, callback) {

// console.log('added to plan', err, charge);
$('.status').html('Billing Information Added! Thank you!');
billing.find({ owner: req.user.username }, function (err, results) {
billing.find({ owner: req.session.user }, function (err, results) {
if (err) {
$('.status').html(err.message);
return callback(err, $.html());
Expand All @@ -125,7 +125,7 @@ module['exports'] = function view (opts, callback) {
}
);
} else {
billing.find({ owner: req.user.username }, function (err, results) {
billing.find({ owner: req.session.user }, function (err, results) {
if (err) {
return callback(null, err.message);
}
Expand Down
2 changes: 1 addition & 1 deletion view/datastore.js
Expand Up @@ -12,7 +12,7 @@ module['exports'] = function view (opts, callback) {
return callback(null, $.html());
}

var datastore = new Datastore({ root: req.user.username });
var datastore = new Datastore({ root: req.session.user });

if (typeof params.key !== 'undefined') {
datastore.get(params.key, function(err, result){
Expand Down
5 changes: 3 additions & 2 deletions view/docs.html
Expand Up @@ -97,7 +97,8 @@ <h2><strong>Hook Debugging and Logs</strong></h2>
<a name="data"></a>
<hr/>
<h2><strong>Sending data to the Hook</strong></h2>
<p>Data can be sent to a Hook through the query string or posted to the Hook through forms or binary data transfers.</p>
<p>Data can be sent to a Hook through any methods HTTP supports.</p>
<p>The most common way to send data to a Hook is through the URL query string or posted through forms or binary data transfers.</p>
<h3><strong>Query String Data</strong></h3>
<p>To add a parameter via query string simply append it to the url of the Hook</p>
<p><strong>Example:</strong> <a href="https://hook.io/Marak/echo?foo=bar&hello=there&run=true">https://hook.io/Marak/echo?foo=bar&hello=there&run=true</a></p>
Expand Down Expand Up @@ -167,7 +168,7 @@ <h2><strong>Specifying Optional Schema</strong></h2>
Documentation for mschema can be found <a href="http://github.com/mschema/mschema/">here</a>.
</p>

<p><strong>Important:</strong> For performance reasons, changes made to the Hook schema will not appear in the User Interface until the Hook has been run once. The schema is applied to the Hook immediately when the gist is updated, just the User Interface will lag behind. This performance setting may be configurable in the future. The work-around is to simply run the Hook once to update the UI with new schema data.</p>
<p><strong>Important:</strong> For performance reasons, the Hook may need to be run to update it's schema.</p>
<hr/>

<a name="forms"/>
Expand Down
4 changes: 2 additions & 2 deletions view/domains.js
Expand Up @@ -25,14 +25,14 @@ module['exports'] = function view (opts, callback) {
bodyParser()(req, res, function bodyParsed() {
mergeParams(req, res, function (){});

req.resource.params.owner = req.user.username;
req.resource.params.owner = req.session.user;

var middle = forms.generate({
view: 'grid-with-form',
resource: domain,
action: '/domains',
params: req.resource.params,
query: { owner: req.user.username },
query: { owner: req.session.user },
useLayout: false,
form: {
create: {
Expand Down
4 changes: 2 additions & 2 deletions view/emails/layout.js
@@ -1,8 +1,8 @@
module['exports'] = function view (opts, callback) {
var req = opts.request
$ = this.$;
if (req.user && req.user.username) {
$('.myHooks').attr('href', '/' + req.user.username);
if (req.user && req.session.user) {
$('.myHooks').attr('href', '/' + req.session.user);
}
callback(null, this.$.html());
};
2 changes: 1 addition & 1 deletion view/env.js
Expand Up @@ -15,7 +15,7 @@ module['exports'] = function view (opts, callback) {

var params = req.resource.params;

user.find({ name: req.user.username }, function(err, results) {
user.find({ name: req.session.user }, function(err, results) {

if (err) {
return callback(null, err.message);
Expand Down
2 changes: 1 addition & 1 deletion view/gist.js
Expand Up @@ -30,7 +30,7 @@ module['exports'] = function view (opts, callback) {
return res.end(err.message);
}
req.session.gistLink = result.html_url;
req.session.gistLink = req.session.gistLink.replace('gist.github.com/', 'gist.github.com/' + req.user.username + "/");
req.session.gistLink = req.session.gistLink.replace('gist.github.com/', 'gist.github.com/' + req.session.user + "/");
return res.redirect('/new')
})
} else {
Expand Down
31 changes: 18 additions & 13 deletions view/index.html
@@ -1,5 +1,3 @@
<br/>
<br/>
<!--
this entire file is sloppy.
please open up a pull request at https://github.com/bigcompany/hook.io to clean it up
Expand Down Expand Up @@ -352,6 +350,10 @@
margin: 0px;
}
.tuts {
font-size: 24px;
}
.scrollForMore {
font-size: 32px;
}
</style>

Expand Down Expand Up @@ -474,7 +476,7 @@
$('#emailLogin').val('Create New Account');
break;
case 'exists':
alert('wtf bbq');
alert('exists');
break;
case 'email-sent':
$('.resetPasswordHolder').html('A password reset link has been emailed to you.')
Expand Down Expand Up @@ -662,13 +664,10 @@
"email": $('#email').val()
},
success: function(res){
alert(res);
if (res === "saved") {
$('.emailReminder').html('<span class="tiny">Verification email sent to: ' + $('#email').val() + "</span>");
}
$('.emailReminder').html('<span class="tiny">Verification email sent to: ' + $('#email').val() + "</span>");
},
error: function (err) {
alert('error' + err)
alert('error' + err);
}
})
return false;
Expand Down Expand Up @@ -761,6 +760,10 @@
return false;
});


$('#updateEmail').on('submit', function(){
return false;
});
$('.prevSnippet').on('click', function(){
var index = $('.selectSnippet').prop('selectedIndex');
var prev = index - 1;
Expand All @@ -776,8 +779,6 @@
var editor;
</script>

<br/>

<div class="container-fluid">

<div class="userBar">
Expand All @@ -804,6 +805,7 @@
</div>

<div class="row loginBar">
<br/>
<div class="col-md-8" align="center">
<div class="loginHolder">
<form action="/signup" id="loginForm">
Expand All @@ -824,11 +826,13 @@
<input type="submit" class="btn" value="Sign in with Github"/>
</form>
<br/>
<div><h3><a href="/pricing">Paid Accounts Available!</a></h3></div>
<div><h2><a href="/pricing">Paid Accounts Available!</a></h2></div>
<br/>
</div>
<p class="hookStats"><a href="#" class="deploymentsLink" title="Whenever a service URL is requested, hook.io will take a copy of the Hook's source code and deploy it to an awaiting worker in our elastic cloud to respond to the incoming request.">Deployments:</a> <span class="totalRun">loading...</span> </p>
<p>Scroll Down For More!</p>
<br/>
<p class"scrollForMore">Scroll Down For More!</p>
<br/>
</div>
<div class="col-md-4" align="left">
<div class="featuresDiv">
Expand All @@ -855,7 +859,8 @@ <h2>Features</h2>
</div>
<div class="row">
<div class="col-md-12" align="left">
<h2 class="tuts">Interactive Microservice Tutorial</h2>
<br/>
<h2 class="tuts">Click "Deploy Service" to instantly deploy your first Microservice!</h2>
<div class="btn-group transport" role="group">
<select name="selectSnippet" class="selectSnippet btn btn-default">
<option value="/Marak/examples-helloWorld">hello world</option>
Expand Down
2 changes: 1 addition & 1 deletion view/index.js
Expand Up @@ -98,9 +98,9 @@ module['exports'] = function view (opts, callback) {
$('.userBar').remove();
callback(null, this.$.html());
} else {
user = user.toLowerCase();
var query = { name: user };
return userResource.find(query, function(err, results){
console.log(err, results[0])
var u = results[0];
if(typeof u.email === "undefined" || u.email.length === 0) {
// do nothing, we have the email
Expand Down
4 changes: 2 additions & 2 deletions view/layout.js
@@ -1,8 +1,8 @@
module['exports'] = function view (opts, callback) {
var req = opts.request
$ = this.$;
if (req.user && req.user.username) {
$('.myHooks').attr('href', '/' + req.user.username);
if (req.user && req.session.user) {
$('.myHooks').attr('href', '/' + req.session.user);
}
$('title').html('hook.io - Free Microservice and Webhook Hosting. Deploy your code in seconds.');

Expand Down
6 changes: 4 additions & 2 deletions view/login.js
Expand Up @@ -22,6 +22,7 @@ module['exports'] = function view (opts, callback) {

parseRequest(req, res, function(err, params){
if (params.name && params.password) {
params.name = params.name.toLowerCase();
user.find({ name: params.name }, function (err, results) {
if (err) {
return res.end(err.message);
Expand All @@ -40,12 +41,13 @@ module['exports'] = function view (opts, callback) {
if (err) {
return res.end(err.message);
}
req.session.user = u.name;
req.session.user = u.name.toLowerCase();
return res.end('valid');
});
});
} else {
callback(null, $.html());
res.redirect('/');
// callback(null, $.html());
}
});

Expand Down
8 changes: 4 additions & 4 deletions view/logs.html
Expand Up @@ -13,6 +13,10 @@
<div align="left" class="logs">
<h1>Logging</h1>

<h2>Writing to Hook Logs</h2>
<p>To write to a Hook's logging output, simply call <code>console.log('hello logging');</code> from inside the Hook.</p>
<p>Calling <code>console.log</code> in the Hook will automatically make the console log statement available as a logging entry.</p>

<h2>Accessing Hook Logs</h2>
<p>To access the logs for a Hook simply attach <code>/logs</code> to the end of the Hook service url.</p>
<p><strong>For example:</strong> <a href="https://hook.io/Marak/echo/logs">https://hook.io/Marak/echo/logs</a></p>
Expand All @@ -26,10 +30,6 @@ <h3>Plain Text Logs</h3>
<p>To access plain text logs, request the logging endpoint with an <code>Accept</code> Header value of <code>text/plain</code></p>
<p><strong>Example: </strong ><code>curl -H "Accept: text/plain" https://hook.io/Marak/echo/logs</code></p>

<h2>Writing to Hook Logs</h2>
<p>To write to a Hook's logging output, simply call <code>console.log('hello logging');</code> from inside the Hook.</p>
<p>Calling <code>console.log</code> in the Hook will automatically make the console log statement available as a logging entry.</p>

<h2>Limitations</h2>
<p>Currently all Free accounts are limited to fifty logging entries per Hook. If you need to increase this limit you can upgrade to a paid account or contact <a href="mailto:hookmaster@hook.io">hookmaster@hook.io</a>

Expand Down

0 comments on commit a06cbf3

Please sign in to comment.