Prevent duplicate registrations.

pull/31/head
Sander Vocke 5 years ago
parent d4e66063ba
commit 38fc3db341
  1. 2
      client/src/components/tables/ResultsTable.tsx
  2. 2
      client/src/lib/useAuth.tsx
  3. 12
      server/endpoints/RegisterUser.ts
  4. 1
      server/migrations/20201110170100_add_users.ts
  5. 13
      server/test/integration/flows/AuthFlow.js

@ -46,7 +46,7 @@ export default function SongTable(props: {
<TableBody>
{props.songs.map((song: any) => {
const title = props.songGetters.getTitle(song);
// TODO / FIXME: display artists and albums separately!
// TODO: display artists and albums separately!
const artistNames = props.songGetters.getArtistNames(song);
const artist = stringifyList(artistNames);
const mainArtistId = props.songGetters.getArtistIds(song)[0];

@ -41,7 +41,7 @@ export const useAuth = () => {
function useProvideAuth() {
const [user, setUser] = useState<AuthUser | null>(null);
// FIXME: password shouldn't be encoded into the URL.
// TODO: password maybe shouldn't be encoded into the URL.
const signin = (email: string, password: string) => {
return (async () => {
const urlBase = (process.env.REACT_APP_BACKEND || "") + serverApi.LoginEndpoint;

@ -18,8 +18,16 @@ export const RegisterUserEndpointHandler: EndpointHandler = async (req: any, res
await knex.transaction(async (trx) => {
try {
// FIXME check if the user already exists
// check if the user already exists
const user = (await trx
.select('id')
.from('users')
.where({ email: reqObject.email }))[0];
if(user) {
res.status(400).send();
return;
}
// Create the new user.
const passwordHash = sha512(reqObject.password);
const userId = (await trx('users')

@ -14,7 +14,6 @@ export async function up(knex: Knex): Promise<void> {
)
// Add user column to other object tables.
// FIXME: figure out what happens in practice with pre-existing objects.
await knex.schema.alterTable(
'songs',
(table: any) => {

@ -35,6 +35,19 @@ describe('Auth registration password and email constraints', () => {
});
});
describe('Attempting to register an already registered user', () => {
it('should fail', async done => {
let req = await init();
try {
await helpers.createUser(req, "someone@email.com", "password1A!", 200);
await helpers.createUser(req, "someone@email.com", "password1A!", 400);
} finally {
req.close();
done();
}
});
});
describe('Auth login access for users', () => {
it('is correctly enforced', async done => {
let req = await init();

Loading…
Cancel
Save