feat: verify token and user
This commit is contained in:
		@@ -17,6 +17,33 @@ export default class DevstarAPIHandler {
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public async verifyToken(token: string, username: string): Promise<string> {
 | 
			
		||||
    return new Promise(async (resolve) => {
 | 
			
		||||
      fetch(this.devstarDomain + `/api/devcontainer/user`, {
 | 
			
		||||
        method: 'GET',
 | 
			
		||||
        headers: {
 | 
			
		||||
          'Content-Type': 'application/json',
 | 
			
		||||
          'Authorization': 'token ' + token
 | 
			
		||||
        }
 | 
			
		||||
      })
 | 
			
		||||
        .then(response => {
 | 
			
		||||
          response.json().then(async data => {
 | 
			
		||||
            if (response.ok) {
 | 
			
		||||
              if (data.username == username) {
 | 
			
		||||
                resolve('ok')
 | 
			
		||||
              } else {
 | 
			
		||||
                utils.showErrorNotification('Token与用户名不符')
 | 
			
		||||
                console.error('Token: ', token, ' Username: ', username)
 | 
			
		||||
              }
 | 
			
		||||
            } else {
 | 
			
		||||
              utils.showErrorNotification('Token错误')
 | 
			
		||||
              console.error('Error token: ', token)
 | 
			
		||||
            }
 | 
			
		||||
          })
 | 
			
		||||
        })
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // 上传公钥
 | 
			
		||||
  public async uploadUserPublicKey(user: User): Promise<string> {
 | 
			
		||||
    return new Promise(async (resolve) => {
 | 
			
		||||
@@ -55,7 +82,7 @@ export default class DevstarAPIHandler {
 | 
			
		||||
          console.error(error);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
      })
 | 
			
		||||
    })
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user