-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
367 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<template> | ||
<img class="animate-pulse" src="@/assets/logo.png" alt="NethServer 8 Logo" /> | ||
<img alt="NethServer 8 Logo" class="animate-pulse" src="@/assets/logo.png" /> | ||
</template> |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { computed } from 'vue' | ||
import axios from 'axios' | ||
|
||
interface LoginResponse { | ||
token: string | ||
expire: string | ||
} | ||
|
||
const TOKEN_KEY = 'token' | ||
const EXPIRE_KEY = 'expire' | ||
|
||
export function useAuth() { | ||
/** | ||
* Token from localStorage | ||
*/ | ||
const token = computed((): string | null => localStorage.getItem(TOKEN_KEY)) | ||
|
||
/** | ||
* Expire date from localStorage | ||
*/ | ||
const expire = computed((): string | null => localStorage.getItem(EXPIRE_KEY)) | ||
|
||
/** | ||
* Whether the user has previously logged in or not | ||
*/ | ||
const previouslyLogged = computed((): boolean => { | ||
return token.value != null && expire.value != null | ||
}) | ||
|
||
/** | ||
* Login to the API, saving the token and expire date to localStorage | ||
* @param username | ||
* @param password | ||
*/ | ||
async function login(username: string, password: string) { | ||
const response = await axios.post<LoginResponse>('/api/login', { | ||
username: username, | ||
password: password | ||
}) | ||
localStorage.setItem(TOKEN_KEY, response.data.token) | ||
localStorage.setItem(EXPIRE_KEY, response.data.expire) | ||
} | ||
|
||
/** | ||
* Removes authorization data from localStorage. | ||
*/ | ||
function logout() { | ||
localStorage.removeItem(TOKEN_KEY) | ||
localStorage.removeItem(EXPIRE_KEY) | ||
} | ||
|
||
return { token, expire, previouslyLogged, login, logout } | ||
} |
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 |
---|---|---|
@@ -1,10 +1,18 @@ | ||
{ | ||
"errors": { | ||
"connection_aborted": "Couldn't connect to the server", | ||
"network": "Network error" | ||
}, | ||
"base_template": { | ||
"logout": "Logout" | ||
}, | ||
"login_form": { | ||
"welcome": "Welcome", | ||
"sign_in_description": "Sign in to access your account settings", | ||
"username": "Username", | ||
"password": "Password", | ||
"remember_me": "Remember me", | ||
"sign_in": "Sign in" | ||
"sign_in": "Sign in", | ||
"invalid_credentials": "Invalid credentials" | ||
} | ||
} | ||
} |
Oops, something went wrong.