feat(webui): rename account (#616)
This commit is contained in:
		
							parent
							
								
									0a4d620652
								
							
						
					
					
						commit
						9be89fa9b7
					
				
							
								
								
									
										13
									
								
								src/controllers/custom/renameAccountController.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								src/controllers/custom/renameAccountController.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
import { getAccountForRequest } from "@/src/services/loginService";
 | 
			
		||||
 | 
			
		||||
export const renameAccountController: RequestHandler = async (req, res) => {
 | 
			
		||||
    const account = await getAccountForRequest(req);
 | 
			
		||||
    if (typeof req.query.newname == "string") {
 | 
			
		||||
        account.DisplayName = req.query.newname;
 | 
			
		||||
        await account.save();
 | 
			
		||||
        res.end();
 | 
			
		||||
    } else {
 | 
			
		||||
        res.status(400).end();
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
@ -5,6 +5,7 @@ import { getItemListsController } from "@/src/controllers/custom/getItemListsCon
 | 
			
		||||
import { pushArchonCrystalUpgradeController } from "@/src/controllers/custom/pushArchonCrystalUpgradeController";
 | 
			
		||||
import { popArchonCrystalUpgradeController } from "@/src/controllers/custom/popArchonCrystalUpgradeController";
 | 
			
		||||
import { deleteAccountController } from "@/src/controllers/custom/deleteAccountController";
 | 
			
		||||
import { renameAccountController } from "@/src/controllers/custom/renameAccountController";
 | 
			
		||||
 | 
			
		||||
import { createAccountController } from "@/src/controllers/custom/createAccountController";
 | 
			
		||||
import { addItemController } from "@/src/controllers/custom/addItemController";
 | 
			
		||||
@ -19,6 +20,7 @@ customRouter.get("/getItemLists", getItemListsController);
 | 
			
		||||
customRouter.get("/pushArchonCrystalUpgrade", pushArchonCrystalUpgradeController);
 | 
			
		||||
customRouter.get("/popArchonCrystalUpgrade", popArchonCrystalUpgradeController);
 | 
			
		||||
customRouter.get("/deleteAccount", deleteAccountController);
 | 
			
		||||
customRouter.get("/renameAccount", renameAccountController);
 | 
			
		||||
 | 
			
		||||
customRouter.post("/createAccount", createAccountController);
 | 
			
		||||
customRouter.post("/addItem", addItemController);
 | 
			
		||||
 | 
			
		||||
@ -39,7 +39,8 @@
 | 
			
		||||
                    <ul class="dropdown-menu dropdown-menu-end">
 | 
			
		||||
                        <li><a class="dropdown-item" href="/webui/" onclick="logout();">Logout</a></li>
 | 
			
		||||
                        <li><hr class="dropdown-divider"></li>
 | 
			
		||||
                        <li><a class="dropdown-item" onclick="deleteAccount();">Delete Account</a></li>
 | 
			
		||||
                        <li><a class="dropdown-item" href="#" onclick="event.preventDefault();renameAccount();">Rename Account</a></li>
 | 
			
		||||
                        <li><a class="dropdown-item" href="#" onclick="event.preventDefault();deleteAccount();">Delete Account</a></li>
 | 
			
		||||
                    </ul>
 | 
			
		||||
                </li>
 | 
			
		||||
            </ul>
 | 
			
		||||
 | 
			
		||||
@ -61,6 +61,15 @@ function logout() {
 | 
			
		||||
    localStorage.removeItem("password");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function renameAccount() {
 | 
			
		||||
    const newname = window.prompt("What would you like to change your account name to?");
 | 
			
		||||
    if (newname) {
 | 
			
		||||
        fetch("/custom/renameAccount?" + window.authz + "&newname=" + newname).then(() => {
 | 
			
		||||
            $(".displayname").text(newname);
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function deleteAccount() {
 | 
			
		||||
    if (
 | 
			
		||||
        window.confirm(
 | 
			
		||||
@ -71,7 +80,7 @@ function deleteAccount() {
 | 
			
		||||
                ")? This action cannot be undone."
 | 
			
		||||
        )
 | 
			
		||||
    ) {
 | 
			
		||||
        fetch("/custom/deleteAccount?" + window.authz).then(function () {
 | 
			
		||||
        fetch("/custom/deleteAccount?" + window.authz).then(() => {
 | 
			
		||||
            logout();
 | 
			
		||||
            single.loadRoute("/webui/"); // Show login screen
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user