Stable offline mode

This commit is contained in:
cyber-dream 2023-12-30 02:34:48 +03:00
parent 258cd0d421
commit 30e635a3b9
8 changed files with 114 additions and 0 deletions

View File

@ -33,6 +33,7 @@
<%- include('login') %>
<%- include('waiting') %>
<%- include('loginOptions') %>
<%- include('loginOffline') %>
<%- include('settings') %>
<%- include('landing') %>
</div>

View File

@ -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 }
/**

View File

@ -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.
*

View File

@ -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)
}
})

View File

@ -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)

View File

@ -18,6 +18,7 @@ const VIEWS = {
landing: '#landingContainer',
loginOptions: '#loginOptionsContainer',
login: '#loginContainer',
loginOffline: '#loginOfflineContainer',
settings: '#settingsContainer',
welcome: '#welcomeContainer',
waiting: '#waitingContainer'

31
app/loginOffline.ejs Normal file
View File

@ -0,0 +1,31 @@
<div id="loginOfflineContainer" style="display: none;">
<div id="loginOfflineCancelContainer" > <!--Delete style="" as temp fix-->
<button id="loginOfflineCancelButton">
<div id="loginOfflineCancelIcon">X</div>
<span id="loginOfflineCancelText">Cancel</span>
</button>
</div>
<div id="loginContent">
<form id="loginForm" style="margin-top: 2.5em;">
<span id="loginSubheader">OFFLINE LOGIN</span>
<div class="loginFieldContainer">
<input id="loginOfflineUsername" class="loginField" type="text" placeholder="USERNAME"/>
</div>
<button id="loginOfflineButton" class="loginButton" enabled>
<div id="loginOfflineButtonContent">
LOGIN
<svg id="loginSVG" viewBox="0 0 24.87 13.97">
<defs>
<style>.arrowLine{fill:none;stroke:#FFF;stroke-width:2px;transition: 0.25s ease;}</style>
</defs>
<polyline class="arrowLine" points="0.71 13.26 12.56 1.41 24.16 13.02"/>
</svg>
<div class="circle-loader">
<div class="checkmark draw"></div>
</div>
</div>
</button>
</form>
</div>
<script src="./assets/js/scripts/loginOffline.js"></script>
</div>

View File

@ -24,6 +24,17 @@
<span><%- lang('loginOptions.loginWithMojang') %></span>
</button>
</div>
<div class="loginOptionButtonContainer">
<button id="loginOptionOffline" class="loginOptionButton">
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 9.677 9.667">
<path d="M-26.332-12.098h2.715c-1.357.18-2.574 1.23-2.715 2.633z" fill="#fff" />
<path d="M2.598.022h7.07L9.665 7c-.003 1.334-1.113 2.46-2.402 2.654H0V2.542C.134 1.2 1.3.195 2.598.022z" fill="#db2331" />
<path d="M1.54 2.844c.314-.76 1.31-.46 1.954-.528.785-.083 1.503.272 2.1.758l.164-.9c.327.345.587.756.964 1.052.28.254.655-.342.86-.013.42.864.408 1.86.54 2.795l-.788-.373C6.9 4.17 5.126 3.052 3.656 3.685c-1.294.592-1.156 2.65.06 3.255 1.354.703 2.953.51 4.405.292-.07.42-.34.87-.834.816l-4.95.002c-.5.055-.886-.413-.838-.89l.04-4.315z" fill="#fff" />
</svg>
<!-- <span><%- lang('loginOptions.loginWithMojang') %></span> -->
<span>Offline</span>
</button>
</div>
</div>
<div id="loginOptionCancelContainer" style="display: none;">
<button id="loginOptionCancelButton"><%- lang('loginOptions.cancelButton') %></button>