working offline accounts

This commit is contained in:
cyber-dream 2022-07-31 07:15:50 +03:00
parent 9d37b49c79
commit 1330e01484
4 changed files with 55 additions and 7 deletions

View File

@ -59,7 +59,8 @@ exports.addMojangAccount = async function(username, password) {
}
exports.addOfflineAccount = async function(usernameOffline){
ConfigManager.addOfflineAccount('0456456413213', '-', "Megatraher")
//TODO: check for forbidden symbols and lenght!!
ConfigManager.addOfflineAccount(usernameOffline)
}
const AUTH_MODE = { FULL: 0, MS_REFRESH: 1, MC_REFRESH: 2 }
@ -186,6 +187,17 @@ exports.removeMojangAccount = async function(uuid){
}
}
exports.removeOfflineAccount = async function(uuid){
try {
ConfigManager.removeAuthAccount(uuid)
ConfigManager.save()
return Promise.resolve()
} catch (err){
log.error('Error while removing account', err)
return Promise.reject(err)
}
}
/**
* Remove a Microsoft account. It is expected that the caller will invoke the OAuth logout
* through the ipc renderer.

View File

@ -1,3 +1,4 @@
const { uuid } = require('discord-rpc-patch/src/util')
const fs = require('fs-extra')
const os = require('os')
const path = require('path')
@ -353,16 +354,18 @@ exports.addMojangAuthAccount = function(uuid, accessToken, username, displayName
return config.authenticationDatabase[uuid]
}
exports.addOfflineAccount = function(uuid, accessToken, usernameOffline){
config.selectedAccount = uuid
config.authenticationDatabase[uuid] = {
exports.addOfflineAccount = function(usernameOffline){
fake_uuid = usernameOffline
config.selectedAccount = fake_uuid
accessToken = ""
config.authenticationDatabase[fake_uuid] = {
type: 'offline',
accessToken,
username: usernameOffline.trim(),
uuid: uuid.trim(),
uuid: fake_uuid.trim(),
displayName: usernameOffline.trim()
}
return config.authenticationDatabase[uuid]
return config.authenticationDatabase[fake_uuid]
}
/**
* Update the tokens of an authenticated microsoft account.

View File

@ -331,6 +331,14 @@ document.getElementById('settingsAddMojangAccount').onclick = (e) => {
})
}
document.getElementById('settingsAddOfflineAccount').onclick = (e) => {
switchView(getCurrentView(), VIEWS.loginOffline, 500, 500, () => {
loginViewOnCancel = VIEWS.settings
loginViewOnSuccess = VIEWS.settings
loginCancelEnabled(true)
})
}
// Bind the add microsoft account button.
document.getElementById('settingsAddMicrosoftAccount').onclick = (e) => {
switchView(getCurrentView(), VIEWS.waiting, 500, 500, () => {
@ -501,6 +509,24 @@ function processLogOut(val, isLastAccount){
switchView(getCurrentView(), VIEWS.waiting, 500, 500, () => {
ipcRenderer.send(MSFT_OPCODE.OPEN_LOGOUT, uuid, isLastAccount)
})
} if(targetAcc.type === 'offline') {
AuthManager.removeOfflineAccount(uuid).then(() => {
if(!isLastAccount && uuid === prevSelAcc.uuid){
const selAcc = ConfigManager.getSelectedAccount()
refreshAuthAccountSelected(selAcc.uuid)
updateSelectedAccount(selAcc)
//validateSelectedAccount()
}
if(isLastAccount) {
loginOptionsCancelEnabled(false)
loginOptionsViewOnLoginSuccess = VIEWS.settings
loginOptionsViewOnLoginCancel = VIEWS.loginOptions
switchView(getCurrentView(), VIEWS.loginOptions)
}
})
$(parent).fadeOut(250, () => {
parent.remove()
})
} else {
AuthManager.removeMojangAccount(uuid).then(() => {
if(!isLastAccount && uuid === prevSelAcc.uuid){
@ -603,6 +629,7 @@ function refreshAuthAccountSelected(uuid){
const settingsCurrentMicrosoftAccounts = document.getElementById('settingsCurrentMicrosoftAccounts')
const settingsCurrentMojangAccounts = document.getElementById('settingsCurrentMojangAccounts')
const settingsCurrentOfflineAccounts = document.getElementById('settingsCurrentOfflineAccounts')
/**
* Add auth account elements for each one stored in the authentication database.
@ -617,6 +644,7 @@ function populateAuthAccounts(){
let microsoftAuthAccountStr = ''
let mojangAuthAccountStr = ''
let offlineAuthAccountStr = ''
authKeys.forEach((val) => {
const acc = authAccounts[val]
@ -647,6 +675,8 @@ function populateAuthAccounts(){
if(acc.type === 'microsoft') {
microsoftAuthAccountStr += accHtml
} if (acc.type === 'offline') {
offlineAuthAccountStr += accHtml
} else {
mojangAuthAccountStr += accHtml
}
@ -655,6 +685,7 @@ function populateAuthAccounts(){
settingsCurrentMicrosoftAccounts.innerHTML = microsoftAuthAccountStr
settingsCurrentMojangAccounts.innerHTML = mojangAuthAccountStr
settingsCurrentOfflineAccounts.innerHTML = offlineAuthAccountStr
}
/**

View File

@ -410,7 +410,9 @@ function setSelectedAccount(uuid){
const authAcc = ConfigManager.setSelectedAccount(uuid)
ConfigManager.save()
updateSelectedAccount(authAcc)
validateSelectedAccount()
if (ConfigManager.getAuthAccounts[uuid].type !== 'offline'){
validateSelectedAccount()
}
}
// Synchronous Listener