var myDictionary = { fr : { 'An error occurred.' : 'Une erreur s\'est produite.', 'Choose Language' : 'Choisissez la langue', 'Close' : 'Fermer', 'Email' : 'Courriel', 'Get the code from the Twofa authenticator app on your mobile device and fill it in below.' : 'Obtenez le code de l\'application d\'authentification MFA sur votre appareil mobile et remplissez-le ci-dessous.', 'Invalid username, password or TFA code.' : 'Nom d\'utilisateur, mot de passe ou code MFA invalide.', 'Invalid username or password.' : 'Nom d\'utilisateur ou mot de passe invalide.', 'Login' : 'Connexion', 'Password' : 'Mot de passe', 'Sign In' : 'Se connecter', 'TFA Code' : 'Code MFA', 'Two Factor Authentication code' : 'Code d\'authentification à deux facteurs', 'Webmail Login' : 'Connexion à la messagerie Web', }, pt : { 'An error occurred.' : 'Um erro ocorreu.', 'Choose Language' : 'Escolher Idioma', 'Close' : 'Feche', 'Email' : 'Email', 'Get the code from the Twofa authenticator app on your mobile device and fill it in below.' : 'Obtenha o código do aplicativo autenticador MFA em seu dispositivo móvel e preencha-o abaixo.', 'Invalid username, password or TFA code.' : 'Nome de usuário, senha ou código inválidos.', 'Invalid username or password.' : 'Nome de usuário ou senha inválidos.', 'Login' : 'Login', 'Password' : 'Senha', 'Sign In' : 'Entrar', 'TFA Code' : 'Código MFA', 'Two Factor Authentication code' : 'Código de autenticação de dois fatores', 'Webmail Login' : 'Login do Webmail', }, es : { 'An error occurred.' : 'Ocurrió un error.', 'Choose Language' : 'Elegir idioma', 'Close' : 'Cerrar', 'Email' : 'Email', 'Get the code from the Twofa authenticator app on your mobile device and fill it in below.' : 'Obtenga el código de la aplicación de autenticación MFA en su dispositivo móvil y complételo a continuación.', 'Invalid username, password or TFA code.' : 'Usuario, contraseña o código invalido.', 'Invalid username or password.' : 'Usuario o contraseña invalido.', 'Login' : 'Login', 'Password' : 'Contraseña', 'Sign In' : 'Entrar', 'TFA Code' : 'Código MFA', 'Two Factor Authentication code' : 'Código de autenticación de dos factores', 'Webmail Login' : 'Inicio de sesión de correo web', }, it : { 'An error occurred.' : 'Si è verificato un errore.', 'Choose Language' : 'Scegli la lingua', 'Close' : 'Chiudere', 'Email' : 'Email', 'Get the code from the Twofa authenticator app on your mobile device and fill it in below.' : 'Ottieni il codice dall\'app di autenticazione MFA sul tuo dispositivo mobile e inseriscilo qui sotto.', 'Invalid username, password or TFA code.' : 'Nome utente, password o codice errati.', 'Invalid username or password.' : 'Nome utente o password errati.', 'Login' : 'Login', 'Password' : 'Parola d\'accesso', 'Sign In' : 'Accedi', 'TFA Code' : 'Codice MFA', 'Two Factor Authentication code' : 'Codice per l\'autenticazione a due fattori', 'Webmail Login' : 'Accesso webmail', }, id : { 'An error occurred.' : 'Terjadi kesalahan.', 'Choose Language' : 'Pilih bahasa', 'Close' : 'Menutup', 'Email' : 'Email', 'Get the code from the Twofa authenticator app on your mobile device and fill it in below.' : 'Dapatkan kode dari aplikasi autentikator TFA di perangkat seluler Anda dan isi di bawah ini.', 'Invalid username, password or TFA code.' : 'Nama pengguna, sandi, atau kode salah.', 'Invalid username or password.' : 'Nama pengguna atau kata sandi salah.', 'Login' : 'Gabung', 'Password' : 'Kata sandi', 'Sign In' : 'Masuk', 'TFA Code' : 'Kode TFA', 'Two Factor Authentication code' : 'Kode Otentikasi Dua Faktor', 'Webmail Login' : 'Masuk webmail', } } $.tr.dictionary(myDictionary); var username = '', domain = '', password = '', url = 'https://cp.emailarray.com/json.php'; function showLoginError(message) { var tr = $.tr.translator(); $('.alert-danger').text(tr(message)).show(); } function submitLogin(totp) { var failureMessage = totp === undefined ? 'Invalid username or password.' : 'Invalid username, password or TFA code.'; var fields = { action: 'publiclogin', username: username, domain: domain, password: password, totp: totp === undefined ? '' : totp }; function handleResponse(data) { if (data && data.returncode === 1 && typeof data.returndata === 'string') { if (data.returndata.startsWith('oex|')) { var webmailForm = $('#oexwebmail'); webmailForm.attr('action', 'https://' + data.returndata.slice(4)); webmailForm.find("input[name='username']").val(username + '@' + domain); webmailForm.find("input[name='password']").val(password); webmailForm.submit(); } else { loginToWebmail(data.returndata); } } else if (data && data.returncode === 2) { $('#2facode').val(''); $('#2faModal').modal('show'); } else { showLoginError(failureMessage); } } $.post(url, fields, null, 'json') .done(handleResponse) .fail(function(xhr) { // A missing second factor is still HTTP 401 in the public API. if (xhr.status === 401 && xhr.responseJSON && xhr.responseJSON.returncode === 2) { handleResponse(xhr.responseJSON); } else { showLoginError(xhr.status === 401 || xhr.status === 403 ? failureMessage : 'An error occurred.'); } }); } $('#loginForm').submit(function(event) { event.preventDefault(); $('.alert-danger').hide(); var $form = $(this); var email = $form.find("input[name='email']").val().split('@'); password = $form.find("input[name='password']").val(); username = email[0]; domain = email[1]; submitLogin(); }); $('#loginWithTFA').click(function() { $('.alert-danger').hide(); $('#2faModal').modal('hide'); submitLogin($('#2facode').val()); }); $( "#langSelect" ).change(function() { $.tr.language($(this).val().toLowerCase(), true); updateTranslation(); }); function updateTranslation() { var tr = $.tr.translator(); $('.trCode').attr('placeholder', tr('TFA Code')); $('.trEmail').attr('placeholder', tr('Email')); $('.trPassword').attr('placeholder', tr('Password')); $('.trLanguage').attr('data-placeholder', tr('Choose Language')); $('.tr').each(function(index) { $(this).html(tr( $(this).data('tr'))); }); }; function loginToWebmail(token) { $.post( url, { action:"generateWebmailToken", token: token }, null, 'json' ) .done(function( data ) { if (data.returncode ===1) { var webmailForm = $('#webmail'); webmailForm.attr('action', 'https://'+data.returndata.url); webmailForm.find("input[name='accessToken']" ).val(data.returndata.token); webmailForm.find("input[name='password']" ).val(password); webmailForm.submit(); } else { showLoginError('An error occurred.'); } }) .fail(function() { showLoginError('An error occurred.'); }); }