Skip to content

Instantly share code, notes, and snippets.

@trotter
Created September 5, 2008 23:19
Show Gist options
  • Save trotter/9056 to your computer and use it in GitHub Desktop.
Save trotter/9056 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "mbox-login",
homepage: "http://www.motionbox.com",
author: {name: "Trotter Cashion", email: "trotter.cashion@motionbox.com"},
license: "MIT",
description: "Quick and easy login to motionbox",
help: "Will log you into Motionbox and open a new tab with your profile page",
takes: {login: noun_arb_text},
modifiers: {"/": noun_arb_text, host: noun_arb_text},
_host: function(host) {
return host || "www.motionbox.com";
},
_login_url: function(host) {
return "http://" + this._host(host) + "/user/login";
},
preview: function(pblock, login, mods) {
var template = "Login to ${url} using ${login} / ${password}";
var subs = {url: this._login_url(mods.host.text), login: login.text, password: mods["/"].text};
pblock.innerHTML = CmdUtils.renderTemplate(template, subs);
},
execute: function(login, mods) {
var url = this._login_url(mods.host.text);
var params = {"user[login]": login.text, "user[password]": mods["/"].text};
var redirect_url = "http://" + this._host(mods.host.text);
jQuery.post(url, params, function(response) {
Utils.openUrlInBrowser(redirect_url);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment