forked from statping/statping
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed authentication via cookies, oauth login,
- Loading branch information
1 parent
2aa3bee
commit 42e1b02
Showing
19 changed files
with
180 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import * as Sentry from "@sentry/browser"; | |
import * as Integrations from "@sentry/integrations"; | ||
const qs = require('querystring'); | ||
|
||
const tokenKey = "statping_user"; | ||
const tokenKey = "statping_auth"; | ||
const errorReporter = "https://[email protected]/3" | ||
|
||
class Api { | ||
|
@@ -29,6 +29,10 @@ class Api { | |
return axios.post('api/core', obj).then(response => (response.data)) | ||
} | ||
|
||
async oauth_save(obj) { | ||
return axios.post('api/oauth', obj).then(response => (response.data)) | ||
} | ||
|
||
async setup_save(data) { | ||
return axios.post('api/setup', qs.stringify(data)).then(response => (response.data)) | ||
} | ||
|
@@ -228,19 +232,11 @@ class Api { | |
|
||
async login(username, password) { | ||
const f = {username: username, password: password} | ||
return axios.post('api/login', qs.stringify(f)) | ||
.then(response => (response.data)) | ||
return axios.post('api/login', qs.stringify(f)).then(response => (response.data)) | ||
} | ||
|
||
async logout() { | ||
await axios.get('api/logout').then(response => (response.data)) | ||
return localStorage.removeItem(tokenKey) | ||
} | ||
|
||
saveToken(username, token, admin) { | ||
const user = {username: username, token: token, admin: admin} | ||
localStorage.setItem(tokenKey, JSON.stringify(user)); | ||
return user | ||
return axios.get('api/logout').then(response => (response.data)) | ||
} | ||
|
||
async scss_base() { | ||
|
@@ -255,17 +251,17 @@ class Api { | |
} | ||
|
||
token() { | ||
const tk = localStorage.getItem(tokenKey) | ||
const tk = $cookies.get(tokenKey) | ||
if (!tk) { | ||
return {}; | ||
return {admin: false}; | ||
} | ||
return JSON.parse(tk); | ||
return tk; | ||
} | ||
|
||
authToken() { | ||
let user = JSON.parse(localStorage.getItem(tokenKey)); | ||
if (user && user.token) { | ||
return {'Authorization': 'Bearer ' + user.token}; | ||
const tk = $cookies.get(tokenKey) | ||
if (tk.token) { | ||
return {'Authorization': 'Bearer ' + tk.token}; | ||
} else { | ||
return {}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.