/*
##########################################################
START LOGIN MANAGER
##########################################################
*/
$.fn.e4eLogin = function () {
var args = arguments[0] || {};
var options = $.extend({}, $.e4eLogin.defaults, args);
var elem = $(this);
return this.each(function () {
new $.e4eLogin.construct(elem, options);
});
};
$.e4eLogin = {
defaults:{
overlay:true,
overlaySettings:{
setClass:'login-overlay',
color:'#000',
opacity: 0.6
},
minimal:false,
animate:true,
formSettings:{
setClass: 'login-panel',
forgottenLink:false,
forgottenInput:true,
forgottenInputSettings:{
preHTML: '
Having trouble logging in? If you would like us to reset your password via email please enter your username:
'
},
logo:true,
websiteName:true,
loginHTML:"Welcome to the
Customers Matter Secure Login ",
closeButton: true,
signup: true
}
},
loginCount: 0,
construct:function(elem, options){
$.e4eLogin.loginCount++;
$(elem)
.append(
(options.overlay === true?
$('
')
.addClass(options.overlaySettings.setClass)
.css({
width: $(elem).width(),
height: $(elem).height(),
position: 'absolute',
top:0,
left:0,
background: options.overlaySettings.color,
opacity: (options.animate === true ? 0 : options.overlaySettings.opacity) // starts off transparent?
})
.animate({opacity:(options.animate === false ? 1 : options.overlaySettings.opacity)}, 500)
:
''
)
)
.append(
(options.overlay === true ?
$('
').addClass('login-shadow').css({opacity:0.4})
:'')
)
.append(
$('
')
.addClass(options.formSettings.setClass)
.addClass((options.minimal === true ? 'login-inline' : ''))
.css({
opacity: (options.animate === true ? 0 : 1) // starts off transparent?
})
.append(
$('')
.addClass('login-input-form')
.append(
(options.minimal === false ?
$('
')
.addClass('login-input-form-div')
.append((options.formSettings.closeButton === true ?
$('
') // close button
.addClass('login-close')
.click(function(){
$.e4eLogin.doClose($(this));
})
: ''))
.append((options.formSettings.logo === true ? $('
').addClass('login-logo') : '')) // show / hide logo
.append(options.formSettings.loginHTML)
.append(
$('
')
.addClass('login-inputArea')
.append(
$(' ')
.addClass('login-input-username')
.append(
$(' ')
.append('Username:')
.attr('for','login-input-username_'+$.e4eLogin.loginCount)
)
.append(
$(' ')
.addClass('login-input-username-input')
.attr({
'id':'login-input-username_'+$.e4eLogin.loginCount,
'type':'text',
'name':'login-input-username-field'
})
)
)
.append(
$(' ')
.addClass('login-input-password')
.append(
$(' ')
.append('Password:')
.attr('for','login-input-password_'+$.e4eLogin.loginCount)
)
.append(
$(' ')
.addClass('login-input-password-input')
.attr({
'id':'login-input-password_'+$.e4eLogin.loginCount,
'type':'password',
'name':'login-input-password-field'
})
)
)
.append(
$(' ')
.addClass('login-input-login')
.append(
$(' ')
.addClass('login-input-login-button')
.attr({
'type':'submit',
'value':'Login'
})
)
)
.append(
(options.formSettings.signup === true ?
$(' ')
.append(
$('
')
.addClass('login-hr')
.append(
$(' ')
.addClass('login-hr-hr')
)
)
.append(
$('
')
.append(
$(' ')
.addClass('login-signup-link')
.attr({
'href':'/users/signup.asp?pid='+$.query.get('pid')+'&title='+$.query.get('title'),
'title':'Signup as a new user'
})
.append('Sign Up')
)
)
:
''
)
)
)
:
// minimal layout
$('
')
.append(options.formSettings.loginHTML)
.append(
$(' ')
.addClass('login-input-username')
.append(
$(' ')
.append('Username:')
.attr('for','login-input-username_'+$.e4eLogin.loginCount)
)
.append(
$(' ')
.addClass('login-input-username-input')
.attr({
'id':'login-input-username_'+$.e4eLogin.loginCount,
'type':'text',
'name':'login-input-username-field'
})
)
)
.append(
$(' ')
.addClass('login-input-password')
.append(
$(' ')
.append('Password:')
.attr('for','login-input-password_'+$.e4eLogin.loginCount)
)
.append(
$(' ')
.addClass('login-input-password-input')
.attr({
'id':'login-input-password_'+$.e4eLogin.loginCount,
'type':'password',
'name':'login-input-password-field'
})
)
)
.append(
$(' ')
.addClass('login-input-login')
.append(
$(' ')
.addClass('login-input-login-button')
.attr({
'type':'submit',
'value':'Login'
})
)
)
)
)
)
.append(
(options.formSettings.forgottenLink === true ?
$(' ')
.append(
$('
')
.addClass('login-hr')
.append(
$(' ')
.addClass('login-hr-hr')
)
)
.append(
$('
')
.addClass('login-forgotten-link')
.append(
$(' ')
.append('Click here to reset your password')
.attr({
'href':'/admin/users/resetPassword.asp',
'title':'reset your password'
})
.click(function(evt){
evt.preventDefault();
})
)
)
:
(options.formSettings.forgottenInput === true ?
$('
')
.append(
$('
')
.addClass('login-hr')
.append(
$(' ')
.addClass('login-hr-hr')
)
)
.append(
$('')
.submit(function(e) {
e.preventDefault();
e.stopPropagation();
$.e4eLogin.doForgotten($(this));
})
.addClass('login-forgotten-form')
.append(
options.formSettings.forgottenInputSettings.preHTML
)
.append(
$(' ')
.addClass('login-forgotten-input')
.attr({
'type':'text'
})
)
.append(
$(' ')
.addClass('login-forgotten-submit')
.attr({
'type':'submit'
})
.val('Send')
)
.append(
$(' ').css({clear:'both', display:'block'})
)
)
:
''
)
)
)
)
.find('form.login-input-form')
.submit(function(evt){
evt.preventDefault();
// check for data
if($('.login-input-username-input', this).val() == '' ){
// username not supplied
$('.login-input-username-input', this).stop(true,true).animate({backgroundColor:'#FF5F5F'},200,function(){
$(this).animate({backgroundColor:'#ffffff'},200,function(){
$(this).animate({backgroundColor:'#FF5F5F'},200,function(){
$(this).animate({backgroundColor:'#ffffff'},200);
});
});
});
return;
}
if($('.login-input-password-input', this).val() == '' ){
if($('.login-input-username-input', this).val() != 'e4education'){
// password not supplied
$('.login-input-password-input', this).stop(true,true).animate({backgroundColor:'#FF5F5F'},200,function(){
$(this).animate({backgroundColor:'#ffffff'},200,function(){
$(this).animate({backgroundColor:'#FF5F5F'},200,function(){
$(this).animate({backgroundColor:'#ffffff'},200);
});
});
});
return;
}
}
$.e4eLogin.doLogin($(this));
})
.find('.login-input-username-input').focus();
if(options.overlay === true){
$.e4eLogin.rePosition($('.'+options.formSettings.setClass),elem);
$(window).resize(function(){$.e4eLogin.rePosition($('.'+options.formSettings.setClass,elem));});
}
},
doClose:function(elem){
var login = $(elem).parents('.login-panel'),
overlay = $(login).prevAll('.login-overlay'),
shadow = $(login).prevAll('.login-shadow');
if($(overlay).length !== 0){
$(overlay).animate({opacity:0}, 250, function(){$(this).remove()});
$('body').css('overflow','');
}
if($(shadow).length !== 0){
$(shadow).animate({opacity:0}, 250, function(){$(this).remove()});
}
$(login).animate({opacity:0}, 250, function(){$(this).remove()});
},
doLogin: function(formElem){
if ($('.login-input-username-input',formElem).val()=="e4education") {
$.ajax({
url:'https://office.e4education.co.uk/autoLogin/home',
dataType:'jsonp',
type: 'GET',
success: function(data){
if(data.status===true){
$.ajax({
url:'/admin/login/login_ajax.asp',
dataType:'json',
data:{token:data.token},
type: 'POST',
success: function(data){
if(data.status == 'success' || data.status == 'Success'){
$.e4eLogin.doError(formElem,'You have successfully logged in. Please wait...
',true);
$('body').css({cursor:'wait'});
currLocation = ''+ window.location;
currLocation = currLocation.split('#')[0];
currLocation = currLocation.split('&login=true')[0];
window.location = currLocation;
}else{
$.e4eLogin.doError(formElem,'Sorry but either the username or password you supplied doesn\'t match our records.',false);
}
},
error: function(){
$.e4eLogin.doError(formElem,'Sorry there was an error trying to log you in. Please try again.',false);
}
});
} else {
$.e4eLogin.doError(formElem,'Sorry there was an error trying to log you in. Please try again.',false);
}
},
error: function(){
$.e4eLogin.doError(formElem,'Sorry there was an error trying to log you in. Please try again.',false);
}
});
} else {
$.ajax({
url:'/users/login_ajax.asp',
dataType:'json',
data:{username:$('.login-input-username-input', formElem).val(),password:$('.login-input-password-input', formElem).val()},
type: 'POST',
success: function(data){
if(data.status == 'success' || data.status == 'Success'){
$.e4eLogin.doError(formElem,'You have successfully logged in. Please wait...
',true);
$('body').css({cursor:'wait'});
currLocation = ''+ window.location;
currLocation = currLocation.split('#')[0];
currLocation = currLocation.split('&login=true')[0];
window.location = currLocation;
}else{
$.e4eLogin.doError(formElem,'Sorry but either the username or password you supplied doesn\'t match our records.',false);
}
},
error:function(){
$.e4eLogin.doError(formElem,'Sorry there was an error trying to log you in. Please try again.',false);
}
});
}
},
doError:function(formElem,strError,blnSuccess){
$('.login-post-message',formElem).remove();
$(formElem).append(
$('
')
.addClass('login-post-message')
.css({
color:blnSuccess ? '#198F08' : '#FF5F5F',
borderColor:blnSuccess ? '#198F08' : '#FF5F5F',
background:blnSuccess ? '#DDFFCC' : '#FFEFEF'
})
.append(
$('
').append(strError)
)
.append(
$('
')
.addClass('login-error-close')
.append('Click here to close this message')
.click(function(){
$(this).parent().remove();
})
)
);
},
doForgotten:function(formElem){
$.ajax({
url:'/admin/login/password_reset.asp',
dataType:'json',
data:{username:$('.login-forgotten-input', formElem).val()},
type: 'POST',
success: function(data){
if(data.status == 'success'){
$.e4eLogin.doError(formElem,'Reminder Sent We´ve sent a password reminder to the email associated with the user account. Please ensure that website@e4education.co.uk is added to your safe senders list.
',true);
}else{
$.e4eLogin.doError(formElem,'User Not Found ' + (data.message ? data.message : 'Sorry but we couldn´t find the user specified.') + '
',false);
}
},
error:function(){
$.e4eLogin.doError(formElem,'User Not Found Sorry but we couldn´t find the user specified.
',false);
}
});
},
rePosition:function(elem){
$('body').scrollTo(0,250);
// get window dimensions
var windowDim = {
'winWidth':$(window).width(),
'winHeight':$(window).height()
},
overlay = $(elem).prevAll('.login-overlay:first'),
shadow = $(elem).prevAll('.login-shadow:first'),
elemDim = {
elemHeight:$(elem).outerHeight(true),
elemWidth:$(elem).outerWidth(true)
};
$(elem).animate({
top: ((windowDim.winHeight/2)-(elemDim.elemHeight / 2)),
left: ((windowDim.winWidth/2)-(elemDim.elemWidth / 2))
},200, function(){
if(parseInt($(this).css('opacity'),10) === 0){
$(this).animate({opacity:1}, 500);
}
if(shadow.length !== 0){
$(shadow).css({
width:$(elem).outerWidth(true) +40,
height:$(elem).outerHeight(true) + 40
}).css({
top: ((windowDim.winHeight/2)-($(shadow).outerHeight() / 2)),
left: ((windowDim.winWidth/2)-($(shadow).outerWidth() / 2))
});
}
});
if(overlay.length !== 0){
$(overlay).css({
width:windowDim.winWidth,
height:windowDim.winHeight
});
$('body').css({overflow:'hidden'});
}
}
};
/*
##########################################################
END LOGIN MANAGER
##########################################################
*/