refactor(user): isLogged add validity verification for username and token
This commit is contained in:
21
src/user.ts
21
src/user.ts
@@ -116,18 +116,19 @@ export default class User {
|
|||||||
vscode.window.showInformationMessage(vscode.l10n.t("User has logged out!"))
|
vscode.window.showInformationMessage(vscode.l10n.t("User has logged out!"))
|
||||||
}
|
}
|
||||||
|
|
||||||
public isLogged() {
|
public async isLogged(): Promise<boolean> {
|
||||||
var existUsername = false;
|
const username: string|undefined = this.context.globalState.get(this.usernameKey)
|
||||||
var existUserToken = false;
|
const userToken: string|undefined = this.context.globalState.get(this.userTokenKey)
|
||||||
if (this.username != undefined && this.username != '') {
|
if ((username != undefined && username != '') && (userToken != undefined && userToken != '')) {
|
||||||
existUsername = true;
|
const devstarAPIHandler = new DevstarAPIHandler(this.devstarDomain)
|
||||||
}
|
|
||||||
if (this.userToken != undefined && this.userToken != '') {
|
|
||||||
existUserToken = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (existUsername && existUserToken) {
|
const res = await devstarAPIHandler.verifyToken(userToken, username)
|
||||||
|
if (!res) {
|
||||||
|
console.error("username or token is error")
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user