ソースを参照

Added desktop acc switch func

tobychui 2 年 前
コミット
fda7d9ce11
3 ファイル変更42 行追加12 行削除
  1. 28 0
      mod/auth/accountSwitch.go
  2. 3 0
      mod/auth/auth.go
  3. 11 12
      web/desktop.system

+ 28 - 0
mod/auth/accountSwitch.go

@@ -245,6 +245,21 @@ func (m *SwitchableAccountPoolManager) GetPoolByID(uuid string) (*SwitchableAcco
 	return &targetPool, nil
 }
 
+// Remove user from all switch pool, which should be called when a user is logged out or removed
+func (p *SwitchableAccountPoolManager) RemoveUserFromAllSwitchableAccountPool(username string) error {
+	allAccountPool, err := p.GetAllPools()
+	if err != nil {
+		return err
+	}
+	for _, accountPool := range allAccountPool {
+		if accountPool.IsAccessibleBy(username) {
+			//aka this user is in the pool
+			accountPool.RemoveUser(username)
+		}
+	}
+	return nil
+}
+
 /*
 	Switachable Account Pool functions
 */
@@ -308,6 +323,19 @@ func (p *SwitchableAccountsPool) UpdateUserPoolAccountInfo(username string) {
 	}
 }
 
+// Remove a user from the pool
+func (p *SwitchableAccountsPool) RemoveUser(username string) {
+	newAccountList := []*SwitchableAccount{}
+	for _, acc := range p.Accounts {
+		if acc.Username != username {
+			newAccountList = append(newAccountList, acc)
+		}
+	}
+
+	p.Accounts = newAccountList
+	p.Save()
+}
+
 // Save changes of this pool to database
 func (p *SwitchableAccountsPool) Save() {
 	p.parent.Database.Write("auth_acswitch", p.UUID, p)

+ 3 - 0
mod/auth/auth.go

@@ -477,6 +477,9 @@ func (a *AuthAgent) UnregisterUser(username string) error {
 
 	//Remove the user's autologin tokens
 	a.RemoveAutologinTokenByUsername(username)
+
+	//Remove user from switchable accounts
+	a.SwitchableAccountManager.RemoveUserFromAllSwitchableAccountPool(username)
 	return nil
 }
 

+ 11 - 12
web/desktop.system

@@ -740,6 +740,9 @@
             right:4px;
             z-index:114;
             width:300px;
+            max-height: calc(100% - 100px);
+            overflow-y: auto;
+            scrollbar-width: thin;
             border-radius: 10px;
             border-top-right-radius: 0px;
             border-top-left-radius: 0px;
@@ -1661,7 +1664,7 @@
             });
         }
 
-        function initDesktopUserInfo(){
+        function initDesktopUserInfo(callback=undefined){
             $.get("system/desktop/user", function(data){
                 if (data.error !== undefined){
                     alert(data.error);
@@ -1684,6 +1687,10 @@
                         //User is admin. Add admin icon
                         $("#username").append(`<i style="margin-left: 0.4em; color: #${desktopThemeColor}" class="small shield alternate icon themed text"></i>`);
                     }
+
+                    if (callback != undefined){
+                        callback();
+                    }
                 }
             });
         }
@@ -7305,8 +7312,6 @@
         }
 
         function switchAccount(object){
-            alert("WIP")
-            return;
             let targetUsername = $(object).attr("acname");
             if (targetUsername == undefined || targetUsername == ""){
                 console.log("Unable to load username from element")
@@ -7324,19 +7329,13 @@
                 url: "system/auth/u/switch",
                 data: {
                     "username": targetUsername,
-                    "pid": browserAccountPoolUUID,
+                    "pid": getBrowserAccountPoolUUID(),
                 },
                 success: function(data){
                     if (data.error != undefined){
-                        showError(data.error);
+                        alert(data.error);
                     }else{
-                        hideError();
-                        initCurrentAccountInfo(function(){
-                            listAllStoredAccounts();
-                            if(ao_module_virtualDesktop){
-                                parent.initDesktop();
-                            }
-                        });
+                        initDesktop();
                     }
                 }
             })