Derp
This commit is contained in:
		
							parent
							
								
									bec7cffe2a
								
							
						
					
					
						commit
						50204599b4
					
				
					 4 changed files with 353 additions and 18 deletions
				
			
		|  | @ -30,6 +30,7 @@ import api from "../app/Api"; | |||
| import prefs from "../app/Prefs"; | ||||
| import session from "../app/Session"; | ||||
| import Pricing from "./Pricing"; | ||||
| import Signup from "./Signup"; | ||||
| 
 | ||||
| // TODO races when two tabs are open
 | ||||
| // TODO investigate service workers
 | ||||
|  | @ -45,6 +46,7 @@ const App = () => { | |||
|                             <Route path={routes.home} element={<Home/>}/> | ||||
|                             <Route path={routes.pricing} element={<Pricing/>}/> | ||||
|                             <Route path={routes.login} element={<Login/>}/> | ||||
|                             <Route path={routes.signup} element={<Signup/>}/> | ||||
|                             <Route element={<Layout/>}> | ||||
|                                 <Route path={routes.app} element={<AllSubscriptions/>}/> | ||||
|                                 <Route path={routes.settings} element={<Preferences/>}/> | ||||
|  |  | |||
|  | @ -1,29 +1,14 @@ | |||
| import * as React from 'react'; | ||||
| import {Avatar, Checkbox, FormControlLabel, Grid, Link, Stack} from "@mui/material"; | ||||
| import {Avatar, Checkbox, FormControlLabel, Grid, Link} from "@mui/material"; | ||||
| import Typography from "@mui/material/Typography"; | ||||
| import Container from "@mui/material/Container"; | ||||
| import LockOutlinedIcon from '@mui/icons-material/LockOutlined'; | ||||
| import TextField from "@mui/material/TextField"; | ||||
| import Button from "@mui/material/Button"; | ||||
| import Box from "@mui/material/Box"; | ||||
| import api from "../app/Api"; | ||||
| import {useNavigate} from "react-router-dom"; | ||||
| import routes from "./routes"; | ||||
| import session from "../app/Session"; | ||||
| 
 | ||||
| const Copyright = (props) => { | ||||
|     return ( | ||||
|         <Typography variant="body2" color="text.secondary" align="center" {...props}> | ||||
|             {'Copyright © '} | ||||
|             <Link color="inherit" href="https://mui.com/"> | ||||
|                 Your Website | ||||
|             </Link>{' '} | ||||
|             {new Date().getFullYear()} | ||||
|             {'.'} | ||||
|         </Typography> | ||||
|     ); | ||||
| }; | ||||
| 
 | ||||
| const Login = () => { | ||||
|     const handleSubmit = async (event) => { | ||||
|         event.preventDefault(); | ||||
|  | @ -93,14 +78,13 @@ const Login = () => { | |||
|                             </Link> | ||||
|                         </Grid> | ||||
|                         <Grid item> | ||||
|                             <Link href="#" variant="body2"> | ||||
|                             <Link to={routes.signup} variant="body2"> | ||||
|                                 {"Don't have an account? Sign Up"} | ||||
|                             </Link> | ||||
|                         </Grid> | ||||
|                     </Grid> | ||||
|                 </Box> | ||||
|             </Box> | ||||
|             <Copyright sx={{mt: 8, mb: 4}}/> | ||||
|         </> | ||||
|     ); | ||||
| } | ||||
|  |  | |||
							
								
								
									
										94
									
								
								web/src/components/Signup.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								web/src/components/Signup.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,94 @@ | |||
| import * as React from 'react'; | ||||
| import {Avatar, Checkbox, FormControlLabel, Grid, Link, Stack} from "@mui/material"; | ||||
| import Typography from "@mui/material/Typography"; | ||||
| import Container from "@mui/material/Container"; | ||||
| import LockOutlinedIcon from '@mui/icons-material/LockOutlined'; | ||||
| import TextField from "@mui/material/TextField"; | ||||
| import Button from "@mui/material/Button"; | ||||
| import Box from "@mui/material/Box"; | ||||
| import api from "../app/Api"; | ||||
| import {useNavigate} from "react-router-dom"; | ||||
| import routes from "./routes"; | ||||
| import session from "../app/Session"; | ||||
| 
 | ||||
| const Signup = () => { | ||||
|     const handleSubmit = async (event) => { | ||||
|         event.preventDefault(); | ||||
|         const data = new FormData(event.currentTarget); | ||||
|         const user = { | ||||
|             username: data.get('username'), | ||||
|             password: data.get('password'), | ||||
|         } | ||||
|         const token = await api.login("http://localhost:2586"/*window.location.origin*/, user); | ||||
|         console.log(`[Api] User auth for user ${user.username} successful, token is ${token}`); | ||||
|         session.store(user.username, token); | ||||
|         window.location.href = routes.app; | ||||
|     }; | ||||
| 
 | ||||
|     return ( | ||||
|         <> | ||||
|             <Box | ||||
|                 sx={{ | ||||
|                     marginTop: 8, | ||||
|                     display: 'flex', | ||||
|                     flexDirection: 'column', | ||||
|                     alignItems: 'center', | ||||
|                 }} | ||||
|             > | ||||
|                 <Avatar sx={{m: 1, bgcolor: 'secondary.main'}}> | ||||
|                     <LockOutlinedIcon/> | ||||
|                 </Avatar> | ||||
|                 <Typography component="h1" variant="h5"> | ||||
|                     Sign in | ||||
|                 </Typography> | ||||
|                 <Box component="form" onSubmit={handleSubmit} noValidate sx={{mt: 1}}> | ||||
|                     <TextField | ||||
|                         margin="normal" | ||||
|                         required | ||||
|                         fullWidth | ||||
|                         id="username" | ||||
|                         label="Username" | ||||
|                         name="username" | ||||
|                         autoFocus | ||||
|                     /> | ||||
|                     <TextField | ||||
|                         margin="normal" | ||||
|                         required | ||||
|                         fullWidth | ||||
|                         name="password" | ||||
|                         label="Password" | ||||
|                         type="password" | ||||
|                         id="password" | ||||
|                         autoComplete="current-password" | ||||
|                     /> | ||||
|                     <FormControlLabel | ||||
|                         control={<Checkbox value="remember" color="primary"/>} | ||||
|                         label="Remember me" | ||||
|                     /> | ||||
|                     <Button | ||||
|                         type="submit" | ||||
|                         fullWidth | ||||
|                         variant="contained" | ||||
|                         sx={{mt: 3, mb: 2}} | ||||
|                     > | ||||
|                         Sign up | ||||
|                     </Button> | ||||
|                     <Grid container> | ||||
|                         <Grid item xs> | ||||
|                             <Link href="#" variant="body2"> | ||||
|                                 Forgot password? | ||||
|                             </Link> | ||||
|                         </Grid> | ||||
|                         <Grid item> | ||||
|                             <Link to={routes.signup} variant="body2"> | ||||
|                                 {"Don't have an account? Sign Up"} | ||||
|                             </Link> | ||||
|                         </Grid> | ||||
|                     </Grid> | ||||
|                 </Box> | ||||
|             </Box> | ||||
|         </> | ||||
|     ); | ||||
| } | ||||
| 
 | ||||
| export default Signup; | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue