I have this example with javascript session that opens a modal in which I use the fancybox and Bootstrap:
- just need to create the image of the company:
/img/logo_empresa.png
- div de overlay with class:
.layer_overlay
- The div where the exit button will appear:
<div id="session_login"></div>
And put this script into HTML:
$(document).ready(function() {
$('.layer_overlay').hide();
if (!$.prototype.fancybox) {
$('<script></script>', {
type: 'text/javascript',
src: 'https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.js'
}).appendTo('head');
$('<link/>', {
rel: 'stylesheet',
type: 'text/css',
href: 'https://cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.min.css'
}).appendTo('head');
}
var modalLogin = {
pagina_atual:'index',
pg_adm:'administrador',
pg_user:'usuario',
tiposLogin : {
A:'Administrador',
U:'Usuário'
},
viewModal : function() {
var content = '<div id="hello" class="col-xs-12 col-md-12 col-sm-12 login-box">\
<img src="/img/logo_empresa.png" border="0" class="text-center responsive-image">\
<h1 class="page-heading">Selecione o tipo de acesso:</h1>\
<ul class="acessos">\
<li><a href="javascript:void(0);" id="A" data-adm="'+modalLogin.tiposLogin.A+'" class="session_select">Administrador</a></li>\
<li><a href="javascript:void(0);" id="U" data-adm="'+modalLogin.tiposLogin.U+'" class="session_select">Usuário</a></li>\
</ul>\
</div>';
$.fancybox.open([
{
type: 'inline',
autoScale: true,
minHeight: 30,
content: content,
closeBtn:false
}
], {
padding: 0
});
$('.layer_overlay').show();
},
mySession : function() {
return localStorage.getItem('login')
},
setSession : function(login) {
if (login == null) {
localStorage.setItem('login', null);
localStorage.removeItem('login');
localStorage.clear();
} else {
localStorage.setItem('login', login);
$('#session_login').html('<a href="javascript:void(0)" id="reset_session">Sair ('+localStorage.getItem('login')+')</a>')
}
},
closeModal : function() {
$('.fancybox-wrap').remove();
$('.layer_overlay').fadeOut('slow');
}
}
$(document).on('click','#reset_session', function() {
$('#session_login').html('');
modalLogin.setSession(null);
window.location.reload();
});
if (localStorage.getItem('login') == 'null' || localStorage.getItem('login') == null || localStorage.getItem('login') == undefined || !localStorage.getItem('login')) {
if (!!$.prototype.fancybox) {
modalLogin.viewModal();
$(document).on('click','.session_select', function() {
var login = $(this).data('login');
modalLogin.setSession(login);
if (login == modalLogin.tiposLogin.A) {
window.location.href=modalLogin.pg_adm;
} else if (login == modalLogin.tiposLogin.U) {
window.location.href=modalLogin.pg_user;
} else {
modalLogin.closeModal();
}
});
}
} else {
$('#session_login').html('<a href="javascript:void(0)" id="reset_session">Sair (Olá '+localStorage.getItem('adm')+'!)</a>')
}
});
I’ll give you a hint, but it’s up to you: On the first login, you let him select how to enter, then add a cookie and every time he enters, he’ll log in with that selected option, and you’ll display on the screen something like: You’ll enter as "User" (click here to change)... Something like that, so if the guy wants to change the login type, he just clicks on that link, you display the dropdown and it changes the login type.
– Rafael Withoeft
Why don’t you validate the level after login? Wouldn’t it be easier? Here I have a similar situation, I have 3 levels of access, I check the level and then load the page referring to the user level.
– Diego
I added an essential detail to the question: I don’t have access to the source code, that is, I can’t modify, only manipulate via browser. Thank you Diego and Rafael.
– David