Browse Source

Clean up and reorganize a few little things before next push.

master
Zed A. Shaw 2 weeks ago
parent
commit
a962c27fa0
6 changed files with 23 additions and 15 deletions
  1. +4
    -3
      src/components/Nav.svelte
  2. +5
    -2
      src/routes/auth/index.svelte
  3. +9
    -5
      src/routes/index.svelte
  4. +1
    -1
      src/routes/register/index.svelte
  5. +3
    -3
      src/routes/user/index.svelte
  6. +1
    -1
      tests/ui/register.spec.js

+ 4
- 3
src/components/Nav.svelte View File

@@ -9,7 +9,8 @@
async function logout(event) {
const response = await post('auth/logout');
$session.user = null;
await goto('/'); }
await goto('/');
}
</script>

<style>
@@ -22,11 +23,11 @@

<header class="navbar">
<section class="navbar-section">
<a class="navbar-brand mr-2" href="/"><h1 class="hide-sm hide-xs">LJSTHW</h1><img id="logo" class="show-sm hide-xs" src="/icons/logo-40.png" alt="LJSTHW logo"></a>
<a class="navbar-brand mr-2" href="{$session.user ? 'modules' : '/'}"><h1 class="hide-sm hide-xs">LJSTHW</h1><img id="logo" class="show-sm hide-xs" src="/icons/logo-40.png" alt="LJSTHW logo"></a>
</section>

<section class="navbar-section">
<a data-testid='nav-blog-logo' rel="prefetch" class:btn-link="{ segment != undefined }" class="btn" href="/"><Icon name="home"/></a>
<a data-testid='nav-blog-logo' rel="prefetch" class:btn-link="{ segment != undefined }" class="btn" href="{$session.user ? 'modules' : '/'}"><Icon name="home"/></a>
<a data-testid='nav-blog-icon' rel="prefetch" class:btn-link="{ segment != 'blog' }" class="btn" href="blog">Blog</a>
{#if valid_user($session.user)}
<a data-testid='nav-blog-icon' rel="prefetch" class:btn-link="{ segment != 'live' }" class="btn" href="live">Live</a>

+ 5
- 2
src/routes/auth/index.svelte View File

@@ -40,7 +40,6 @@
if(email) {
const response = await post('auth/verify', { email, token });
console.log("Got response to verify", response.user);
if(response.user) console.log("User verified", response.user.verified);

if(response.user && response.user.verified) {
// TODO: have to reset these from the logout so...probably on the session or page load
@@ -53,7 +52,11 @@
console.log("Session user is now", $session.user);

// send them to register if they haven't yet
if($session.user.registered === false) await goto('register');
if($session.user.registered === false) {
await goto('register');
} else {
await goto('modules');
}
} else {
$session.user = null;
error = response.message;

+ 9
- 5
src/routes/index.svelte View File

@@ -4,13 +4,12 @@
import { goto, stores } from '@sapper/app';
import { fly } from 'svelte/transition';
import { quintOut } from 'svelte/easing';
import { onMount } from 'svelte';

const { session } = stores();

let email='';
let visible=false;

setTimeout(() => visible = true, 300);
const flyOpts = {delay: 200, duration: 300, x: 100, y: 500, opacity: 0.5, easing: quintOut};

const register = async (event) => {
// TODO: is there a better way to talk to the other page?
@@ -18,8 +17,13 @@
await goto('auth');
}

const flyOpts = {delay: 200, duration: 300, x: 100, y: 500, opacity: 0.5, easing: quintOut};

onMount(async () => {
if($session.user) {
await goto('modules');
} else {
setTimeout(() => visible = true, 300);
}
});
</script>

<style lang="scss">

+ 1
- 1
src/routes/register/index.svelte View File

@@ -33,7 +33,7 @@ const register = async (event) => {
if(res.user) {
console.log('New user is', res.user);
$session.user = res.user;
goto('live');
await goto('modules');
} else {
error = res.message;
}

+ 3
- 3
src/routes/user/index.svelte View File

@@ -15,12 +15,12 @@
let user_email = '';
let error = '';

onMount(() => {
onMount(async () => {
// TODO: there has to be a better spot for this
if(!$session.user) {
goto('auth');
await goto('auth');
} else if($session.user.registered !== true) {
goto('register');
await goto('register');
} else {
console.log("User given", $session.user);
full_name = $session.user.full_name;

+ 1
- 1
tests/ui/register.spec.js View File

@@ -45,7 +45,7 @@ it('Can register for an account after soft login', async () => {
await page.click(t.sel('tos-agree'));
await page.click(t.sel('register-submit'));

await page.waitForSelector(t.sel('live-page'));
await page.waitForSelector(t.sel('modules-page'));
// and validate the user in the backend
let {user, is_valid} = await User.find_and_validate(main_user.email, true);

Loading…
Cancel
Save