Skip to content

Commit

Permalink
Update mobile.system
Browse files Browse the repository at this point in the history
Added mobile account switching logic
  • Loading branch information
tobychui committed Jul 9, 2023
1 parent 5c01df8 commit 604dccd
Showing 1 changed file with 148 additions and 3 deletions.
151 changes: 148 additions & 3 deletions src/web/mobile.system
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<script type="text/javascript" src="./script/applocale.js"></script>
<style>

document, body{
body{
height: 100%;
}
.themeColor{
Expand Down Expand Up @@ -367,6 +367,25 @@
.disabled{
pointer-events: none;
}

#alternativeAccountList{
padding-bottom: 0.6em;
}

.alternativeAccount{
padding-top: 0.6em !important;
padding-bottom: 0.6em !important;
margin: 0;

}

.alternativeAccount .usericon{
width: 35px !important;
}

.alternativeAccount .username{
font-weight: 400;
}
</style>
</head>
<body>
Expand Down Expand Up @@ -396,11 +415,21 @@
<img class="usericon" src="img/desktop/system_icon/user.svg">
</div>
<div class="content">
<dic class="author" id="username">User</dic>
<div class="text" id="usergroups">@user</div>
<dic class="author" id="username" style="font-weight: 600 !important;">User</dic>
<div class="text" id="usergroups" style="color: #616162;">@user</div>
</div>
</div>
</div>
<div class="ui divider"></div>
<div id="alternativeAccountList">

</div>
<div class="ui fluid basic button" style="" onclick="openSwitchAccountPanel(); toggleProfileInfo();">
<i class="ui blue user plus icon" style="margin-right: 0.6em;"></i> <span locale="account/switch/addAccount">Add another account</span>
</div>
<div id="signoutAllButton" style="margin-top: 0.6em; margin-bottom: 1.2em;" class="ui fluid basic black button" onclick="logoutAllAccounts();">
<i class="log out icon icon" style="margin-right: 0.6em;"></i> <span locale="account/switch/signoutAll">Sign-out all accounts</span>
</div>
<button locale="quickAccess/logout" onclick="logout();" class="ui basic blue mini button" style="position: absolute; top: 1em; right: 1em;">Logout</button>
<button onclick="toggleProfileInfo();" class="circular ui themecolor icon button" style="position: absolute; bottom: 0px; right: 0px; margin-bottom: -10px; margin-right: -10px; color: white;">
<i class="remove icon"></i>
Expand Down Expand Up @@ -1415,6 +1444,8 @@
if (data.UserIcon !== ""){
$(".usericon").attr("src",data.UserIcon);
}

listAllStoredAccounts();
}
});
}
Expand Down Expand Up @@ -1539,6 +1570,120 @@
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}

/*
Account switching functions
*/

function listAllStoredAccounts(){
$("#alternativeAccountList").empty();

//Request server side for the account pool
$.get("system/auth/u/list", function(data){
if (data.error != undefined){
$("#signoutAllButton").addClass('disabled');
$("#alternativeAccountList").append(`<div class="ui message">
<i class="ui green check circle icon"></i> ${applocale.getString("account/switch/noAlternative", "No other account stored on this browser")}
</div>`);
return;
}else{
if (data.length > 1){
data.forEach(function(account){
if (account.Username == userInfo.Username){
//Skip
return;
}

$.get("system/desktop/user?target=" + account.Username, function(data){
let userIcon = data.UserIcon;
if (userIcon == ""){
userIcon = "img/desktop/system_icon/user.svg"
}
$("#alternativeAccountList").append(`
<div class="alternativeAccount ${account.IsExpired?"expired":""}" acname="${account.Username}" onclick="switchAccount(this);">
<div class="ui header">
<img class="usericon" src="${userIcon}">
<div class="content" style="font-size: 95% !important;">
<span class="username">${account.Username}</span> ${(data.IsAdmin)?'<i style="margin-left: 0.4em; color: rgb(38, 50, 56);" class="small shield alternate icon themed text isAdminIcon"></i>':""}
<div class="sub header usergroup">${!account.IsExpired?"<i class='ui green check circle icon' style='margin-right: 0px;'></i> " + applocale.getString("account/switch/sessionValid", "Session Valid"):"<i class='ui red times circle icon' style='margin-right: 0px;'></i> " + applocale.getString("account/switch/sessionExpired", "Session Expired")}</div>
</div>
</div>
</div>
`);
});
});
$("#signoutAllButton").removeClass('disabled');
}else{
$("#signoutAllButton").addClass('disabled');
$("#alternativeAccountList").append(`<div class="ui message">
<i class="ui green check circle icon"></i> ${applocale.getString("account/switch/noAlternative", "No other account stored on this browser")}
</div>`);
return;
}
}
})
}

function switchAccount(object){
let targetUsername = $(object).attr("acname");
if (targetUsername == undefined || targetUsername == ""){
console.log("Unable to load username from element")
return;
}

//Check if it is expired
if ($(object).hasClass("expired")){
openSwitchAccountPanel();
return;
}

$.ajax({
url: "system/auth/u/switch",
data: {
"username": targetUsername,
},
success: function(data){
if (data.error != undefined){
alert(data.error);
}else{
window.location.reload();
}
}
})
}

function openSwitchAccountPanel(){
var uuid = newFloatWindow({
url: 'SystemAO/advance/switchAccount.html',
width: 470,
height: 680,
appicon: "SystemAO/desktop/img/account-switch.png",
title: "Switch Account"
});
}

function logoutAllAccounts(){
if (confirm(applocale.getString("account/switch/logout/confirm", "This will logout all other accounts from this browser. Confirm?"))){
$.ajax({
url: "system/auth/u/logoutAll",
success: function(data){
if (data.error != undefined){
alert(data.error);
}else{
//Reset the browser pool id
localStorage.removeItem("ao_acc");
listAllStoredAccounts();
toggleProfileInfo();
}
}
})
}
}

//mobile mode not support re-initialization. Refresh page.
function initDesktop(){
window.location.reload();
}

</script>
</body>
</html>

0 comments on commit 604dccd

Please sign in to comment.