diff --git a/app/app.ejs b/app/app.ejs index 75b5ea2..edac3f9 100644 --- a/app/app.ejs +++ b/app/app.ejs @@ -33,6 +33,7 @@ <%- include('login') %> <%- include('waiting') %> <%- include('loginOptions') %> + <%- include('loginOffline') %> <%- include('settings') %> <%- include('landing') %> diff --git a/app/assets/js/authmanager.js b/app/assets/js/authmanager.js index 3f43144..2dd5791 100644 --- a/app/assets/js/authmanager.js +++ b/app/assets/js/authmanager.js @@ -57,6 +57,11 @@ exports.addMojangAccount = async function(username, password) { } } +exports.addOfflineAccount = async function(usernameOffline){ + //TODO: check for forbidden symbols and lenght!! + ConfigManager.addOfflineAccount(usernameOffline) +} + const AUTH_MODE = { FULL: 0, MS_REFRESH: 1, MC_REFRESH: 2 } /** diff --git a/app/assets/js/configmanager.js b/app/assets/js/configmanager.js index 38f864f..6299ff5 100644 --- a/app/assets/js/configmanager.js +++ b/app/assets/js/configmanager.js @@ -349,6 +349,22 @@ exports.addMojangAuthAccount = function(uuid, accessToken, username, displayName return config.authenticationDatabase[uuid] } +exports.addOfflineAccount = function(usernameOffline){ + console.log("pizda") + fake_uuid = usernameOffline + config.selectedAccount = fake_uuid + accessToken = "" + config.authenticationDatabase[fake_uuid] = { + type: 'offline', + accessToken, + username: usernameOffline.trim(), + uuid: fake_uuid.trim(), + displayName: usernameOffline.trim() + } + return config.authenticationDatabase[fake_uuid] +} + + /** * Update the tokens of an authenticated microsoft account. * diff --git a/app/assets/js/scripts/loginOffline.js b/app/assets/js/scripts/loginOffline.js new file mode 100644 index 0000000..c08d0f6 --- /dev/null +++ b/app/assets/js/scripts/loginOffline.js @@ -0,0 +1,39 @@ +//const loggerOfflineLogin = LoggerUtil1('%c[LoginOffline]', 'color: #000668; font-weight: bold') + +const loginOfflineButton = document.getElementById('loginOfflineButton') +const loginOfflineCancelContainer = document.getElementById('loginOfflineCancelContainer') +const loginOfflineCancelButton = document.getElementById('loginOfflineCancelButton') + +function loginOfflineDisabled(v){ + if(loginOfflineButton.disabled !== v){ + loginOfflineButton.disabled = v + } +} + +function formOfflineDisabled(v){ + loginOfflineDisabled(v) + loginOfflineUsername.disabled = v +} + + + +loginOfflineButton.addEventListener('click', () => { + formOfflineDisabled(true) + AuthManager.addOfflineAccount(loginOfflineUsername.value).then((value) =>{ + switchView(VIEWS.loginOffline, VIEWS.landing, 500, 500) + + }) + loginOfflineUsername = '' +}) + +loginOfflineCancelButton.addEventListener('click', () => { + if (Object.keys(ConfigManager.getAuthAccounts()).length === 0) { + loginOfflineUsername.value = '' + switchView(VIEWS.loginOffline, VIEWS.loginOptions, 500, 500) + } + else + { + loginOfflineUsername.value = '' + switchView(VIEWS.loginOffline, VIEWS.landing, 500, 500) + } +}) \ No newline at end of file diff --git a/app/assets/js/scripts/loginOptions.js b/app/assets/js/scripts/loginOptions.js index cdb1bc8..678f158 100644 --- a/app/assets/js/scripts/loginOptions.js +++ b/app/assets/js/scripts/loginOptions.js @@ -1,6 +1,7 @@ const loginOptionsCancelContainer = document.getElementById('loginOptionCancelContainer') const loginOptionMicrosoft = document.getElementById('loginOptionMicrosoft') const loginOptionMojang = document.getElementById('loginOptionMojang') +const loginOptionOffline = document.getElementById('loginOptionOffline') const loginOptionsCancelButton = document.getElementById('loginOptionCancelButton') let loginOptionsCancellable = false @@ -36,6 +37,15 @@ loginOptionMojang.onclick = (e) => { }) } + +loginOptionOffline.onclick = (e) => { + switchView(getCurrentView(), VIEWS.loginOffline, 500, 500, () => { + loginViewOnSuccess = loginOptionsViewOnLoginSuccess + loginViewOnCancel = loginOptionsViewOnLoginCancel + loginCancelEnabled(true) + }) +} + loginOptionsCancelButton.onclick = (e) => { switchView(getCurrentView(), loginOptionsViewOnCancel, 500, 500, () => { // Clear login values (Mojang login) diff --git a/app/assets/js/scripts/uibinder.js b/app/assets/js/scripts/uibinder.js index 5fe79df..fc7d7cf 100644 --- a/app/assets/js/scripts/uibinder.js +++ b/app/assets/js/scripts/uibinder.js @@ -18,6 +18,7 @@ const VIEWS = { landing: '#landingContainer', loginOptions: '#loginOptionsContainer', login: '#loginContainer', + loginOffline: '#loginOfflineContainer', settings: '#settingsContainer', welcome: '#welcomeContainer', waiting: '#waitingContainer' diff --git a/app/loginOffline.ejs b/app/loginOffline.ejs new file mode 100644 index 0000000..2abc925 --- /dev/null +++ b/app/loginOffline.ejs @@ -0,0 +1,31 @@ +
\ No newline at end of file diff --git a/app/loginOptions.ejs b/app/loginOptions.ejs index 20aa67c..6f258af 100644 --- a/app/loginOptions.ejs +++ b/app/loginOptions.ejs @@ -24,6 +24,17 @@ <%- lang('loginOptions.loginWithMojang') %> +