Skip to content

Commit

Permalink
v0.0.1-alpha.6
Browse files Browse the repository at this point in the history
Fixed AuthManager sending incorrect client token to the auth endpoint.
Fixed minor issues with the validate selected function.
Fixed minor issue related to UI transitions.
Added account validations on startup and when account is switched.
Updated dependencies.
  • Loading branch information
dscalzi committed May 30, 2018
1 parent 5a692d9 commit daa6faa
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 68 deletions.
2 changes: 1 addition & 1 deletion app/assets/js/authmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Mojang = require('./mojang.js')
*/
exports.addAccount = async function(username, password){
try {
const session = await Mojang.authenticate(username, password, ConfigManager.getClientToken)
const session = await Mojang.authenticate(username, password, ConfigManager.getClientToken())
const ret = ConfigManager.addAuthAccount(session.selectedProfile.id, session.accessToken, username, session.selectedProfile.name)
ConfigManager.save()
return ret
Expand Down
2 changes: 2 additions & 0 deletions app/assets/js/scripts/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ loginButton.addEventListener('click', () => {
switchView(VIEWS.login, VIEWS.landing, 500, 500, () => {
loginUsername.value = ''
loginPassword.value = ''
$('.circle-loader').toggleClass('load-complete')
$('.checkmark').toggle()
loginLoading(false)
loginButton.innerHTML = loginButton.innerHTML.replace('SUCCESS', 'LOGIN')
formDisabled(false)
Expand Down
4 changes: 0 additions & 4 deletions app/assets/js/scripts/overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,8 @@ function populateServerListings(){
function populateAccountListings(){
const accountsObj = ConfigManager.getAuthAccounts()
const accounts = Array.from(Object.keys(accountsObj), v=>accountsObj[v]);
const selectedUUID = ConfigManager.getSelectedAccount().uuid
let htmlString = ``
for(let i=0; i<accounts.length; i++){
if(accounts[i].uuid === selectedUUID) {
continue
}
htmlString += `<button class="accountListing" uuid="${accounts[i].uuid}" ${i===0 ? 'selected' : ''}>
<img src="https://crafatar.com/renders/head/${accounts[i].uuid}?scale=2&default=MHF_Steve&overlay">
<div class="accountListingName">${accounts[i].displayName}</div>
Expand Down
53 changes: 30 additions & 23 deletions app/assets/js/scripts/uibinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ let fatalStartupError = false

// Mapping of each view to their container IDs.
const VIEWS = {
landing: 'landingContainer',
login: 'loginContainer',
settings: 'settingsContainer',
welcome: 'welcomeContainer'
landing: '#landingContainer',
login: '#loginContainer',
settings: '#settingsContainer',
welcome: '#welcomeContainer'
}

// The currently shown view container.
Expand All @@ -35,10 +35,10 @@ let currentView = VIEWS.landing
* fades in.
*/
function switchView(current, next, currentFadeTime = 500, nextFadeTime = 500, onCurrentFade = () => {}, onNextFade = () => {}){
currentView = current
$(`#${current}`).fadeOut(currentFadeTime, () => {
currentView = next
$(`${current}`).fadeOut(currentFadeTime, () => {
onCurrentFade()
$(`#${next}`).fadeIn(nextFadeTime, () => {
$(`${next}`).fadeIn(nextFadeTime, () => {
onNextFade()
})
})
Expand All @@ -61,12 +61,22 @@ function showMainUI(){
document.body.style.backgroundImage = `url('assets/images/backgrounds/${document.body.getAttribute('bkid')}.jpg')`
$('#main').show()

//validateSelectedAccount()
// If this is enabled in a development environment we'll get ratelimited.
// The relaunch frequency is usually far too high.
if(!isDev){
validateSelectedAccount().then((v) => {
if(v){
console.log('%c[AuthManager]', 'color: #209b07; font-weight: bold', 'Account access token validated.')
} else {
console.log('%c[AuthManager]', 'color: #a02d2a; font-weight: bold', 'Account access token is invalid.')
}
})
}

if(ConfigManager.isFirstLaunch()){
$('#welcomeContainer').fadeIn(1000)
$(VIEWS.welcome).fadeIn(1000)
} else {
$('#landingContainer').fadeIn(1000)
$(VIEWS.landing).fadeIn(1000)
}

setTimeout(() => {
Expand Down Expand Up @@ -123,10 +133,12 @@ async function validateSelectedAccount(){
if(selectedAcc != null){
const val = await AuthManager.validateSelected()
if(!val){
ConfigManager.removeAuthAccount(selectedAcc.uuid)
ConfigManager.save()
const accLen = Object.keys(ConfigManager.getAuthAccounts()).length
setOverlayContent(
'Failed to Refresh Login',
`We were unable to refresh the login for <strong>${selectedAcc.displayName}</strong>. Please ${accLen > 1 ? 'select another account or ' : ''} login again.`,
`We were unable to refresh the login for <strong>${selectedAcc.displayName}</strong>. Please ${accLen > 0 ? 'select another account or ' : ''} login again.`,
'Login',
'Select Another Account'
)
Expand All @@ -137,25 +149,20 @@ async function validateSelectedAccount(){
toggleOverlay(false)
})
setDismissHandler(() => {
if(accLen > 2){
if(accLen > 1){
prepareAccountSelectionList()
$('#overlayContent').fadeOut(250, () => {
$('#accountSelectContent').fadeIn(250)
})
} else {
const accountsObj = ConfigManager.getAuthAccounts()
const accounts = Array.from(Object.keys(accountsObj), v=>accountsObj[v]);
const selectedUUID = ConfigManager.getSelectedAccount().uuid
for(let i=0; i<accounts.length; i++){
if(accounts[i].uuid !== selectedUUID){
setSelectedAccount(accounts[i].uuid)
toggleOverlay(false)
validateSelectedAccount()
}
}
const accounts = Array.from(Object.keys(accountsObj), v => accountsObj[v]);
// This function validates the account switch.
setSelectedAccount(accounts[0].uuid)
toggleOverlay(false)
}
})
toggleOverlay(true, accLen > 1)
toggleOverlay(true, accLen > 0)
} else {
return true
}
Expand All @@ -174,7 +181,7 @@ function setSelectedAccount(uuid){
const authAcc = ConfigManager.setSelectedAccount(uuid)
ConfigManager.save()
updateSelectedAccount(authAcc)
//validateSelectedAccount()
validateSelectedAccount()
}

// Synchronous Listener
Expand Down
10 changes: 0 additions & 10 deletions app/login.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,4 @@
</form>
</div>
<script src="./assets/js/scripts/login.js"></script>
<!-- Will reuse this down the line, then it will be removed from this file. -->
<!--<div id="loginLoading">
<div id="loginLoadingContent">
<div id="loadSpinnerContainer">
<img id="loadCenterImage" src="assets/images/westeroscraftlogo1.png">
<img id="loadSpinnerImage" class="rotating" src="assets/images/westeroscraftlogo2.png">
</div>
<span id="loadDescText">LOGGING IN</span>
</div>
</div>-->
</div>
155 changes: 127 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit daa6faa

Please sign in to comment.