2019-12-30 14:27:49 +00:00
|
|
|
<script>
|
|
|
|
|
import { onMount } from 'svelte';
|
2019-12-30 20:36:35 +00:00
|
|
|
import { userId, isAdmin } from '../UserState'
|
2019-12-30 18:50:32 +00:00
|
|
|
|
2019-12-30 14:27:49 +00:00
|
|
|
import axios from 'axios'
|
|
|
|
|
import page from 'page'
|
|
|
|
|
import moment from 'moment'
|
2019-12-30 18:50:32 +00:00
|
|
|
|
2019-12-30 14:27:49 +00:00
|
|
|
import CharacterLink from '../components/CharacterLink'
|
|
|
|
|
import LoginList from '../components/LoginList'
|
2019-12-30 18:20:50 +00:00
|
|
|
import AccountLink from '../components/AccountLink'
|
2019-12-30 18:50:32 +00:00
|
|
|
import ActionButtons from '../components/ActionButtons'
|
|
|
|
|
import ActionModal from '../components/ActionModal.svelte'
|
2019-12-30 14:27:49 +00:00
|
|
|
|
2019-12-30 18:20:50 +00:00
|
|
|
export let pageCtx;
|
|
|
|
|
export let appAlert;
|
|
|
|
|
export let params;
|
2019-12-30 14:27:49 +00:00
|
|
|
export let ready;
|
2019-12-30 18:20:50 +00:00
|
|
|
|
2019-12-30 14:27:49 +00:00
|
|
|
ready = false;
|
|
|
|
|
|
|
|
|
|
let username;
|
|
|
|
|
let characters = [];
|
|
|
|
|
let createDate;
|
|
|
|
|
let email;
|
|
|
|
|
let account;
|
|
|
|
|
|
2019-12-30 18:50:32 +00:00
|
|
|
async function refresh() {
|
2019-12-30 18:20:50 +00:00
|
|
|
let loadID = params.id || $userId;
|
|
|
|
|
|
2019-12-30 14:27:49 +00:00
|
|
|
try {
|
2019-12-30 18:20:50 +00:00
|
|
|
const resp = await axios.get("/api/user/"+loadID+"/profile")
|
2019-12-30 14:27:49 +00:00
|
|
|
account = resp.data;
|
|
|
|
|
username = resp.data.name;
|
|
|
|
|
characters = resp.data.characters;
|
|
|
|
|
createDate = moment(resp.data.account_created).format('MMMM Do YYYY, h:mm:ss a')
|
|
|
|
|
+ " (" + moment(resp.data.account_created).fromNow() + ")";
|
|
|
|
|
email = resp.data.email;
|
|
|
|
|
|
|
|
|
|
ready = true
|
|
|
|
|
} catch (e) {
|
|
|
|
|
if (e.response && e.response.status == 403) {
|
2019-12-30 18:20:50 +00:00
|
|
|
if (e.response.data.message == "session required") {
|
|
|
|
|
page("/login?redirect="+pageCtx.pathname)
|
|
|
|
|
} else {
|
|
|
|
|
appAlert.message(e.response.data.message)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
appAlert.message(e.message)
|
2019-12-30 14:27:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-12-30 18:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
await refresh();
|
2019-12-30 14:27:49 +00:00
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<svelte:head>
|
|
|
|
|
<title>PSForever - Profile</title>
|
|
|
|
|
</svelte:head>
|
|
|
|
|
|
2019-12-30 18:20:50 +00:00
|
|
|
{#if account}
|
|
|
|
|
<h1>Account: <AccountLink account={account}/></h1>
|
2019-12-30 20:36:35 +00:00
|
|
|
{#if $isAdmin}
|
2019-12-30 18:50:32 +00:00
|
|
|
<ActionButtons {account} />
|
2019-12-30 20:36:35 +00:00
|
|
|
{/if}
|
2019-12-30 18:50:32 +00:00
|
|
|
|
2019-12-30 14:27:49 +00:00
|
|
|
<form>
|
|
|
|
|
<div class="form-group row">
|
|
|
|
|
<label for="staticEmail" class="col-sm-2 col-form-label">Email</label>
|
|
|
|
|
<div class="col-sm-10">
|
|
|
|
|
<input type="text" readonly class="form-control-plaintext" id="staticEmail" bind:value={email}>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-group row">
|
|
|
|
|
<label for="staticAccountCreated" class="col-sm-2 col-form-label">Account Created</label>
|
|
|
|
|
<div class="col-sm-10">
|
|
|
|
|
<input type="text" readonly class="form-control-plaintext" id="staticAccountCreated" bind:value={createDate}>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
|
|
|
|
|
<h2>Characters</h2>
|
2019-12-30 18:20:50 +00:00
|
|
|
<p>
|
2019-12-30 18:50:32 +00:00
|
|
|
{#if characters.length >= 1}
|
2019-12-30 18:20:50 +00:00
|
|
|
<div class="row">
|
|
|
|
|
{#each characters as char, i}
|
|
|
|
|
<div class="col-md-4 col-12"><CharacterLink character={char} /></div>
|
|
|
|
|
{/each}
|
|
|
|
|
</div>
|
|
|
|
|
{:else}
|
|
|
|
|
You have no characters
|
|
|
|
|
{/if}
|
|
|
|
|
</p>
|
2019-12-30 14:27:49 +00:00
|
|
|
|
|
|
|
|
<h2>Logins</h2>
|
2019-12-30 18:20:50 +00:00
|
|
|
<p>
|
2019-12-30 14:27:49 +00:00
|
|
|
<LoginList account_id={account.id} />
|
2019-12-30 18:20:50 +00:00
|
|
|
</p>
|
2019-12-30 14:27:49 +00:00
|
|
|
{/if}
|
2019-12-30 18:20:50 +00:00
|
|
|
|
2019-12-31 20:25:35 +00:00
|
|
|
<ActionModal on:action={() => refresh()} />
|