2014-10-21 08:42:02 -04:00
|
|
|
|
(function () {
|
|
|
|
|
|
|
|
|
|
function login(page, username, password) {
|
|
|
|
|
|
2015-05-13 00:55:19 -04:00
|
|
|
|
Dashboard.showModalLoadingMsg();
|
2014-10-21 08:42:02 -04:00
|
|
|
|
|
2015-12-14 10:43:03 -05:00
|
|
|
|
ConnectionManager.loginToConnect(username, password).then(function () {
|
2014-10-21 08:42:02 -04:00
|
|
|
|
|
2015-05-20 12:28:55 -04:00
|
|
|
|
Dashboard.hideModalLoadingMsg();
|
|
|
|
|
Dashboard.navigate('selectserver.html');
|
2014-10-21 08:42:02 -04:00
|
|
|
|
|
2015-12-14 10:43:03 -05:00
|
|
|
|
}, function () {
|
2014-10-25 14:32:58 -04:00
|
|
|
|
|
2015-05-15 11:46:20 -04:00
|
|
|
|
Dashboard.hideModalLoadingMsg();
|
2014-10-21 08:42:02 -04:00
|
|
|
|
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
message: Globalize.translate('MessageInvalidUser'),
|
|
|
|
|
title: Globalize.translate('HeaderLoginFailure')
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('#txtManualPassword', page).val('');
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-05 11:24:47 -04:00
|
|
|
|
function handleConnectionResult(page, result) {
|
|
|
|
|
|
2015-05-15 11:46:20 -04:00
|
|
|
|
Dashboard.hideModalLoadingMsg();
|
2015-05-13 00:55:19 -04:00
|
|
|
|
|
2015-05-05 11:24:47 -04:00
|
|
|
|
switch (result.State) {
|
|
|
|
|
|
|
|
|
|
case MediaBrowser.ConnectionState.SignedIn:
|
|
|
|
|
{
|
|
|
|
|
var apiClient = result.ApiClient;
|
|
|
|
|
|
2015-05-20 12:28:55 -04:00
|
|
|
|
Dashboard.onServerChanged(apiClient.getCurrentUserId(), apiClient.accessToken(), apiClient);
|
2016-03-16 01:33:31 -04:00
|
|
|
|
Dashboard.navigate('home.html');
|
2015-05-05 11:24:47 -04:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case MediaBrowser.ConnectionState.ServerSignIn:
|
|
|
|
|
{
|
2015-05-20 13:29:26 -04:00
|
|
|
|
Dashboard.navigate('login.html?serverid=' + result.Servers[0].Id, false, 'none');
|
2015-05-05 11:24:47 -04:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case MediaBrowser.ConnectionState.ServerSelection:
|
|
|
|
|
{
|
2015-05-20 13:29:26 -04:00
|
|
|
|
Dashboard.navigate('selectserver.html', false, 'none');
|
2015-05-05 11:24:47 -04:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case MediaBrowser.ConnectionState.ConnectSignIn:
|
|
|
|
|
{
|
|
|
|
|
loadMode(page, 'welcome');
|
|
|
|
|
}
|
|
|
|
|
break;
|
2016-02-21 17:17:38 -05:00
|
|
|
|
case MediaBrowser.ConnectionState.ServerUpdateNeeded:
|
|
|
|
|
{
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
message: Globalize.translate('ServerUpdateNeeded', '<a href="https://emby.media">https://emby.media</a>')
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
break;
|
2015-05-06 08:56:26 -04:00
|
|
|
|
case MediaBrowser.ConnectionState.Unavailable:
|
|
|
|
|
{
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
message: Globalize.translate("MessageUnableToConnectToServer"),
|
|
|
|
|
title: Globalize.translate("HeaderConnectionFailure")
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
break;
|
2015-05-05 11:24:47 -04:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadAppConnection(page) {
|
|
|
|
|
|
2015-05-13 00:55:19 -04:00
|
|
|
|
Dashboard.showModalLoadingMsg();
|
2015-05-05 11:24:47 -04:00
|
|
|
|
|
2015-12-14 10:43:03 -05:00
|
|
|
|
ConnectionManager.connect().then(function (result) {
|
2015-05-05 11:24:47 -04:00
|
|
|
|
|
|
|
|
|
handleConnectionResult(page, result);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadPage(page) {
|
|
|
|
|
|
2015-05-06 08:56:26 -04:00
|
|
|
|
var mode = getParameterByName('mode') || 'auto';
|
2015-05-05 11:24:47 -04:00
|
|
|
|
|
2015-05-06 08:56:26 -04:00
|
|
|
|
if (mode == 'auto') {
|
2015-05-05 11:24:47 -04:00
|
|
|
|
|
2015-05-28 19:37:43 -04:00
|
|
|
|
if (AppInfo.isNativeApp) {
|
2015-05-05 11:24:47 -04:00
|
|
|
|
loadAppConnection(page);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
mode = 'connect';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadMode(page, mode);
|
|
|
|
|
}
|
|
|
|
|
function loadMode(page, mode) {
|
|
|
|
|
|
|
|
|
|
if (mode == 'welcome') {
|
|
|
|
|
$('.connectLoginForm', page).hide();
|
|
|
|
|
$('.welcomeContainer', page).show();
|
|
|
|
|
$('.manualServerForm', page).hide();
|
2015-06-13 19:56:59 -04:00
|
|
|
|
$('.signupForm', page).hide();
|
2015-05-05 11:24:47 -04:00
|
|
|
|
}
|
|
|
|
|
else if (mode == 'connect') {
|
|
|
|
|
$('.connectLoginForm', page).show();
|
|
|
|
|
$('.welcomeContainer', page).hide();
|
|
|
|
|
$('.manualServerForm', page).hide();
|
2015-06-13 19:56:59 -04:00
|
|
|
|
$('.signupForm', page).hide();
|
2015-05-05 11:24:47 -04:00
|
|
|
|
}
|
|
|
|
|
else if (mode == 'manualserver') {
|
|
|
|
|
$('.manualServerForm', page).show();
|
|
|
|
|
$('.connectLoginForm', page).hide();
|
|
|
|
|
$('.welcomeContainer', page).hide();
|
2015-06-13 19:56:59 -04:00
|
|
|
|
$('.signupForm', page).hide();
|
|
|
|
|
}
|
|
|
|
|
else if (mode == 'signup') {
|
|
|
|
|
$('.manualServerForm', page).hide();
|
|
|
|
|
$('.connectLoginForm', page).hide();
|
|
|
|
|
$('.welcomeContainer', page).hide();
|
|
|
|
|
$('.signupForm', page).show();
|
2015-06-15 00:17:12 -04:00
|
|
|
|
initSignup(page);
|
2015-05-05 11:24:47 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-13 00:55:19 -04:00
|
|
|
|
function skip() {
|
|
|
|
|
|
|
|
|
|
Dashboard.navigate('selectserver.html');
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-19 15:15:40 -04:00
|
|
|
|
function onSubmit() {
|
|
|
|
|
var page = $(this).parents('.page');
|
|
|
|
|
|
|
|
|
|
submit(page);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function onManualServerSubmit() {
|
|
|
|
|
var page = $(this).parents('.page');
|
|
|
|
|
|
|
|
|
|
submitManualServer(page);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-13 19:56:59 -04:00
|
|
|
|
function onSignupFormSubmit() {
|
|
|
|
|
|
2015-06-15 00:17:12 -04:00
|
|
|
|
if (!supportInAppSignup()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-13 19:56:59 -04:00
|
|
|
|
var page = $(this).parents('.page');
|
|
|
|
|
|
2015-12-14 10:43:03 -05:00
|
|
|
|
ConnectionManager.signupForConnect($('#txtSignupEmail', page).val(), $('#txtSignupUsername', page).val(), $('#txtSignupPassword', page).val(), $('#txtSignupPasswordConfirm', page).val()).then(function () {
|
2015-06-13 19:56:59 -04:00
|
|
|
|
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
message: Globalize.translate('MessageThankYouForConnectSignUp'),
|
|
|
|
|
callback: function () {
|
|
|
|
|
Dashboard.navigate('connectlogin.html?mode=welcome');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2015-12-14 10:43:03 -05:00
|
|
|
|
}, function (result) {
|
2015-06-13 19:56:59 -04:00
|
|
|
|
|
|
|
|
|
if (result.errorCode == 'passwordmatch') {
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
message: Globalize.translate('ErrorMessagePasswordNotMatchConfirm')
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (result.errorCode == 'USERNAME_IN_USE') {
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
message: Globalize.translate('ErrorMessageUsernameInUse')
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else if (result.errorCode == 'EMAIL_IN_USE') {
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
message: Globalize.translate('ErrorMessageEmailInUse')
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
Dashboard.alert({
|
|
|
|
|
message: Globalize.translate('DefaultErrorMessage')
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-15 00:17:12 -04:00
|
|
|
|
function requireCaptcha() {
|
2015-12-14 10:43:03 -05:00
|
|
|
|
return !AppInfo.isNativeApp && window.location.href.toLowerCase().indexOf('https') == 0;
|
2015-06-15 00:17:12 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function supportInAppSignup() {
|
2015-12-14 12:10:42 -05:00
|
|
|
|
return AppInfo.isNativeApp;
|
2015-12-14 10:43:03 -05:00
|
|
|
|
return AppInfo.isNativeApp || window.location.href.toLowerCase().indexOf('https') == 0;
|
2015-06-15 00:17:12 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initSignup(page) {
|
|
|
|
|
|
|
|
|
|
if (!supportInAppSignup()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!requireCaptcha()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
require(['https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit'], function () {
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-01 10:01:59 -04:00
|
|
|
|
$(document).on('pageinit', "#connectLoginPage", function () {
|
2015-05-06 23:11:51 -04:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
2015-05-13 00:55:19 -04:00
|
|
|
|
$('.btnSkipConnect', page).on('click', function () {
|
|
|
|
|
skip();
|
2015-05-06 23:11:51 -04:00
|
|
|
|
});
|
|
|
|
|
|
2015-05-19 15:15:40 -04:00
|
|
|
|
$('.connectLoginForm').off('submit', onSubmit).on('submit', onSubmit);
|
|
|
|
|
$('.manualServerForm').off('submit', onManualServerSubmit).on('submit', onManualServerSubmit);
|
2015-06-13 19:56:59 -04:00
|
|
|
|
$('.signupForm').off('submit', onSignupFormSubmit).on('submit', onSignupFormSubmit);
|
2015-05-19 15:15:40 -04:00
|
|
|
|
|
2015-06-15 00:17:12 -04:00
|
|
|
|
$('.btnSignupForConnect', page).on('click', function () {
|
|
|
|
|
|
|
|
|
|
if (supportInAppSignup()) {
|
|
|
|
|
Dashboard.navigate('connectlogin.html?mode=signup');
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2015-06-16 00:52:01 -04:00
|
|
|
|
$('.btnCancelSignup', page).on('click', function () {
|
|
|
|
|
|
|
|
|
|
history.back();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnCancelManualServer', page).on('click', function () {
|
|
|
|
|
|
|
|
|
|
history.back();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.btnWelcomeNext', page).on('click', function () {
|
|
|
|
|
Dashboard.navigate('connectlogin.html?mode=connect');
|
|
|
|
|
});
|
|
|
|
|
|
2015-10-08 13:54:38 -04:00
|
|
|
|
var terms = page.querySelector('.terms');
|
|
|
|
|
terms.innerHTML = Globalize.translate('LoginDisclaimer') + "<div style='margin-top:5px;'><a href='http://emby.media/terms' target='_blank'>" + Globalize.translate('TermsOfUse') + "</a></div>";
|
|
|
|
|
|
|
|
|
|
if (AppInfo.isNativeApp) {
|
|
|
|
|
terms.classList.add('hide');
|
2016-02-29 11:23:30 -05:00
|
|
|
|
page.querySelector('.tvAppInfo').classList.add('hide');
|
2015-10-08 13:54:38 -04:00
|
|
|
|
} else {
|
|
|
|
|
terms.classList.remove('hide');
|
2016-02-29 11:23:30 -05:00
|
|
|
|
page.querySelector('.tvAppInfo').classList.remove('hide');
|
2015-10-08 13:54:38 -04:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-01 02:22:46 -04:00
|
|
|
|
}).on('pagebeforeshow', "#connectLoginPage", function () {
|
2015-05-05 11:24:47 -04:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
|
2015-06-13 19:56:59 -04:00
|
|
|
|
$('#txtSignupEmail', page).val('');
|
|
|
|
|
$('#txtSignupUsername', page).val('');
|
|
|
|
|
$('#txtSignupPassword', page).val('');
|
|
|
|
|
$('#txtSignupPasswordConfirm', page).val('');
|
2015-05-05 11:24:47 -04:00
|
|
|
|
|
2016-03-09 19:05:29 -05:00
|
|
|
|
if (browserInfo.safari && AppInfo.isNativeApp) {
|
|
|
|
|
// With apple we can't even have a link to the site
|
|
|
|
|
$('.embyIntroDownloadMessage', page).html(Globalize.translate('EmbyIntroDownloadMessageWithoutLink'));
|
|
|
|
|
} else {
|
|
|
|
|
var link = '<a href="http://emby.media" target="_blank">http://emby.media</a>';
|
|
|
|
|
$('.embyIntroDownloadMessage', page).html(Globalize.translate('EmbyIntroDownloadMessage', link));
|
|
|
|
|
}
|
2015-06-13 19:56:59 -04:00
|
|
|
|
|
2015-09-25 22:31:13 -04:00
|
|
|
|
}).on('pageshow', "#connectLoginPage", function () {
|
2015-06-13 19:56:59 -04:00
|
|
|
|
|
|
|
|
|
var page = this;
|
|
|
|
|
loadPage(page);
|
2015-05-05 11:24:47 -04:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function submitManualServer(page) {
|
|
|
|
|
|
|
|
|
|
var host = $('#txtServerHost', page).val();
|
|
|
|
|
var port = $('#txtServerPort', page).val();
|
|
|
|
|
|
|
|
|
|
if (port) {
|
|
|
|
|
host += ':' + port;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-13 00:55:19 -04:00
|
|
|
|
Dashboard.showModalLoadingMsg();
|
2015-05-05 11:24:47 -04:00
|
|
|
|
|
2015-12-14 10:43:03 -05:00
|
|
|
|
ConnectionManager.connectToAddress(host).then(function (result) {
|
2015-05-05 11:24:47 -04:00
|
|
|
|
|
|
|
|
|
handleConnectionResult(page, result);
|
|
|
|
|
|
2015-12-14 10:43:03 -05:00
|
|
|
|
}, function () {
|
2015-05-06 08:56:26 -04:00
|
|
|
|
handleConnectionResult(page, {
|
|
|
|
|
State: MediaBrowser.ConnectionState.Unavailable
|
|
|
|
|
});
|
|
|
|
|
|
2015-05-05 11:24:47 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-21 08:42:02 -04:00
|
|
|
|
function submit(page) {
|
|
|
|
|
|
|
|
|
|
var user = $('#txtManualName', page).val();
|
|
|
|
|
var password = $('#txtManualPassword', page).val();
|
|
|
|
|
|
|
|
|
|
login(page, user, password);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})();
|