Merge branch 'feature/node' of https://github.com/remy/jsbin into feature/node

This commit is contained in:
Remy Sharp 2012-06-27 08:18:45 +01:00
commit f5e902aaa0
6 changed files with 91 additions and 21 deletions

View File

@ -48,6 +48,7 @@ if ($session) {
}
$home = isset($session['user']) ? $session['user']['name'] : '';
$email = isset($session['user']) ? $session['user']['email'] : '';
$csrf = isset($_COOKIE['_csrf']) ? $_COOKIE['_csrf'] : md5(rand());
if (!in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD'))) {
@ -150,14 +151,16 @@ if (!$action) {
$key = $_POST['key'];
$name = $_POST['name'];
$email = $_POST['email'];
// TODO allow email to be used as the lookup key
$sql = sprintf('select * from ownership where name="%s"', mysql_real_escape_string($name));
$result = mysql_query($sql);
$ok = false;
$created = false;
$rows_affected = mysql_num_rows($result);
header('content-type: application/json');
if (!mysql_num_rows($result)) {
if (!$rows_affected && strlen($email)) {
// store and okay (note "key" is a reserved word - typical!)
$key = $bcrypt->hash($key);
$sql = sprintf('insert into ownership (`name`, `key`, `email`, `last_login`, `created`, `updated`) values ("%s", "%s", "%s", NOW(), NOW(), NOW())', mysql_real_escape_string($name), mysql_real_escape_string($key), mysql_real_escape_string($email));
@ -167,12 +170,16 @@ if (!$action) {
$created = true;
// echo json_encode(array('ok' => true, 'created' => true));
} else {
echo json_encode(array('ok' => false, 'error' => mysql_error()));
echo json_encode(array('ok' => false, 'message' => 'Sorry, I couldn\'t find your account. Can you double check?'));
// echo json_encode(array('ok' => false, 'error' => mysql_error()));
}
// } else if (!strlen($email)) {
// echo json_encode(array('ok' => false, 'message' => 'ok2 Sorry, I couldn\'t find your account. Can you double check?'));
} else {
// check key
$row = mysql_fetch_object($result);
$email = $row->email;
$hashed = $row->key;
$created = date_parse($row->created);
if (!$created || $created['warning_count']) {
@ -182,7 +189,7 @@ if (!$action) {
if (!mysql_query($sql)) {
echo json_encode(array('ok' => false, 'error' => mysql_error()));
exit;
}
}
}
}
@ -201,6 +208,7 @@ if (!$action) {
if ($ok) {
$data = json_encode(array('user' => array(
'name' => $name,
'email' => $email,
'lastLogin' => time()
)));
$hash = session_hash($data);

View File

@ -30,6 +30,11 @@ $list_history = ob_get_clean();
$code_id_domain = preg_replace('/https?:\/\//', '', $code_id_path);
$gravatar = '';
if ($email) {
$gravatar = 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($email))) . '?s=28';
}
$view = file_get_contents('../views/index.html');
$mustache = new Mustache;
echo $mustache->render($view, array(
@ -37,6 +42,7 @@ echo $mustache->render($view, array(
'root' => ROOT,
'version' => VERSION,
'home' => $home,
'gravatar' => $gravatar,
'revision' => $revision,
'code_id' => $code_id,
'url' => $_SERVER['REQUEST_URI'],

View File

@ -1145,7 +1145,9 @@ input {
background: #f3b8b6;
background: rgba(255, 0, 0, 0.2);
border: 1px solid red;
margin: 10px 0;
margin: 0;
white-space: normal;
line-height: 18px;
}
/*#loginFeedback:empty {
@ -1561,10 +1563,10 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
}
.icon { font-family: sans-serif; }
/*.button-dropdown:after,*/
/*.fake-dropdown:after { content: "▾"; padding-left: 5px; padding-right: 3px; }*/
/*.button-dropdown:empty:after,*/
/*.fake-dropdown:empty:after { padding-left: 0; }*/
.button-dropdown-arrow:after,
.fake-dropdown:after { content: "▾"; padding-left: 5px; padding-right: 3px; }
.button-dropdown-arrow:empty:after,
.fake-dropdown:empty:after { padding-left: 0; }
.editbox {
@ -2132,4 +2134,50 @@ pre .highlight:last-of-type {
transition-property: opacity, margin-right;
transition-timing-function: ease-out, ease-out;
transition-duration: 100ms, 100ms;
}
.dropdown {
margin-top: 8px;
}
.dropdown > div:after, .dropdown > div:before {
bottom: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
z-index: 1;
left: 17%;
}
.dropdown > div:after {
border-bottom-color: #fff;
border-width: 10px;
margin-left: -10px;
top: -16px;
}
.dd-right.dropdown > div:after {
left: 83%;
}
.dropdown > div:before {
border-bottom-color: #ccc;
border-width: 11px;
margin-left: -11px;
top: -18px;
}
.dd-right.dropdown > div:before {
left: 83%;
}
.avatar {
margin-right: 7px;
vertical-align: top;
display: inline-block;
border-radius: 1px;
margin-top: -2px;
}

View File

@ -24,13 +24,13 @@ var $loginForm = $('form.login').submit(function (event) {
var data = $.parseJSON(jqXHR.responseText) || {};
// cookie is required to share with the server so we can do a redirect on new bin
if (data.ok) {
$loginFeedback.text('Successfully tied this browser to "' + name + '".');
setTimeout(function () {
window.location = window.location.pathname + window.location.search;
}, 500);
// $loginFeedback.text('Successfully tied this browser to "' + name + '".');
// setTimeout(function () {
window.location = window.location.pathname + window.location.search;
// }, 500);
} else {
analytics.login(false);
$loginFeedback.text('"' + name + '" has already been taken. Please either double check the password, or choose another username.');
$loginFeedback.text(data.message || ('"' + name + '" has already been taken. Please either double check the password, or choose another username.'));
}
}
});

View File

@ -72,22 +72,25 @@ var dropdownOpen = false,
menuDown = false;
function opendropdown(el) {
var menu;
if (!dropdownOpen) {
$(el).closest('.menu').addClass('open');
dropdownOpen = true;
menu = $(el).closest('.menu').addClass('open').trigger('open');
menu.find('input:first').focus();
dropdownOpen = el;
}
}
function closedropdown() {
menuDown = false;
if (dropdownOpen) {
dropdownButtons.closest('.menu').removeClass('open');
dropdownButtons.closest('.menu').removeClass('open').trigger('close');
dropdownOpen = false;
onhover = false;
}
}
$('.button-open').mousedown(function (e) {
if (dropdownOpen && dropdownOpen !== this) closedropdown();
if (!dropdownOpen) {
menuDown = true;
opendropdown(this);
@ -98,7 +101,7 @@ $('.button-open').mousedown(function (e) {
var dropdownButtons = $('.button-dropdown, .button-open').mousedown(function (e) {
$dropdownLinks.removeClass('hover');
if (dropdownOpen && dropdownOpen !== this) closedropdown();
if (!dropdownOpen) {
menuDown = true;
opendropdown(this);
@ -204,6 +207,11 @@ $('#createnew').click(function () {
}, 0);
});
$('form.login').closest('.menu').bind('close', function () {
$(this).find('.loginFeedback').empty().hide();
});
jsbin.settings.includejs = jsbin.settings.includejs || false;
$('#enablejs').change(function () {
jsbin.settings.includejs = this.checked;

View File

@ -47,9 +47,9 @@
{{#home}}
<div class="menu">
<div class="group">
<a href="#" class="button homebtn">{{home}}</a><a href="#homemenu" class="button button-dropdown"><span class="icon icon-chevron-down"></span></a>
<a href="#" class="button homebtn">{{#gravatar}}<img class="avatar" src="{{gravatar}}">{{/gravatar}}{{home}}</a><a href="#homemenu" class="button button-dropdown button-dropdown-arrow"><span class="icon icon-chevron-down"></span></a>
</div>
<div class="dropdown" id="homemenu">
<div class="dropdown dd-right" id="homemenu">
<div class="dropdownmenu">
<form action="{{root}}/logout" method="POST">
<input type="hidden" name="_csrf" value="{{token}}" />
@ -78,7 +78,7 @@
</div>
<div>
<input type=submit value="Log in">
<a id="lostpass" href="#">Lost password?</a>
<!--<a id="lostpass" href="#">Lost password?</a>-->
</div>
</form>
</div>