Basic login
This commit is contained in:
parent
91551e711d
commit
ebaf09d045
|
@ -0,0 +1,46 @@
|
||||||
|
|
||||||
|
class ApiController {
|
||||||
|
username: string;
|
||||||
|
password: string;
|
||||||
|
token: string;
|
||||||
|
apiurl: string;
|
||||||
|
constructor() {
|
||||||
|
this.username = 'test';
|
||||||
|
this.password = 'prozac-prowler-stoop-patriot';
|
||||||
|
}
|
||||||
|
|
||||||
|
async getApiurl() {
|
||||||
|
let response = await fetch(`${window.location.href}apiurl`)
|
||||||
|
this.apiurl = await response.text();
|
||||||
|
console.log(this.apiurl);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async login() {
|
||||||
|
let promise = await fetch(`${this.apiurl}/token`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"accept": "application/json",
|
||||||
|
},
|
||||||
|
body: new URLSearchParams({
|
||||||
|
username: this.username,
|
||||||
|
password: this.password
|
||||||
|
})
|
||||||
|
|
||||||
|
});
|
||||||
|
if(promise.ok) {
|
||||||
|
this.token = (await promise.json())['access_token'];
|
||||||
|
console.log(this.token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setToken(token: string) {
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
getToken() :string {
|
||||||
|
return this.token;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Api = new ApiController();
|
|
@ -1,4 +1,5 @@
|
||||||
import { Component, h } from '@stencil/core';
|
import { Component, h} from '@stencil/core';
|
||||||
|
import { Api } from '../api';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
tag: 'app-home',
|
tag: 'app-home',
|
||||||
|
@ -6,6 +7,14 @@ import { Component, h } from '@stencil/core';
|
||||||
shadow: true,
|
shadow: true,
|
||||||
})
|
})
|
||||||
export class AppHome {
|
export class AppHome {
|
||||||
|
constructor() {
|
||||||
|
this.start()
|
||||||
|
}
|
||||||
|
|
||||||
|
async start() {
|
||||||
|
await Api.getApiurl();
|
||||||
|
await Api.login();
|
||||||
|
}
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div class="app-home">
|
<div class="app-home">
|
||||||
|
|
Loading…
Reference in New Issue