Stuff
This commit is contained in:
parent
c35e5b33d1
commit
c2f16f740b
21 changed files with 332 additions and 547 deletions
|
@ -115,7 +115,7 @@ const SettingsIcons = (props) => {
|
|||
handleClose(event);
|
||||
await subscriptionManager.remove(props.subscription.id);
|
||||
if (session.exists() && props.subscription.remoteId) {
|
||||
await api.userSubscriptionDelete("http://localhost:2586", session.token(), props.subscription.remoteId);
|
||||
await api.deleteAccountSubscription("http://localhost:2586", session.token(), props.subscription.remoteId);
|
||||
}
|
||||
const newSelected = await subscriptionManager.first(); // May be undefined
|
||||
if (newSelected) {
|
||||
|
|
|
@ -91,7 +91,7 @@ const Layout = () => {
|
|||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const account = await api.userAccount("http://localhost:2586", session.token());
|
||||
const account = await api.getAccountSettings("http://localhost:2586", session.token());
|
||||
if (account) {
|
||||
if (account.language) {
|
||||
await i18n.changeLanguage(account.language);
|
||||
|
|
|
@ -8,6 +8,8 @@ import Box from "@mui/material/Box";
|
|||
import api from "../app/Api";
|
||||
import routes from "./routes";
|
||||
import session from "../app/Session";
|
||||
import logo from "../img/ntfy2.svg";
|
||||
import {NavLink} from "react-router-dom";
|
||||
|
||||
const Login = () => {
|
||||
const handleSubmit = async (event) => {
|
||||
|
@ -24,68 +26,59 @@ const Login = () => {
|
|||
};
|
||||
|
||||
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">
|
||||
<Box
|
||||
sx={{
|
||||
display: 'flex',
|
||||
flexGrow: 1,
|
||||
justifyContent: 'center',
|
||||
flexDirection: 'column',
|
||||
alignContent: 'center',
|
||||
alignItems: 'center',
|
||||
height: '100vh'
|
||||
}}
|
||||
>
|
||||
<Avatar
|
||||
sx={{ m: 2, width: 64, height: 64, borderRadius: 3 }}
|
||||
src={logo}
|
||||
variant="rounded"
|
||||
/>
|
||||
<Typography sx={{ typography: 'h6' }}>
|
||||
Sign in to your ntfy account
|
||||
</Typography>
|
||||
<Box component="form" onSubmit={handleSubmit} noValidate sx={{mt: 1, maxWidth: 400}}>
|
||||
<TextField
|
||||
margin="dense"
|
||||
required
|
||||
fullWidth
|
||||
id="username"
|
||||
label="Username"
|
||||
name="username"
|
||||
autoFocus
|
||||
/>
|
||||
<TextField
|
||||
margin="dense"
|
||||
required
|
||||
fullWidth
|
||||
name="password"
|
||||
label="Password"
|
||||
type="password"
|
||||
id="password"
|
||||
autoComplete="current-password"
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
fullWidth
|
||||
variant="contained"
|
||||
sx={{mt: 2, mb: 2}}
|
||||
>
|
||||
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 In
|
||||
</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>
|
||||
</Button>
|
||||
<Box sx={{width: "100%"}}>
|
||||
<NavLink to="#" variant="body1" sx={{float: "left"}}>Reset password</NavLink>
|
||||
<div style={{float: "right"}}><NavLink to={routes.signup} variant="body1">Sign Up</NavLink></div>
|
||||
</Box>
|
||||
</Box>
|
||||
</>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ const Sound = () => {
|
|||
const handleChange = async (ev) => {
|
||||
await prefs.setSound(ev.target.value);
|
||||
if (session.exists()) {
|
||||
await api.updateUserAccount("http://localhost:2586", session.token(), {
|
||||
await api.updateAccountSettings("http://localhost:2586", session.token(), {
|
||||
notification: {
|
||||
sound: ev.target.value
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ const MinPriority = () => {
|
|||
const handleChange = async (ev) => {
|
||||
await prefs.setMinPriority(ev.target.value);
|
||||
if (session.exists()) {
|
||||
await api.updateUserAccount("http://localhost:2586", session.token(), {
|
||||
await api.updateAccountSettings("http://localhost:2586", session.token(), {
|
||||
notification: {
|
||||
min_priority: ev.target.value
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ const DeleteAfter = () => {
|
|||
const handleChange = async (ev) => {
|
||||
await prefs.setDeleteAfter(ev.target.value);
|
||||
if (session.exists()) {
|
||||
await api.updateUserAccount("http://localhost:2586", session.token(), {
|
||||
await api.updateAccountSettings("http://localhost:2586", session.token(), {
|
||||
notification: {
|
||||
delete_after: ev.target.value
|
||||
}
|
||||
|
@ -467,7 +467,7 @@ const Language = () => {
|
|||
const handleChange = async (ev) => {
|
||||
await i18n.changeLanguage(ev.target.value);
|
||||
if (session.exists()) {
|
||||
await api.updateUserAccount("http://localhost:2586", session.token(), {
|
||||
await api.updateAccountSettings("http://localhost:2586", session.token(), {
|
||||
language: ev.target.value
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,24 +1,27 @@
|
|||
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 {Avatar, Link} from "@mui/material";
|
||||
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";
|
||||
import logo from "../img/ntfy2.svg";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import {NavLink} from "react-router-dom";
|
||||
|
||||
const Signup = () => {
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
const data = new FormData(event.currentTarget);
|
||||
const username = data.get('username');
|
||||
const password = data.get('password');
|
||||
const user = {
|
||||
username: data.get('username'),
|
||||
password: data.get('password'),
|
||||
}
|
||||
username: username,
|
||||
password: password
|
||||
}; // FIXME omg so awful
|
||||
|
||||
await api.createAccount("http://localhost:2586"/*window.location.origin*/, username, 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);
|
||||
|
@ -26,68 +29,69 @@ const Signup = () => {
|
|||
};
|
||||
|
||||
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
|
||||
sx={{
|
||||
display: 'flex',
|
||||
flexGrow: 1,
|
||||
justifyContent: 'center',
|
||||
flexDirection: 'column',
|
||||
alignContent: 'center',
|
||||
alignItems: 'center',
|
||||
height: '100vh'
|
||||
}}
|
||||
>
|
||||
<Avatar
|
||||
sx={{ m: 2, width: 64, height: 64, borderRadius: 3 }}
|
||||
src={logo}
|
||||
variant="rounded"
|
||||
/>
|
||||
<Typography sx={{ typography: 'h6' }}>
|
||||
Create a ntfy account
|
||||
</Typography>
|
||||
<Box component="form" onSubmit={handleSubmit} noValidate sx={{mt: 1, maxWidth: 400}}>
|
||||
<TextField
|
||||
margin="dense"
|
||||
required
|
||||
fullWidth
|
||||
id="username"
|
||||
label="Username"
|
||||
name="username"
|
||||
autoFocus
|
||||
/>
|
||||
<TextField
|
||||
margin="dense"
|
||||
required
|
||||
fullWidth
|
||||
name="password"
|
||||
label="Password"
|
||||
type="password"
|
||||
id="password"
|
||||
autoComplete="current-password"
|
||||
/>
|
||||
<TextField
|
||||
margin="dense"
|
||||
required
|
||||
fullWidth
|
||||
name="confirm-password"
|
||||
label="Confirm password"
|
||||
type="password"
|
||||
id="confirm-password"
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
fullWidth
|
||||
variant="contained"
|
||||
sx={{mt: 2, mb: 2}}
|
||||
>
|
||||
Sign up
|
||||
</Button>
|
||||
</Box>
|
||||
</>
|
||||
<Typography sx={{mb: 4}}>
|
||||
<NavLink to={routes.login} variant="body1">
|
||||
Already have an account? Sign in
|
||||
</NavLink>
|
||||
</Typography>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ const SiteLayout = (props) => {
|
|||
<li><NavLink to={routes.home} activeStyle>Features</NavLink></li>
|
||||
<li><NavLink to={routes.pricing} activeStyle>Pricing</NavLink></li>
|
||||
<li><NavLink to="/docs" reloadDocument={true} activeStyle>Docs</NavLink></li>
|
||||
{session.exists() && <li><NavLink to={routes.signup} activeStyle>Sign up</NavLink></li>}
|
||||
{!session.exists() && <li><NavLink to={routes.signup} activeStyle>Sign up</NavLink></li>}
|
||||
{!session.exists() && <li><NavLink to={routes.login} activeStyle>Login</NavLink></li>}
|
||||
<li><NavLink to={routes.app} activeStyle>Open app</NavLink></li>
|
||||
</ol>
|
||||
|
|
|
@ -28,7 +28,7 @@ const SubscribeDialog = (props) => {
|
|||
const actualBaseUrl = (baseUrl) ? baseUrl : window.location.origin;
|
||||
const subscription = await subscriptionManager.add(actualBaseUrl, topic);
|
||||
if (session.exists()) {
|
||||
const remoteSubscription = await api.userSubscriptionAdd("http://localhost:2586", session.token(), {
|
||||
const remoteSubscription = await api.addAccountSubscription("http://localhost:2586", session.token(), {
|
||||
base_url: actualBaseUrl,
|
||||
topic: topic
|
||||
});
|
||||
|
|
|
@ -64,7 +64,7 @@ export const useAutoSubscribe = (subscriptions, selected) => {
|
|||
(async () => {
|
||||
const subscription = await subscriptionManager.add(baseUrl, params.topic);
|
||||
if (session.exists()) {
|
||||
const remoteSubscription = await api.userSubscriptionAdd("http://localhost:2586", session.token(), {
|
||||
const remoteSubscription = await api.addAccountSubscription("http://localhost:2586", session.token(), {
|
||||
base_url: baseUrl,
|
||||
topic: params.topic
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue