deicidus
3 years ago
17 changed files with 1266 additions and 1253 deletions
@ -0,0 +1,15 @@ |
|||||||
|
.DS_Store |
||||||
|
node_modules |
||||||
|
/build |
||||||
|
/dist |
||||||
|
/production |
||||||
|
/.svelte-kit |
||||||
|
/package |
||||||
|
.env |
||||||
|
.env.* |
||||||
|
!.env.example |
||||||
|
|
||||||
|
# Ignore files for PNPM, NPM and YARN |
||||||
|
pnpm-lock.yaml |
||||||
|
package-lock.json |
||||||
|
yarn.lock |
@ -0,0 +1,13 @@ |
|||||||
|
{ |
||||||
|
printWidth: 80, |
||||||
|
useTabs: false, |
||||||
|
tabWidth: 2, |
||||||
|
semi: false, |
||||||
|
singleQuote: true, |
||||||
|
quoteProps: 'as-needed', |
||||||
|
trailingComma: 'none', |
||||||
|
bracketSpacing: true, |
||||||
|
arrowParens: 'avoid', |
||||||
|
htmlWhitespaceSensitivity: strict, |
||||||
|
vueIndentScriptAndStyle: true, |
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
import { aoEnv } from './settings.js' |
||||||
|
import { getCard } from './api.js' |
||||||
|
|
||||||
|
// Prints the text (.name) of the first card prioritized in the logged-in users member card
|
||||||
|
export async function getTopPriorityText() { |
||||||
|
// Get the first priority of my member card
|
||||||
|
const memberId = aoEnv('AO_CLI_SESSION_MEMBERID') |
||||||
|
if(!memberId) { |
||||||
|
return 'Not logged in' |
||||||
|
} |
||||||
|
const fetchedCards = await getCard(memberId, 'priority') |
||||||
|
console.log('fetch result:', fetchedCards) |
||||||
|
if(!fetchedCards || fetchedCards.length < 2) { |
||||||
|
return 'None' |
||||||
|
} |
||||||
|
const firstPriorityCard = fetchedCards[1] |
||||||
|
return firstPriorityCard.name |
||||||
|
} |
||||||
|
|
||||||
|
// Makes an API request to get the first prioritized card in the member card of the logged-in user
|
||||||
|
async function getFirstPriorityCard() { |
||||||
|
|
||||||
|
} |
@ -0,0 +1,62 @@ |
|||||||
|
import { createSession, logout as apiLogout } from './api.js' |
||||||
|
import { aoEnv, setAoEnv } from './settings.js' |
||||||
|
import { askQuestionText } from './welcome.js' |
||||||
|
|
||||||
|
// Returns true if there is a session cookie for ao-cli saved in the AO .env file (=ready to make session requests)
|
||||||
|
export function isLoggedIn() { |
||||||
|
const username = aoEnv('AO_CLI_SESSION_USERNAME') |
||||||
|
const sessionId = aoEnv('AO_CLI_SESSION_ID') |
||||||
|
const sessionToken = aoEnv('AO_CLI_SESSION_TOKEN') |
||||||
|
return username && sessionId && sessionToken |
||||||
|
} |
||||||
|
|
||||||
|
// Interactive prompt to log in. Performs the login request.
|
||||||
|
export async function loginPrompt() { |
||||||
|
const username = await askQuestionText('Username:') |
||||||
|
const password = await askQuestionText('Password:', { type: 'password' }) |
||||||
|
await login(username, password) |
||||||
|
} |
||||||
|
|
||||||
|
export async function login(username, password) { |
||||||
|
try { |
||||||
|
console.log('Attempting login as', username, 'with password', '*'.repeat(password.length)) |
||||||
|
const response = await createSession(username, password) |
||||||
|
if(response) { |
||||||
|
setAoEnv('AO_CLI_SESSION_USERNAME', username) |
||||||
|
setAoEnv('AO_CLI_SESSION_MEMBERID', response.memberId) // might not need to save this actually
|
||||||
|
setAoEnv('AO_CLI_SESSION_ID', response.session) |
||||||
|
setAoEnv('AO_CLI_SESSION_TOKEN', response.token) |
||||||
|
console.log('Logged in as', username + '.', 'memberId:', response.memberId) |
||||||
|
return true |
||||||
|
} else { |
||||||
|
console.log('Login failed. Response:', response) |
||||||
|
return false |
||||||
|
} |
||||||
|
} catch(err) { |
||||||
|
if(err.status === 401) { |
||||||
|
console.log("No account on the AO server matched the username and password you entered. (401 Unauthorized)") |
||||||
|
} else { |
||||||
|
console.log(err) |
||||||
|
} |
||||||
|
return false |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
export async function logout() { |
||||||
|
try { |
||||||
|
console.log('Logging out...') |
||||||
|
const response = await apiLogout() |
||||||
|
if(response.statusCode === 200) { |
||||||
|
setAoEnv('AO_CLI_SESSION_USERNAME', null) |
||||||
|
setAoEnv('AO_CLI_SESSION_ID', null) |
||||||
|
setAoEnv('AO_CLI_SESSION_TOKEN', null) |
||||||
|
console.log('Logged out') |
||||||
|
} else { |
||||||
|
console.log('Logout failed. Response:', response) |
||||||
|
return false |
||||||
|
} |
||||||
|
} catch(err) { |
||||||
|
console.log(err) |
||||||
|
} |
||||||
|
return true |
||||||
|
} |
Loading…
Reference in new issue