Advertisement
Guest User

Untitled

a guest
Dec 26th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react'
  2. import styled from 'react-emotion'
  3. import { FaArrowRight, FaExclamationTriangle } from 'react-icons/fa'
  4.  
  5. import Authentication from './authentication'
  6. import Button from './button'
  7. import LoginLinks from './login-links'
  8. import Img from "gatsby-image"
  9. import { graphql } from 'gatsby'
  10.  
  11. export const query = graphql`
  12.   query {
  13.     file(relativePath: { eq: "images/logo-big.png" }) {
  14.       childImageSharp {
  15.         # Specify the image processing specifications right in the query.
  16.         # Makes it trivial to update as your page's design changes.
  17.        fixed(width: 125, height: 125) {
  18.          ...GatsbyImageSharpFixed
  19.        }
  20.      }
  21.    }
  22.  }
  23. `
  24.  
  25.  
  26. const GUEST_PASS = 'kYcHtjkAFeml&48clhP#A!K9vKl%Nc5309IFgB2eqJk!JO6'
  27.  
  28. const Container = styled.div(
  29.     {
  30.         display: `flex`,
  31.         justifyContent: 'center',
  32.         flex: 1,
  33.         minHeight: '100%',
  34.         flexDirection: 'column',
  35.         padding: '1rem',
  36.     },
  37.     ({ theme }) => ({
  38.         color: theme.color,
  39.     })
  40. )
  41.  
  42. const Title = styled.h1({
  43.     fontSize: 28,
  44.     fontWeight: 400,
  45.     textAlign: 'left',
  46. })
  47.  
  48. const Subtitle = styled.span(
  49.     {
  50.         display: 'block',
  51.         fontSize: 40,
  52.         fontWeight: 700,
  53.     },
  54.     ({ theme }) => ({
  55.         color: theme.name === 'dark' ? '#3FA9F5' : theme.accent,
  56.     })
  57. )
  58.  
  59. const Message = styled.h4(
  60.     {
  61.         fontSize: 14,
  62.         margin: '0.5rem 0',
  63.     },
  64.     ({ theme }) => ({
  65.         color: theme.alert,
  66.     })
  67. )
  68.  
  69. let username
  70. let password
  71.  
  72. function Login() {
  73.     const userInput = (
  74.         <input
  75.             name="username"
  76.             onChange={event => {
  77.                 username = event.target.value
  78.             }}
  79.         />
  80.     )
  81.     const passInput = (
  82.         <input
  83.             name="password"
  84.             type="password"
  85.             onChange={event => {
  86.                 password = event.target.value
  87.             }}
  88.         />
  89.     )
  90.     return (
  91.         <Container>
  92.             <Authentication>
  93.                 {({ authenticated, login, loginOffline, register, error }) => {
  94.                     if (authenticated) {
  95.                         return null
  96.                     }
  97.                     return (
  98.                         <>
  99.                             <Title>
  100.                                 Welcome to
  101.                                 <Subtitle>Spark2Date</Subtitle>
  102.                             </Title>
  103.                             <Img fixed={data.file.childImageSharp.fixed} />
  104.                             <label>
  105.                                 Username:
  106.                                 {userInput}
  107.                             </label>
  108.                             <label>
  109.                                 Password:
  110.                                 {passInput}
  111.                             </label>
  112.                             <Button
  113.                                 css={{ margin: '1rem 0' }}
  114.                                 onClick={() => {
  115.                                     // TODO: fix login as guest when server can be hosted on cloud
  116.                                     if (document.URL.includes('localhost:8000'))
  117.                                         login(`guest_${Math.random()}`, GUEST_PASS)
  118.                                     else loginOffline()
  119.                                 }}
  120.                             >
  121.                                 Log in as Guest{' '}
  122.                                 <FaArrowRight css={{ position: 'relative', top: 4 }} />
  123.                             </Button>
  124.                             <Button
  125.                                 css={{ margin: '1rem 0' }}
  126.                                 onClick={() => {
  127.                                     login(username, password)
  128.                                 }}
  129.                             >
  130.                                 Log in <FaArrowRight css={{ position: 'relative', top: 4 }} />
  131.                             </Button>
  132.                             <Button
  133.                                 css={{ margin: '1rem 0' }}
  134.                                 onClick={() => {
  135.                                     register(username, password)
  136.                                 }}
  137.                             >
  138.                                 Register
  139.                                 <FaArrowRight css={{ position: 'relative', top: 4 }} />
  140.                             </Button>
  141.                             {error && (
  142.                                 <Message>
  143.                                     <FaExclamationTriangle
  144.                                         css={{
  145.                                             position: 'relative',
  146.                                             top: 2,
  147.                                             marginRight: '0.25rem',
  148.                                         }}
  149.                                     />
  150.                                     <p>{error}</p>
  151.                                 </Message>
  152.                             )}
  153.                         </>
  154.                     )
  155.                 }}
  156.             </Authentication>
  157.             <LoginLinks />
  158.         </Container>
  159.     )
  160. }
  161.  
  162. export default Login
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement