Skip to content

Instantly share code, notes, and snippets.

@fiatjaf fiatjaf/command.js
Last active Aug 29, 2015

Embed
What would you like to do?
in a couchapp's entry page,this bookmarklet opens a form into which you can type your login and password and start a session.
var form = '<div style="position:absolute;left:50%;top:50%;margin-left:-150px;margin-top:-100px;width:300px;height:200px;"><form id="loginForm"><input placeholder="nome" name="name"><input placeholder="senha" type="password" name="password"><button onclick="login(event)">OK</button></form></div>';
document.write(form);
function login(event) {
event.preventDefault();
event.returnValue = false;
var form = document.getElementById('loginForm');
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
location.reload();
}
};
xhr.open('POST', '/_session', true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send('name=' + form.name.value + '&password=' + form.password.value);
};
{
"name": "Login to CouchApp",
"description": "Open a form to login to the current CouchApp (if you're seeing the 'not authorized to this db' page)",
"link": "https://gist.github.com/fiatjaf/b8d4f3b0b76f4e493e46"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.