Skip to content

Instantly share code, notes, and snippets.

@pblocz
Last active August 29, 2015 14:11
Show Gist options
  • Save pblocz/2b50eaf5e4912cbf8d35 to your computer and use it in GitHub Desktop.
Save pblocz/2b50eaf5e4912cbf8d35 to your computer and use it in GitHub Desktop.
To login automatically into UCM unified login
/*! cv-autologin.user.js v1.0 | (c) 2014 Pablo Cabeza | MIT license: http://opensource.org/licenses/mit-license.php */
// ==UserScript==
// @name cv-autologin
// @namespace https://gist.github.com/2b50eaf5e4912cbf8d35
// @version 1.0
// @description To login automatically into UCM unified login
// @author Pablo Cabeza
// @include https://sso.ucm.es/simplesaml/module.php/userpasswordcaptcha/loginuserpass.php*
// @include http://www.ucm.es/campusvirtual*
// @include https://www.ucm.es/campusvirtual*
// @grant none
// @require http://code.jquery.com/jquery-latest.js
// @updateURL https://gist.github.com/PCabeza/2b50eaf5e4912cbf8d35/raw/cv-autologin.user.js
// @downloadURL https://gist.github.com/PCabeza/2b50eaf5e4912cbf8d35/raw/cv-autologin.user.js
// ==/UserScript==
(function(win,doc,$) {
var logindata = ['user','pass'];
var elids = ["#username","#password"];
var redirect_url = "www.ucm.es/campusvirtual"
function loginErrors() { return $('img[src$="gtk-dialog-error.48x48.png"]').length!==0; }
function setData(call){
if(logindata.length) {
$.each(elids,function(i,v) { $(v).val(logindata[i]); });
call();
}
else { // todo check if focus is in user of password
var val = true;
$.each(elids,function(i,v) { console.log($(v).val()); val = val && Boolean($(v).val()); } );
console.log(val);
if(val) call();
else win.setTimeout(function(){ setData(call); },500);
}
}
function submit(){ $('form[name=f]').submit(); }
function login() { if(!loginErrors()) setData(submit); }
function disableCaptcha() {
$.each(elids, function(i,v) { $(v).removeAttr('onblur'); });
}
$(doc).ready(function(){
var uri = win.location.host + win.location.pathname;
// If we are of cv redirect
if(uri==redirect_url||uri==redirect_url+"/") $('#login form [type=submit]').click();
// If we are on login form
else {
disableCaptcha();
login();
}
});
})(window,document,jQuery);
@jesusjda
Copy link

please update from my fork!
to access with "https"

https://gist.github.com/friker92/fbf3bda3952632cebd6e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment