mirror of
https://github.com/binwiederhier/ntfy.git
synced 2024-12-03 15:14:36 +03:00
Check username taken
This commit is contained in:
parent
6039002ed5
commit
7bd1c6e115
@ -47,7 +47,6 @@ import (
|
||||
purge accounts that were not logged into in X
|
||||
sync subscription display name
|
||||
store users
|
||||
signup: check unique user
|
||||
Pages:
|
||||
- Home
|
||||
- Password reset
|
||||
|
@ -160,6 +160,9 @@ class Api {
|
||||
method: "POST",
|
||||
body: body
|
||||
});
|
||||
if (response.status === 409) {
|
||||
throw new UsernameTakenError(username)
|
||||
}
|
||||
if (response.status !== 200) {
|
||||
throw new Error(`Unexpected server response ${response.status}`);
|
||||
}
|
||||
@ -250,5 +253,12 @@ class Api {
|
||||
}
|
||||
}
|
||||
|
||||
export class UsernameTakenError extends Error {
|
||||
constructor(username) {
|
||||
super();
|
||||
this.username = username;
|
||||
}
|
||||
}
|
||||
|
||||
const api = new Api();
|
||||
export default api;
|
||||
|
@ -2,7 +2,7 @@ import * as React from 'react';
|
||||
import TextField from "@mui/material/TextField";
|
||||
import Button from "@mui/material/Button";
|
||||
import Box from "@mui/material/Box";
|
||||
import api from "../app/Api";
|
||||
import api, {UsernameTakenError} from "../app/Api";
|
||||
import routes from "./routes";
|
||||
import session from "../app/Session";
|
||||
import Typography from "@mui/material/Typography";
|
||||
@ -34,7 +34,9 @@ const Signup = () => {
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(`[Signup] Signup for user ${user.username} failed`, e);
|
||||
if (e && e.message) {
|
||||
if ((e instanceof UsernameTakenError)) {
|
||||
setError(t("Username {{username}} is already taken", { username: e.username }));
|
||||
} else if (e.message) {
|
||||
setError(e.message);
|
||||
} else {
|
||||
setError(t("Unknown error. Check logs for details."))
|
||||
|
@ -14,8 +14,8 @@ 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.login} activeStyle>Login</NavLink></li>}
|
||||
{config.enableSignup && !session.exists() && <li><NavLink to={routes.signup} activeStyle>Sign up</NavLink></li>}
|
||||
{config.enableLogin && !session.exists() && <li><NavLink to={routes.login} activeStyle>Login</NavLink></li>}
|
||||
<li><NavLink to={routes.app} activeStyle>Open app</NavLink></li>
|
||||
</ol>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user