108 lines
5.0 KiB
JavaScript
108 lines
5.0 KiB
JavaScript
function init__SYSTEM_SAI_saimod_sys_login() {
|
|
//jqBootstrapValidation
|
|
$("#login_form input").not("[type=submit]").jqBootstrapValidation({
|
|
preventSubmit: true,
|
|
submitError: function($form, event, errors) {},
|
|
submitSuccess: function($form, event){
|
|
$.get(SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_login&action=login&username='+$('#bt_login_user').val()+'&password_sha='+$.sha1($('#bt_login_password').val())+'&password_md5='+$.md5($('#bt_login_password').val()), function (data) {
|
|
if(data == 1){
|
|
$('.help-block').html("Login successfull.</br>");
|
|
location.reload(true);
|
|
} else {
|
|
$('.help-block').html("Login not successfull.</br> User & Password combination wrong.")
|
|
}
|
|
});
|
|
event.preventDefault();
|
|
}
|
|
});
|
|
|
|
$("#logout_form input").not("[type=submit]").jqBootstrapValidation({
|
|
preventSubmit: true,
|
|
submitError: function($form, event, errors) {},
|
|
submitSuccess: function($form, event){
|
|
$.get(SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_login&action=logout', function (data) {
|
|
if(data == 1){
|
|
$('.help-block').html("Logout successfull.</br>");
|
|
location.reload(true);
|
|
} else {
|
|
$('.help-block').html("Logout not successfull.</br>")
|
|
}
|
|
});
|
|
event.preventDefault();
|
|
}
|
|
});
|
|
|
|
$.getJSON('./?module=user&action=area&getUserDetails=1', function(data){
|
|
$('#user_email_input').attr('value', data.email);
|
|
$('span#user_username').text(data.username);
|
|
$('span#user_email').text(data.email);
|
|
$('span#user_joindate').text(data.joindate);
|
|
$('span#user_last_active').text(new Date(data.last_active * 1000).toString('yyyy-MM-dd h:mm:ss'));
|
|
$('span#user_locale').text(data.locale);
|
|
});
|
|
|
|
$("#register_link").click(function(){
|
|
$('div#content-wrapper').load(SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_login&action=registerform');
|
|
});
|
|
|
|
$('#btn_user_registration_cancel').click(function(){
|
|
$('#site-content-wrapper').slideUp('slow');
|
|
site_content_is_visible = false;
|
|
showNavbarControls();
|
|
$('#navigation-left').children().children().removeClass('active');
|
|
$("#map-link").parent().attr('class', 'active');
|
|
});
|
|
|
|
|
|
//jqBootstrapValidation
|
|
$("#register_user_form input").not("[type=submit]").jqBootstrapValidation({
|
|
preventSubmit: true,
|
|
submitError: function (form, event, errors) {},
|
|
submitSuccess: function($form, event){
|
|
var username = document.getElementById('register_username').value;
|
|
var email = document.getElementById('register_email').value;
|
|
var password = document.getElementById('user_register_password2').value;
|
|
|
|
var select_locale = document.getElementById('register_locale_select');
|
|
var locale = "";
|
|
for (var i = 0; i < select_locale.options.length; i++) {
|
|
if(select_locale.options[i].selected ){
|
|
locale = select_locale.options[i].value;
|
|
}
|
|
}
|
|
|
|
|
|
$.ajax({
|
|
dataType: "json",
|
|
url: SAI_ENDPOINT+'sai_mod=.SYSTEM.SAI.saimod_sys_login&action=register&username='+username+'&password_sha='+$.sha1(password)+'&email='+email+'&locale='+locale,
|
|
data: null,
|
|
success: function (dataCreate) {
|
|
if(dataCreate.status === true){ // reload -> user will be loged in
|
|
window.location.href = location.href.replace(/#/g, "");
|
|
}else{ // show errors
|
|
var result = dataCreate.result;
|
|
var code = result.code;
|
|
var msg = result.message;
|
|
|
|
switch (code){
|
|
case 1: // username invalid
|
|
case 2: // username already exists
|
|
$('#register-help-block-username').html('<ul role="alert"><li><font color="red">'+msg+'</font></li></ul>');
|
|
break;
|
|
case 3: // invalid email
|
|
$('#register-help-block-email').html('<ul role="alert"><li><font color="red">'+msg+'</font></li></ul>');
|
|
break;
|
|
case 4: //registration failed
|
|
alert(msg);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
event.preventDefault();
|
|
}
|
|
});
|
|
}; |