import React, { useState } from 'react'; import { Route, Link } from 'react-router-dom'; import './light.css'; import { Container, Form, Header, Image, Message, Segment } from 'semantic-ui-react'; import { requester } from './utils.js'; export function AuthForm(props) { const { user } = props; const username = user ? user.username : ''; const [input, setInput] = useState({ username: username }); const [error, setError] = useState({}); const [success, setSuccess] = useState(false); const [loading, setLoading] = useState(false); const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value }); const handleChange = (e) => handleValues(e, e.currentTarget); const handleSubmit = (e) => { if (input.username.includes('@')) { setError({ username: 'Spaceport username, not email.' }); } else { if (loading) return; setLoading(true); const data = { ...input, username: input.username.toLowerCase() }; requester('/spaceport-auth/login/', 'POST', '', data) .then(res => { setSuccess(true); setError({}); }) .catch(err => { setLoading(false); console.log(err); setError(err.data); }); } }; return ( success ? props.children :
Log In to Spaceport
{user ? <> : <> } Authorize Forgot your password?

Click here to reset it.

); }; export function AuthWiki(props) { const { user } = props; return (
Protospace Wiki

would like to request Spaceport authentication.

URL: wiki.protospace.ca

Success!

You can now log into the Wiki:

{user &&

Username: {user.member.mediawiki_username || user.username}
Password: [this Spaceport password]

}

Protospace Wiki

); } export function AuthDiscourse(props) { const { user } = props; return (
Protospace Discourse

would like to request Spaceport authentication.

URL: forum.protospace.ca

Success!

You can now log into the Discourse:

{user &&

Username: {user.member.discourse_username || user.username}
Password: [this Spaceport password]

}

Protospace Discourse

); } export function Auth(props) { const { user } = props; return (
Spaceport Auth

Use this page to link different applications to your Spaceport account.

); }