[WIP] Feat: create/get user public/private key
This commit is contained in:
		@@ -314,7 +314,7 @@ header("Allow: GET, POST, OPTIONS, PUT, DELETE");
 | 
			
		||||
            document.getElementById('loginModal').style.display = 'none';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        function login() {
 | 
			
		||||
        async function login() {
 | 
			
		||||
            var username = document.getElementById('username').value;
 | 
			
		||||
            var password = document.getElementById('password').value;
 | 
			
		||||
            const url = DEVSTAR_HOME + `/api/v1/users/${username}/tokens`;
 | 
			
		||||
@@ -343,7 +343,7 @@ header("Allow: GET, POST, OPTIONS, PUT, DELETE");
 | 
			
		||||
                }
 | 
			
		||||
                return response.json();
 | 
			
		||||
            })
 | 
			
		||||
            .then(data => {
 | 
			
		||||
            .then(async data => {
 | 
			
		||||
                // store token in global variable and vscode global state
 | 
			
		||||
                USERTOKEN = data.sha1;
 | 
			
		||||
                USERNAME = username;
 | 
			
		||||
@@ -351,6 +351,21 @@ header("Allow: GET, POST, OPTIONS, PUT, DELETE");
 | 
			
		||||
                setUsernameToVSCode(username);
 | 
			
		||||
                loadPageModules()
 | 
			
		||||
 | 
			
		||||
                // if user public key exist, meaning that public key has been uploaded
 | 
			
		||||
                await getUserPublicKeyFromVSCode()
 | 
			
		||||
                .then(async userPublicKey => {
 | 
			
		||||
                    if (userPublicKey == '') {
 | 
			
		||||
                        await createUserPublicKeyByVSCode()
 | 
			
		||||
                        await getUserPublicKeyFromVSCode()
 | 
			
		||||
                        .then(async userPublicKey => {
 | 
			
		||||
                            // upload new created public key
 | 
			
		||||
                            
 | 
			
		||||
                        })
 | 
			
		||||
 | 
			
		||||
                    } 
 | 
			
		||||
                })
 | 
			
		||||
                
 | 
			
		||||
 | 
			
		||||
                closeLoginModal()
 | 
			
		||||
            })
 | 
			
		||||
            .catch(error => {
 | 
			
		||||
@@ -418,6 +433,33 @@ header("Allow: GET, POST, OPTIONS, PUT, DELETE");
 | 
			
		||||
            })
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        async function getUserPublicKeyFromVSCode() {
 | 
			
		||||
            return new Promise(async (resolve, reject) => {
 | 
			
		||||
                await communicateVSCodeByWebview('getUserPublicKey', {})
 | 
			
		||||
                .then(data => {
 | 
			
		||||
                    const publicKey = data.userPublicKey;
 | 
			
		||||
                    resolve(publicKey)
 | 
			
		||||
                })
 | 
			
		||||
                .catch(error => {
 | 
			
		||||
                    reject(error)
 | 
			
		||||
                })
 | 
			
		||||
            })
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        async function createUserPublicKeyByVSCode() {
 | 
			
		||||
            await communicateVSCodeByWebview('createUserPublicKey', {})
 | 
			
		||||
            .then(res => {
 | 
			
		||||
                if (res.ok) {
 | 
			
		||||
                    console.log('User public key has been created')
 | 
			
		||||
                } else {
 | 
			
		||||
                    console.error('Failed to create user public key')
 | 
			
		||||
                }
 | 
			
		||||
            })
 | 
			
		||||
            .catch(error => {
 | 
			
		||||
                console.error('Failed to request to create user public key: ', erro)
 | 
			
		||||
            })
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // ===================================== Repo ===========================
 | 
			
		||||
        function loadRepositories() {
 | 
			
		||||
            // clear old data
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user